diff --git a/eth/backend.go b/eth/backend.go index 2dd5dd0085..99cb3841c3 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -248,7 +248,9 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { return nil, err } eth.bloomIndexer.Start(eth.blockchain) - eth.filterMaps = filtermaps.NewFilterMaps(chainDb, eth.newChainView(eth.blockchain.CurrentBlock()), filtermaps.DefaultParams, config.LogHistory, 1000, config.LogNoHistory, config.LogExportCheckpoints) + fmConfig := filtermaps.Config{History: config.LogHistory, Disabled: config.LogNoHistory, ExportFileName: config.LogExportCheckpoints} + chainView := eth.newChainView(eth.blockchain.CurrentBlock()) + eth.filterMaps = filtermaps.NewFilterMaps(chainDb, chainView, 0, 0, filtermaps.DefaultParams, fmConfig) eth.closeFilterMaps = make(chan chan struct{}) if config.BlobPool.Datadir != "" { @@ -436,25 +438,23 @@ func (s *Ethereum) updateFilterMapsHeads() { } }() - head := s.blockchain.CurrentBlock() - s.filterMaps.SetTargetView(s.newChainView(head)) - var lastFinalBlock uint64 - + var head *types.Header setHead := func(newHead *types.Header) { if newHead == nil { return } if head == nil || newHead.Hash() != head.Hash() { head = newHead - s.filterMaps.SetTargetView(s.newChainView(head)) - } - if fb := s.blockchain.CurrentFinalBlock(); fb != nil { - if finalBlock := fb.Number.Uint64(); finalBlock != lastFinalBlock { - s.filterMaps.SetFinalBlock(finalBlock) - lastFinalBlock = finalBlock + chainView := s.newChainView(head) + historyCutoff := s.blockchain.HistoryPruningCutoff() + var finalBlock uint64 + if fb := s.blockchain.CurrentFinalBlock(); fb != nil { + finalBlock = fb.Number.Uint64() } + s.filterMaps.SetTarget(chainView, historyCutoff, finalBlock) } } + setHead(s.blockchain.CurrentBlock()) for { select { diff --git a/eth/filters/filter_system_test.go b/eth/filters/filter_system_test.go index 39820c1e6d..4799cf8d4c 100644 --- a/eth/filters/filter_system_test.go +++ b/eth/filters/filter_system_test.go @@ -158,9 +158,15 @@ func (b *testBackend) NewMatcherBackend() filtermaps.MatcherBackend { return b.fm.NewMatcherBackend() } -func (b *testBackend) startFilterMaps(history uint64, noHistory bool, params filtermaps.Params) { +func (b *testBackend) startFilterMaps(history uint64, disabled bool, params filtermaps.Params) { head := b.CurrentBlock() - b.fm = filtermaps.NewFilterMaps(b.db, filtermaps.NewChainView(b, head.Number.Uint64(), head.Hash()), params, history, 1, noHistory, "") + chainView := filtermaps.NewChainView(b, head.Number.Uint64(), head.Hash()) + config := filtermaps.Config{ + History: history, + Disabled: disabled, + ExportFileName: "", + } + b.fm = filtermaps.NewFilterMaps(b.db, chainView, 0, 0, params, config) b.fm.Start() b.fm.WaitIdle() } diff --git a/eth/filters/filter_test.go b/eth/filters/filter_test.go index 10a73a137c..e3e33f994b 100644 --- a/eth/filters/filter_test.go +++ b/eth/filters/filter_test.go @@ -476,7 +476,7 @@ func TestRangeLogs(t *testing.T) { updateHead := func() { head := bc.CurrentBlock() - backend.fm.SetTargetView(filtermaps.NewChainView(backend, head.Number.Uint64(), head.Hash())) + backend.fm.SetTarget(filtermaps.NewChainView(backend, head.Number.Uint64(), head.Hash()), 0, 0) backend.fm.WaitIdle() }