core/filtermaps: add database version, enforce log index reset

This commit is contained in:
Zsolt Felfoldi 2025-04-15 01:05:39 +02:00
parent 756a6f8261
commit 11e654e4d5
2 changed files with 6 additions and 2 deletions

View file

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

View file

@ -434,6 +434,7 @@ func DeleteBlockLvPointers(db ethdb.KeyValueStore, blocks common.Range[uint64],
// FilterMapsRange is a storage representation of the block range covered by the // FilterMapsRange is a storage representation of the block range covered by the
// filter maps structure and the corresponting log value index range. // filter maps structure and the corresponting log value index range.
type FilterMapsRange struct { type FilterMapsRange struct {
Version uint32
HeadIndexed bool HeadIndexed bool
HeadDelimiter uint64 HeadDelimiter uint64
BlocksFirst, BlocksAfterLast uint64 BlocksFirst, BlocksAfterLast uint64