core/filtermaps: fixed tests and rebase issues

This commit is contained in:
Zsolt Felfoldi 2024-10-30 01:32:08 +01:00
parent 38194a0fbe
commit 08a345e602
2 changed files with 14 additions and 10 deletions

View File

@ -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) log.Error("Error fetching tail block pointer, resetting log index", "error", err)
fm.filterMapsRange = filterMapsRange{} // updateLoop resets the database 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 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) 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 // Note that this function assumes that the indexer read lock is being held when
// called from outside the updateLoop goroutine. // called from outside the updateLoop goroutine.
func (f *FilterMaps) getLogByLvIndex(lvIndex uint64) (*types.Log, error) { 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 return nil, nil
} }
// find possible block range based on map to block pointers // find possible block range based on map to block pointers

View File

@ -140,14 +140,11 @@ func TestIndexerCompareDb(t *testing.T) {
chain2 := ts.chain.getCanonicalChain() chain2 := ts.chain.getCanonicalChain()
ts.storeDbHash("chain 2 [0, 1200]") ts.storeDbHash("chain 2 [0, 1200]")
ts.setHistory(800, false)
ts.fm.WaitIdle()
ts.storeDbHash("chain 2 [401, 1200]")
ts.chain.setHead(600) ts.chain.setHead(600)
ts.fm.WaitIdle() ts.fm.WaitIdle()
ts.checkDbHash("chain 1/2 [0, 600]") ts.checkDbHash("chain 1/2 [0, 600]")
ts.setHistory(800, false)
ts.chain.setCanonicalChain(chain1) ts.chain.setCanonicalChain(chain1)
ts.fm.WaitIdle() ts.fm.WaitIdle()
ts.storeDbHash("chain 1 [201, 1000]") ts.storeDbHash("chain 1 [201, 1000]")
@ -156,6 +153,11 @@ func TestIndexerCompareDb(t *testing.T) {
ts.fm.WaitIdle() ts.fm.WaitIdle()
ts.checkDbHash("chain 1 [0, 1000]") 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.setHistory(0, true)
ts.fm.WaitIdle() ts.fm.WaitIdle()
ts.storeDbHash("no index") ts.storeDbHash("no index")
@ -282,7 +284,10 @@ func (tc *testChain) GetHeader(hash common.Hash, number uint64) *types.Header {
tc.lock.RLock() tc.lock.RLock()
defer tc.lock.RUnlock() 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 { 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.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) { func (tc *testChain) setHead(headNum int) {
@ -385,7 +390,7 @@ func (tc *testChain) setHead(headNum int) {
defer tc.lock.Unlock() defer tc.lock.Unlock()
tc.canonical = tc.canonical[:headNum+1] 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 { func (tc *testChain) getCanonicalChain() []common.Hash {
@ -404,5 +409,5 @@ func (tc *testChain) setCanonicalChain(cc []common.Hash) {
tc.canonical = make([]common.Hash, len(cc)) tc.canonical = make([]common.Hash, len(cc))
copy(tc.canonical, 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()})
} }