eth/filters: SyncRange update

This commit is contained in:
Zsolt Felfoldi 2025-03-14 16:15:25 +01:00
parent 0ca476b13f
commit 90efe8ff19

View file

@ -167,7 +167,7 @@ func (f *Filter) rangeLogs(ctx context.Context, firstBlock, lastBlock uint64) ([
if err != nil { if err != nil {
return nil, err return nil, err
} }
if !syncRange.Indexed { if syncRange.IndexedBlocks.IsEmpty() {
// fallback to completely unindexed search // fallback to completely unindexed search
headNum := syncRange.HeadNumber headNum := syncRange.HeadNumber
if firstBlock > headNum { if firstBlock > headNum {
@ -245,20 +245,20 @@ func (f *Filter) rangeLogs(ctx context.Context, firstBlock, lastBlock uint64) ([
// if we have matches, they start at searchFirst // if we have matches, they start at searchFirst
if haveMatches { if haveMatches {
searchFirst = matchLast + 1 searchFirst = matchLast + 1
if !syncRange.Indexed || syncRange.FirstIndexed > searchFirst { if syncRange.IndexedBlocks.IsEmpty() || syncRange.IndexedBlocks.First() > searchFirst {
forceUnindexed = true forceUnindexed = true
} }
} }
var newMatches []*types.Log var newMatches []*types.Log
if !syncRange.Indexed || syncRange.FirstIndexed > searchLast || syncRange.LastIndexed < searchFirst { if syncRange.IndexedBlocks.IsEmpty() || syncRange.IndexedBlocks.First() > searchLast || syncRange.IndexedBlocks.Last() < searchFirst {
forceUnindexed = true forceUnindexed = true
} }
if !forceUnindexed { if !forceUnindexed {
if syncRange.FirstIndexed > searchFirst { if syncRange.IndexedBlocks.First() > searchFirst {
searchFirst = syncRange.FirstIndexed searchFirst = syncRange.IndexedBlocks.First()
} }
if syncRange.LastIndexed < searchLast { if syncRange.IndexedBlocks.Last() < searchLast {
searchLast = syncRange.LastIndexed searchLast = syncRange.IndexedBlocks.Last()
} }
if f.rangeLogsTestHook != nil { if f.rangeLogsTestHook != nil {
f.rangeLogsTestHook <- rangeLogsTestEvent{rangeLogsTestIndexed, searchFirst, searchLast} f.rangeLogsTestHook <- rangeLogsTestEvent{rangeLogsTestIndexed, searchFirst, searchLast}
@ -300,13 +300,13 @@ func (f *Filter) rangeLogs(ctx context.Context, firstBlock, lastBlock uint64) ([
return matches, err return matches, err
} }
headBlock = syncRange.HeadNumber // Head is guaranteed != nil headBlock = syncRange.HeadNumber // Head is guaranteed != nil
if !syncRange.Valid { if syncRange.ValidBlocks.IsEmpty() {
matches, haveMatches, matchFirst, matchLast = nil, false, 0, 0 matches, haveMatches, matchFirst, matchLast = nil, false, 0, 0
} else { } else {
if syncRange.FirstValid > trimTailIfNotValid { if syncRange.ValidBlocks.First() > trimTailIfNotValid {
trimMatches(syncRange.FirstValid, syncRange.LastValid) trimMatches(syncRange.ValidBlocks.First(), syncRange.ValidBlocks.Last())
} else { } else {
trimMatches(0, syncRange.LastValid) trimMatches(0, syncRange.ValidBlocks.Last())
} }
} }
if f.rangeLogsTestHook != nil { if f.rangeLogsTestHook != nil {