fix txindexer panic

This commit is contained in:
Sina Mahmoodi 2025-04-16 17:57:08 +02:00
parent f62a7e22c9
commit d4b106c978

View file

@ -205,7 +205,8 @@ func (indexer *txIndexer) loop(chain *BlockChain) {
var ( var (
stop chan struct{} // Non-nil if background routine is active stop chan struct{} // Non-nil if background routine is active
done chan struct{} // Non-nil if background routine is active done chan struct{} // Non-nil if background routine is active
head = rawdb.ReadHeadBlock(indexer.db).NumberU64() // The latest announced chain head headBlock = rawdb.ReadHeadBlock(indexer.db) // The latest announced chain head
head uint64
headCh = make(chan ChainHeadEvent) headCh = make(chan ChainHeadEvent)
sub = chain.SubscribeChainHeadEvent(headCh) sub = chain.SubscribeChainHeadEvent(headCh)
@ -213,13 +214,16 @@ func (indexer *txIndexer) loop(chain *BlockChain) {
defer sub.Unsubscribe() defer sub.Unsubscribe()
// Validate the transaction indexes and repair if necessary // Validate the transaction indexes and repair if necessary
indexer.repair(head) if headBlock != nil {
indexer.repair(headBlock.NumberU64())
}
// Launch the initial processing if chain is not empty (head != genesis). // Launch the initial processing if chain is not empty (head != genesis).
// This step is useful in these scenarios that chain has no progress. // This step is useful in these scenarios that chain has no progress.
if head != 0 { if headBlock != nil && headBlock.NumberU64() != 0 {
stop = make(chan struct{}) stop = make(chan struct{})
done = make(chan struct{}) done = make(chan struct{})
head = headBlock.Number().Uint64()
go indexer.run(head, stop, done) go indexer.run(head, stop, done)
} }
for { for {