core/filtermaps: fixed tests and rebase issues

pull/30370/head
Zsolt Felfoldi 4 weeks ago
parent eb0138c811
commit 3b9372875b
  1. 3
      core/filtermaps/filtermaps.go
  2. 21
      core/filtermaps/indexer_test.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

@ -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()})
}

Loading…
Cancel
Save