Fix checking of ERC20 tail on new blocks scanning

This commit is contained in:
Roman Volosovskyi 2023-10-12 15:07:21 +02:00
parent 28cfeb4bc8
commit 778753bb57
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
2 changed files with 31 additions and 8 deletions

View File

@ -230,6 +230,11 @@ func (c *findBlocksCommand) Run(parent context.Context) (err error) {
} }
for { for {
if from.Cmp(to) == 0 {
log.Debug("findBlocksCommand empty range", "from", from, "to", to)
break
}
var headers []*DBHeader var headers []*DBHeader
if c.reachedETHHistoryStart { if c.reachedETHHistoryStart {
if c.fromBlockNumber.Cmp(zero) == 0 && c.startBlockNumber != nil && c.startBlockNumber.Cmp(zero) == 1 { if c.fromBlockNumber.Cmp(zero) == 0 && c.startBlockNumber != nil && c.startBlockNumber.Cmp(zero) == 1 {
@ -264,6 +269,7 @@ func (c *findBlocksCommand) Run(parent context.Context) (err error) {
} }
if c.reachedETHHistoryStart { if c.reachedETHHistoryStart {
log.Debug("findBlocksCommand reached first ETH transfer and checked erc20 tail", "chain", c.chainClient.NetworkID(), "account", c.account)
break break
} }
@ -272,24 +278,26 @@ func (c *findBlocksCommand) Run(parent context.Context) (err error) {
break break
} }
if from.Cmp(to) == 0 { if c.startBlockNumber != nil && c.fromBlockNumber.Cmp(from) == -1 {
log.Debug("ERC20 tail should be checked", "initial from", c.fromBlockNumber, "actual from", from, "first ETH block", c.startBlockNumber)
c.reachedETHHistoryStart = true
continue
}
if c.startBlockNumber != nil && c.startBlockNumber.Cmp(from) >= 0 {
log.Debug("Checked all ranges, stop execution", "startBlock", c.startBlockNumber, "from", from, "to", to)
break break
} }
nextFrom, nextTo := nextRange(c.defaultNodeBlockChunkSize, c.resFromBlock.Number, c.fromBlockNumber) nextFrom, nextTo := nextRange(c.defaultNodeBlockChunkSize, c.resFromBlock.Number, c.fromBlockNumber)
if nextFrom.Cmp(from) == 0 && nextTo.Cmp(to) == 0 { if nextFrom.Cmp(from) == 0 && nextTo.Cmp(to) == 0 {
log.Debug("findBlocksCommand empty next range", "from", from, "to", to)
break break
} }
from = nextFrom from = nextFrom
to = nextTo to = nextTo
if to.Cmp(c.fromBlockNumber) <= 0 || (c.startBlockNumber != nil &&
c.startBlockNumber.Cmp(big.NewInt(0)) > 0 && to.Cmp(c.startBlockNumber) <= 0) {
log.Debug("Checked all ranges, stop execution", "startBlock", c.startBlockNumber, "from", from, "to", to)
c.reachedETHHistoryStart = true
}
} }
log.Debug("end findBlocksCommand", "account", c.account, "chain", c.chainClient.NetworkID(), "noLimit", c.noLimit) log.Debug("end findBlocksCommand", "account", c.account, "chain", c.chainClient.NetworkID(), "noLimit", c.noLimit)

View File

@ -673,6 +673,20 @@ func getCases() []findBlockCase {
}, },
} }
case10 := findBlockCase{
balanceChanges: [][]int{},
toBlock: 100,
fromBlock: 99,
expectedBlocksFound: 0,
label: "single block range, no transactions",
expectedCalls: map[string]int{
// only two requests to check the range for incoming ERC20
"FilterLogs": 2,
// no contract calls as ERC20 is not checked
"CallContract": 0,
},
}
cases = append(cases, case1) cases = append(cases, case1)
cases = append(cases, case100transfers) cases = append(cases, case100transfers)
cases = append(cases, case3) cases = append(cases, case3)
@ -683,8 +697,9 @@ func getCases() []findBlockCase {
cases = append(cases, case7emptyHistoryWithOneERC20Transfer) cases = append(cases, case7emptyHistoryWithOneERC20Transfer)
cases = append(cases, case8emptyHistoryWithERC20Transfers) cases = append(cases, case8emptyHistoryWithERC20Transfers)
cases = append(cases, case9emptyHistoryWithERC20Transfers) cases = append(cases, case9emptyHistoryWithERC20Transfers)
cases = append(cases, case10)
//cases = append([]findBlockCase{}, case9emptyHistoryWithERC20Transfers) //cases = append([]findBlockCase{}, case10)
return cases return cases
} }