[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:
parent
1097b14a7f
commit
6bea21c197
|
@ -474,6 +474,7 @@ func (c *findAndCheckBlockRangeCommand) fastIndex(ctx context.Context, bCache *b
|
|||
balanceCache: bCache,
|
||||
address: address,
|
||||
eth: ÐTransferDownloader{
|
||||
chain: c.chain,
|
||||
client: c.client,
|
||||
accounts: []common.Address{address},
|
||||
signer: types.NewEIP155Signer(c.chain),
|
||||
|
@ -567,13 +568,13 @@ func loadTransfers(ctx context.Context, accounts []common.Address, db *Database,
|
|||
if !ok {
|
||||
blocks, _ = db.GetBlocksByAddress(address, numberOfBlocksCheckedPerIteration)
|
||||
}
|
||||
|
||||
for _, block := range blocks {
|
||||
transfers := &transfersCommand{
|
||||
db: db,
|
||||
client: client,
|
||||
address: address,
|
||||
eth: ÐTransferDownloader{
|
||||
chain: chain,
|
||||
client: client,
|
||||
accounts: []common.Address{address},
|
||||
signer: types.NewEIP155Signer(chain),
|
||||
|
@ -804,6 +805,7 @@ func (c *controlCommand) Run(parent context.Context) error {
|
|||
}
|
||||
|
||||
downloader := ÐTransferDownloader{
|
||||
chain: c.chain,
|
||||
client: c.client,
|
||||
accounts: c.accounts,
|
||||
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) {
|
||||
downloader := ÐTransferDownloader{
|
||||
chain: c.chain,
|
||||
client: c.client,
|
||||
accounts: c.accounts,
|
||||
signer: types.NewEIP155Signer(c.chain),
|
||||
|
|
|
@ -48,6 +48,7 @@ func (s *NewBlocksSuite) SetupTest() {
|
|||
accounts: []common.Address{s.address},
|
||||
erc20: NewERC20TransfersDownloader(client, []common.Address{s.address}, s.backend.Signer),
|
||||
eth: ÐTransferDownloader{
|
||||
chain: s.backend.Chain,
|
||||
client: client,
|
||||
signer: s.backend.Signer,
|
||||
db: s.db,
|
||||
|
@ -197,6 +198,7 @@ func (s *NewBlocksSuite) downloadHistorical() {
|
|||
db: s.db,
|
||||
balanceCache: newBalanceCache(),
|
||||
eth: ÐTransferDownloader{
|
||||
chain: s.backend.Chain,
|
||||
client: client,
|
||||
signer: s.backend.Signer,
|
||||
accounts: []common.Address{s.address},
|
||||
|
|
|
@ -54,6 +54,7 @@ type ETHTransferDownloader struct {
|
|||
accounts []common.Address
|
||||
signer types.Signer
|
||||
db *Database
|
||||
chain *big.Int
|
||||
}
|
||||
|
||||
var errLogsDownloaderStuck = errors.New("logs downloader stuck")
|
||||
|
@ -95,7 +96,6 @@ func (d *ETHTransferDownloader) getTransfersInBlock(ctx context.Context, blk *ty
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, t := range preloadedTransfers {
|
||||
transfer, err := d.transferFromLog(ctx, *t.Log, address, t.ID)
|
||||
if err != nil {
|
||||
|
@ -106,8 +106,11 @@ func (d *ETHTransferDownloader) getTransfersInBlock(ctx context.Context, blk *ty
|
|||
}
|
||||
|
||||
for _, tx := range blk.Transactions() {
|
||||
|
||||
if tx.ChainId().Cmp(d.chain) != 0 {
|
||||
continue
|
||||
}
|
||||
from, err := types.Sender(d.signer, tx)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ func (s *ETHTransferSuite) SetupTest() {
|
|||
db, stop := setupTestDB(s.Suite.T())
|
||||
s.dbStop = stop
|
||||
s.downloader = ÐTransferDownloader{
|
||||
chain: big.NewInt(1337),
|
||||
signer: s.signer,
|
||||
client: &walletClient{client: s.ethclient},
|
||||
db: db,
|
||||
|
|
|
@ -151,6 +151,7 @@ func (r *Reactor) newControlCommand(accounts []common.Address) *controlCommand {
|
|||
client: client,
|
||||
accounts: accounts,
|
||||
eth: ÐTransferDownloader{
|
||||
chain: r.chain,
|
||||
client: client,
|
||||
accounts: accounts,
|
||||
signer: signer,
|
||||
|
|
|
@ -21,6 +21,7 @@ type Backend struct {
|
|||
Ethereum *eth.Ethereum
|
||||
Faucet *ecdsa.PrivateKey
|
||||
Signer types.Signer
|
||||
Chain *big.Int
|
||||
}
|
||||
|
||||
func NewBackend() (*Backend, error) {
|
||||
|
@ -64,6 +65,7 @@ func NewBackend() (*Backend, error) {
|
|||
Faucet: faucet,
|
||||
Signer: types.NewEIP155Signer(config.ChainID),
|
||||
genesis: genesis,
|
||||
Chain: config.ChainID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue