[wallet] Skip transaction on chain id mismatch

Sometimes eth_getBlockByNumber returns txs with chainId which is not
equal to chanin's id. That caused an error and tx fetching was
interrupted. From now on such txs will be skipped.
This commit is contained in:
Roman Volosovskyi 2021-03-19 15:39:01 +02:00
parent 1097b14a7f
commit 6bea21c197
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
7 changed files with 16 additions and 4 deletions

View File

@ -1 +1 @@
0.73.7 0.73.8

View File

@ -474,6 +474,7 @@ func (c *findAndCheckBlockRangeCommand) fastIndex(ctx context.Context, bCache *b
balanceCache: bCache, balanceCache: bCache,
address: address, address: address,
eth: &ETHTransferDownloader{ eth: &ETHTransferDownloader{
chain: c.chain,
client: c.client, client: c.client,
accounts: []common.Address{address}, accounts: []common.Address{address},
signer: types.NewEIP155Signer(c.chain), signer: types.NewEIP155Signer(c.chain),
@ -567,13 +568,13 @@ func loadTransfers(ctx context.Context, accounts []common.Address, db *Database,
if !ok { if !ok {
blocks, _ = db.GetBlocksByAddress(address, numberOfBlocksCheckedPerIteration) blocks, _ = db.GetBlocksByAddress(address, numberOfBlocksCheckedPerIteration)
} }
for _, block := range blocks { for _, block := range blocks {
transfers := &transfersCommand{ transfers := &transfersCommand{
db: db, db: db,
client: client, client: client,
address: address, address: address,
eth: &ETHTransferDownloader{ eth: &ETHTransferDownloader{
chain: chain,
client: client, client: client,
accounts: []common.Address{address}, accounts: []common.Address{address},
signer: types.NewEIP155Signer(chain), signer: types.NewEIP155Signer(chain),
@ -804,6 +805,7 @@ func (c *controlCommand) Run(parent context.Context) error {
} }
downloader := &ETHTransferDownloader{ downloader := &ETHTransferDownloader{
chain: c.chain,
client: c.client, client: c.client,
accounts: c.accounts, accounts: c.accounts,
signer: types.NewEIP155Signer(c.chain), signer: types.NewEIP155Signer(c.chain),
@ -1008,6 +1010,7 @@ func (c *loadTransfersCommand) LoadTransfers(ctx context.Context, downloader *ET
func (c *loadTransfersCommand) Run(parent context.Context) (err error) { func (c *loadTransfersCommand) Run(parent context.Context) (err error) {
downloader := &ETHTransferDownloader{ downloader := &ETHTransferDownloader{
chain: c.chain,
client: c.client, client: c.client,
accounts: c.accounts, accounts: c.accounts,
signer: types.NewEIP155Signer(c.chain), signer: types.NewEIP155Signer(c.chain),

View File

@ -48,6 +48,7 @@ func (s *NewBlocksSuite) SetupTest() {
accounts: []common.Address{s.address}, accounts: []common.Address{s.address},
erc20: NewERC20TransfersDownloader(client, []common.Address{s.address}, s.backend.Signer), erc20: NewERC20TransfersDownloader(client, []common.Address{s.address}, s.backend.Signer),
eth: &ETHTransferDownloader{ eth: &ETHTransferDownloader{
chain: s.backend.Chain,
client: client, client: client,
signer: s.backend.Signer, signer: s.backend.Signer,
db: s.db, db: s.db,
@ -197,6 +198,7 @@ func (s *NewBlocksSuite) downloadHistorical() {
db: s.db, db: s.db,
balanceCache: newBalanceCache(), balanceCache: newBalanceCache(),
eth: &ETHTransferDownloader{ eth: &ETHTransferDownloader{
chain: s.backend.Chain,
client: client, client: client,
signer: s.backend.Signer, signer: s.backend.Signer,
accounts: []common.Address{s.address}, accounts: []common.Address{s.address},

View File

@ -54,6 +54,7 @@ type ETHTransferDownloader struct {
accounts []common.Address accounts []common.Address
signer types.Signer signer types.Signer
db *Database db *Database
chain *big.Int
} }
var errLogsDownloaderStuck = errors.New("logs downloader stuck") var errLogsDownloaderStuck = errors.New("logs downloader stuck")
@ -95,7 +96,6 @@ func (d *ETHTransferDownloader) getTransfersInBlock(ctx context.Context, blk *ty
if err != nil { if err != nil {
return nil, err return nil, err
} }
for _, t := range preloadedTransfers { for _, t := range preloadedTransfers {
transfer, err := d.transferFromLog(ctx, *t.Log, address, t.ID) transfer, err := d.transferFromLog(ctx, *t.Log, address, t.ID)
if err != nil { if err != nil {
@ -106,8 +106,11 @@ func (d *ETHTransferDownloader) getTransfersInBlock(ctx context.Context, blk *ty
} }
for _, tx := range blk.Transactions() { for _, tx := range blk.Transactions() {
if tx.ChainId().Cmp(d.chain) != 0 {
continue
}
from, err := types.Sender(d.signer, tx) from, err := types.Sender(d.signer, tx)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -55,6 +55,7 @@ func (s *ETHTransferSuite) SetupTest() {
db, stop := setupTestDB(s.Suite.T()) db, stop := setupTestDB(s.Suite.T())
s.dbStop = stop s.dbStop = stop
s.downloader = &ETHTransferDownloader{ s.downloader = &ETHTransferDownloader{
chain: big.NewInt(1337),
signer: s.signer, signer: s.signer,
client: &walletClient{client: s.ethclient}, client: &walletClient{client: s.ethclient},
db: db, db: db,

View File

@ -151,6 +151,7 @@ func (r *Reactor) newControlCommand(accounts []common.Address) *controlCommand {
client: client, client: client,
accounts: accounts, accounts: accounts,
eth: &ETHTransferDownloader{ eth: &ETHTransferDownloader{
chain: r.chain,
client: client, client: client,
accounts: accounts, accounts: accounts,
signer: signer, signer: signer,

View File

@ -21,6 +21,7 @@ type Backend struct {
Ethereum *eth.Ethereum Ethereum *eth.Ethereum
Faucet *ecdsa.PrivateKey Faucet *ecdsa.PrivateKey
Signer types.Signer Signer types.Signer
Chain *big.Int
} }
func NewBackend() (*Backend, error) { func NewBackend() (*Backend, error) {
@ -64,6 +65,7 @@ func NewBackend() (*Backend, error) {
Faucet: faucet, Faucet: faucet,
Signer: types.NewEIP155Signer(config.ChainID), Signer: types.NewEIP155Signer(config.ChainID),
genesis: genesis, genesis: genesis,
Chain: config.ChainID,
}, nil }, nil
} }