From 08a345e60294a986d43c08c3dea665e783c01158 Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Wed, 30 Oct 2024 01:32:08 +0100 Subject: [PATCH] core/filtermaps: fixed tests and rebase issues --- core/filtermaps/filtermaps.go | 3 +-- core/filtermaps/indexer_test.go | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/core/filtermaps/filtermaps.go b/core/filtermaps/filtermaps.go index 420ec766c1..e49cd684bd 100644 --- a/core/filtermaps/filtermaps.go +++ b/core/filtermaps/filtermaps.go @@ -203,7 +203,6 @@ func NewFilterMaps(db ethdb.KeyValueStore, chain blockchain, params Params, hist log.Error("Error fetching tail block pointer, resetting log index", "error", err) fm.filterMapsRange = filterMapsRange{} // updateLoop resets the database } - headBlockPtr, _ := fm.getBlockLvPointer(fm.headBlockNumber) log.Trace("Log index head", "number", fm.headBlockNumber, "hash", fm.headBlockHash.String(), "log value pointer", fm.headLvPointer) log.Trace("Log index tail", "number", fm.tailBlockNumber, "parentHash", fm.tailParentHash.String(), "log value pointer", fm.tailBlockLvPointer) } @@ -337,7 +336,7 @@ func (f *FilterMaps) updateMapCache() { // Note that this function assumes that the indexer read lock is being held when // called from outside the updateLoop goroutine. func (f *FilterMaps) getLogByLvIndex(lvIndex uint64) (*types.Log, error) { - if lvIndex < f.tailBlockLvPointer || lvIndex > f.headLvPointer { + if lvIndex < f.tailBlockLvPointer || lvIndex >= f.headLvPointer { return nil, nil } // find possible block range based on map to block pointers diff --git a/core/filtermaps/indexer_test.go b/core/filtermaps/indexer_test.go index 84e348cd42..6fc700bf3c 100644 --- a/core/filtermaps/indexer_test.go +++ b/core/filtermaps/indexer_test.go @@ -140,14 +140,11 @@ func TestIndexerCompareDb(t *testing.T) { chain2 := ts.chain.getCanonicalChain() ts.storeDbHash("chain 2 [0, 1200]") - ts.setHistory(800, false) - ts.fm.WaitIdle() - ts.storeDbHash("chain 2 [401, 1200]") - ts.chain.setHead(600) ts.fm.WaitIdle() ts.checkDbHash("chain 1/2 [0, 600]") + ts.setHistory(800, false) ts.chain.setCanonicalChain(chain1) ts.fm.WaitIdle() ts.storeDbHash("chain 1 [201, 1000]") @@ -156,6 +153,11 @@ func TestIndexerCompareDb(t *testing.T) { ts.fm.WaitIdle() ts.checkDbHash("chain 1 [0, 1000]") + ts.setHistory(800, false) + ts.chain.setCanonicalChain(chain2) + ts.fm.WaitIdle() + ts.storeDbHash("chain 2 [401, 1200]") + ts.setHistory(0, true) ts.fm.WaitIdle() ts.storeDbHash("no index") @@ -282,7 +284,10 @@ func (tc *testChain) GetHeader(hash common.Hash, number uint64) *types.Header { tc.lock.RLock() defer tc.lock.RUnlock() - return tc.blocks[hash].Header() + if block := tc.blocks[hash]; block != nil { + return block.Header() + } + return nil } func (tc *testChain) GetCanonicalHash(number uint64) common.Hash { @@ -377,7 +382,7 @@ func (tc *testChain) addBlocks(count, maxTxPerBlock, maxLogsPerReceipt, maxTopic tc.receipts[hash] = types.Receipts{} } } - tc.chainHeadFeed.Send(core.ChainEvent{Block: tc.blocks[tc.canonical[len(tc.canonical)-1]]}) + tc.chainHeadFeed.Send(core.ChainEvent{Header: tc.blocks[tc.canonical[len(tc.canonical)-1]].Header()}) } func (tc *testChain) setHead(headNum int) { @@ -385,7 +390,7 @@ func (tc *testChain) setHead(headNum int) { defer tc.lock.Unlock() tc.canonical = tc.canonical[:headNum+1] - tc.chainHeadFeed.Send(core.ChainEvent{Block: tc.blocks[tc.canonical[len(tc.canonical)-1]]}) + tc.chainHeadFeed.Send(core.ChainEvent{Header: tc.blocks[tc.canonical[len(tc.canonical)-1]].Header()}) } func (tc *testChain) getCanonicalChain() []common.Hash { @@ -404,5 +409,5 @@ func (tc *testChain) setCanonicalChain(cc []common.Hash) { tc.canonical = make([]common.Hash, len(cc)) copy(tc.canonical, cc) - tc.chainHeadFeed.Send(core.ChainEvent{Block: tc.blocks[tc.canonical[len(tc.canonical)-1]]}) + tc.chainHeadFeed.Send(core.ChainEvent{Header: tc.blocks[tc.canonical[len(tc.canonical)-1]].Header()}) }