Skip to content

Commit 17676e5

Browse files
committed
core/filtermaps: fix log value search range
1 parent 7612872 commit 17676e5

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

core/filtermaps/filtermaps.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -662,15 +662,11 @@ func (f *FilterMaps) mapRowIndex(mapIndex, rowIndex uint32) uint64 {
662662
}
663663

664664
// getBlockLvPointer returns the starting log value index where the log values
665-
// generated by the given block are located. If blockNumber is beyond the current
666-
// head then the first unoccupied log value index is returned.
665+
// generated by the given block are located.
667666
//
668667
// Note that this function assumes that the indexer read lock is being held when
669668
// called from outside the indexerLoop goroutine.
670669
func (f *FilterMaps) getBlockLvPointer(blockNumber uint64) (uint64, error) {
671-
if blockNumber >= f.indexedRange.blocks.AfterLast() && f.indexedRange.headIndexed {
672-
return f.indexedRange.headDelimiter + 1, nil
673-
}
674670
if lvPointer, ok := f.lvPointerCache.Get(blockNumber); ok {
675671
return lvPointer, nil
676672
}

core/filtermaps/matcher_backend.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,26 @@ func (fm *FilterMapsMatcherBackend) GetFilterMapRow(ctx context.Context, mapInde
8282
}
8383

8484
// GetBlockLvPointer returns the starting log value index where the log values
85-
// generated by the given block are located. If blockNumber is beyond the current
86-
// head then the first unoccupied log value index is returned.
85+
// generated by the given block are located. If blockNumber is beyond the last
86+
// indexed block then the pointer will point right after this block, ensuring
87+
// that the matcher does not fail and can return a set of results where the
88+
// valid range is correct.
8789
// GetBlockLvPointer implements MatcherBackend.
8890
func (fm *FilterMapsMatcherBackend) GetBlockLvPointer(ctx context.Context, blockNumber uint64) (uint64, error) {
8991
fm.f.indexLock.RLock()
9092
defer fm.f.indexLock.RUnlock()
9193

94+
if blockNumber >= fm.f.indexedRange.blocks.AfterLast() {
95+
if fm.f.indexedRange.headIndexed {
96+
// return index after head block
97+
return fm.f.indexedRange.headDelimiter + 1, nil
98+
}
99+
if fm.f.indexedRange.blocks.Count() > 0 {
100+
// return index at the beginning of the last, partially indexed
101+
// block (after the last fully indexed one)
102+
blockNumber = fm.f.indexedRange.blocks.Last()
103+
}
104+
}
92105
return fm.f.getBlockLvPointer(blockNumber)
93106
}
94107

0 commit comments

Comments
 (0)