Skip to content

Commit 3b93728

Browse files
committed
core/filtermaps: fixed tests and rebase issues
1 parent eb0138c commit 3b93728

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

core/filtermaps/filtermaps.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ func NewFilterMaps(db ethdb.KeyValueStore, chain blockchain, params Params, hist
203203
log.Error("Error fetching tail block pointer, resetting log index", "error", err)
204204
fm.filterMapsRange = filterMapsRange{} // updateLoop resets the database
205205
}
206-
headBlockPtr, _ := fm.getBlockLvPointer(fm.headBlockNumber)
207206
log.Trace("Log index head", "number", fm.headBlockNumber, "hash", fm.headBlockHash.String(), "log value pointer", fm.headLvPointer)
208207
log.Trace("Log index tail", "number", fm.tailBlockNumber, "parentHash", fm.tailParentHash.String(), "log value pointer", fm.tailBlockLvPointer)
209208
}
@@ -337,7 +336,7 @@ func (f *FilterMaps) updateMapCache() {
337336
// Note that this function assumes that the indexer read lock is being held when
338337
// called from outside the updateLoop goroutine.
339338
func (f *FilterMaps) getLogByLvIndex(lvIndex uint64) (*types.Log, error) {
340-
if lvIndex < f.tailBlockLvPointer || lvIndex > f.headLvPointer {
339+
if lvIndex < f.tailBlockLvPointer || lvIndex >= f.headLvPointer {
341340
return nil, nil
342341
}
343342
// find possible block range based on map to block pointers

core/filtermaps/indexer_test.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,11 @@ func TestIndexerCompareDb(t *testing.T) {
140140
chain2 := ts.chain.getCanonicalChain()
141141
ts.storeDbHash("chain 2 [0, 1200]")
142142

143-
ts.setHistory(800, false)
144-
ts.fm.WaitIdle()
145-
ts.storeDbHash("chain 2 [401, 1200]")
146-
147143
ts.chain.setHead(600)
148144
ts.fm.WaitIdle()
149145
ts.checkDbHash("chain 1/2 [0, 600]")
150146

147+
ts.setHistory(800, false)
151148
ts.chain.setCanonicalChain(chain1)
152149
ts.fm.WaitIdle()
153150
ts.storeDbHash("chain 1 [201, 1000]")
@@ -156,6 +153,11 @@ func TestIndexerCompareDb(t *testing.T) {
156153
ts.fm.WaitIdle()
157154
ts.checkDbHash("chain 1 [0, 1000]")
158155

156+
ts.setHistory(800, false)
157+
ts.chain.setCanonicalChain(chain2)
158+
ts.fm.WaitIdle()
159+
ts.storeDbHash("chain 2 [401, 1200]")
160+
159161
ts.setHistory(0, true)
160162
ts.fm.WaitIdle()
161163
ts.storeDbHash("no index")
@@ -282,7 +284,10 @@ func (tc *testChain) GetHeader(hash common.Hash, number uint64) *types.Header {
282284
tc.lock.RLock()
283285
defer tc.lock.RUnlock()
284286

285-
return tc.blocks[hash].Header()
287+
if block := tc.blocks[hash]; block != nil {
288+
return block.Header()
289+
}
290+
return nil
286291
}
287292

288293
func (tc *testChain) GetCanonicalHash(number uint64) common.Hash {
@@ -377,15 +382,15 @@ func (tc *testChain) addBlocks(count, maxTxPerBlock, maxLogsPerReceipt, maxTopic
377382
tc.receipts[hash] = types.Receipts{}
378383
}
379384
}
380-
tc.chainHeadFeed.Send(core.ChainEvent{Block: tc.blocks[tc.canonical[len(tc.canonical)-1]]})
385+
tc.chainHeadFeed.Send(core.ChainEvent{Header: tc.blocks[tc.canonical[len(tc.canonical)-1]].Header()})
381386
}
382387

383388
func (tc *testChain) setHead(headNum int) {
384389
tc.lock.Lock()
385390
defer tc.lock.Unlock()
386391

387392
tc.canonical = tc.canonical[:headNum+1]
388-
tc.chainHeadFeed.Send(core.ChainEvent{Block: tc.blocks[tc.canonical[len(tc.canonical)-1]]})
393+
tc.chainHeadFeed.Send(core.ChainEvent{Header: tc.blocks[tc.canonical[len(tc.canonical)-1]].Header()})
389394
}
390395

391396
func (tc *testChain) getCanonicalChain() []common.Hash {
@@ -404,5 +409,5 @@ func (tc *testChain) setCanonicalChain(cc []common.Hash) {
404409

405410
tc.canonical = make([]common.Hash, len(cc))
406411
copy(tc.canonical, cc)
407-
tc.chainHeadFeed.Send(core.ChainEvent{Block: tc.blocks[tc.canonical[len(tc.canonical)-1]]})
412+
tc.chainHeadFeed.Send(core.ChainEvent{Header: tc.blocks[tc.canonical[len(tc.canonical)-1]].Header()})
408413
}

0 commit comments

Comments
 (0)