From e01d8094dd82cbf82e8c4008b7951ba26b1dacbf Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 13 Mar 2025 13:06:15 +0100 Subject: [PATCH] core/filtermaps: add Config struct --- core/filtermaps/filtermaps.go | 19 ++++++++++++++----- core/filtermaps/indexer_test.go | 7 ++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/core/filtermaps/filtermaps.go b/core/filtermaps/filtermaps.go index 8eabdd3082..af4a3d6e9f 100644 --- a/core/filtermaps/filtermaps.go +++ b/core/filtermaps/filtermaps.go @@ -166,8 +166,18 @@ type lastBlockOfMap struct { id common.Hash } +// Config contains the configuration options for NewFilterMaps. +type Config struct { + History uint64 // number of historical blocks to index + NoHistory bool // disables indexing completely + + // This option enables the checkpoint JSON file generator. + // If set, the given file will be updated with checkpoint information. + ExportFileName string +} + // NewFilterMaps creates a new FilterMaps and starts the indexer. -func NewFilterMaps(db ethdb.KeyValueStore, initView *ChainView, params Params, history, unindexLimit uint64, noHistory bool, exportFileName string) *FilterMaps { +func NewFilterMaps(db ethdb.KeyValueStore, initView *ChainView, params Params, config Config) *FilterMaps { rs, initialized, err := rawdb.ReadFilterMapsRange(db) if err != nil { log.Error("Error reading log index range", "error", err) @@ -180,10 +190,9 @@ func NewFilterMaps(db ethdb.KeyValueStore, initView *ChainView, params Params, h targetViewCh: make(chan *ChainView, 1), finalBlockCh: make(chan uint64, 1), blockProcessingCh: make(chan bool, 1), - history: history, - noHistory: noHistory, - unindexLimit: unindexLimit, - exportFileName: exportFileName, + history: config.History, + noHistory: config.NoHistory, + exportFileName: config.ExportFileName, Params: params, indexedRange: filterMapsRange{ initialized: initialized, diff --git a/core/filtermaps/indexer_test.go b/core/filtermaps/indexer_test.go index 8bf1dce20b..0807e762ea 100644 --- a/core/filtermaps/indexer_test.go +++ b/core/filtermaps/indexer_test.go @@ -230,7 +230,12 @@ func (ts *testSetup) setHistory(history uint64, noHistory bool) { ts.fm.Stop() } head := ts.chain.CurrentBlock() - ts.fm = NewFilterMaps(ts.db, NewChainView(ts.chain, head.Number.Uint64(), head.Hash()), ts.params, history, 1, noHistory, "") + view := NewChainView(ts.chain, head.Number.Uint64(), head.Hash()) + config := Config{ + History: history, + NoHistory: noHistory, + } + ts.fm = NewFilterMaps(ts.db, view, ts.params, config) ts.fm.testDisableSnapshots = ts.testDisableSnapshots ts.fm.Start() }