Skip to content

Commit

Permalink
core/filtermaps: fixed tests and rebase issues
Browse files Browse the repository at this point in the history
  • Loading branch information
zsfelfoldi committed Oct 30, 2024
1 parent eb0138c commit 3b93728
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
3 changes: 1 addition & 2 deletions core/filtermaps/filtermaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
21 changes: 13 additions & 8 deletions core/filtermaps/indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]")
Expand All @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -377,15 +382,15 @@ 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) {
tc.lock.Lock()
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 {
Expand All @@ -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()})
}

0 comments on commit 3b93728

Please sign in to comment.