Skip to content

Commit 844e795

Browse files
committed
core/filtermaps: add database version, enforce log index reset
1 parent dfa2356 commit 844e795

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

core/filtermaps/filtermaps.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ var (
5050
)
5151

5252
const (
53+
databaseVersion = 1 // reindexed if database version does not match
5354
cachedLastBlocks = 1000 // last block of map pointers
5455
cachedLvPointers = 1000 // first log value pointer of block pointers
5556
cachedBaseRows = 100 // groups of base layer filter row data
@@ -210,8 +211,9 @@ type Config struct {
210211
// NewFilterMaps creates a new FilterMaps and starts the indexer.
211212
func NewFilterMaps(db ethdb.KeyValueStore, initView *ChainView, historyCutoff, finalBlock uint64, params Params, config Config) *FilterMaps {
212213
rs, initialized, err := rawdb.ReadFilterMapsRange(db)
213-
if err != nil {
214-
log.Error("Error reading log index range", "error", err)
214+
if err != nil || rs.Version != databaseVersion {
215+
rs, initialized = rawdb.FilterMapsRange{}, false
216+
log.Warn("Invalid log index database version; resetting log index")
215217
}
216218
params.deriveFields()
217219
f := &FilterMaps{
@@ -440,6 +442,7 @@ func (f *FilterMaps) setRange(batch ethdb.KeyValueWriter, newView *ChainView, ne
440442
f.updateMatchersValidRange()
441443
if newRange.initialized {
442444
rs := rawdb.FilterMapsRange{
445+
Version: databaseVersion,
443446
HeadIndexed: newRange.headIndexed,
444447
HeadDelimiter: newRange.headDelimiter,
445448
BlocksFirst: newRange.blocks.First(),

core/rawdb/accessors_indexes.go

+1
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ func DeleteBlockLvPointers(db ethdb.KeyValueStore, blocks common.Range[uint64],
434434
// FilterMapsRange is a storage representation of the block range covered by the
435435
// filter maps structure and the corresponting log value index range.
436436
type FilterMapsRange struct {
437+
Version uint32
437438
HeadIndexed bool
438439
HeadDelimiter uint64
439440
BlocksFirst, BlocksAfterLast uint64

0 commit comments

Comments
 (0)