try fix for setHead

This commit is contained in:
Sina Mahmoodi 2025-04-16 18:10:53 +02:00
parent d4b106c978
commit 60e7867bcd

View file

@ -600,11 +600,15 @@ func (bc *BlockChain) SetHead(head uint64) error {
// Send chain head event to update the transaction pool // Send chain head event to update the transaction pool
header := bc.CurrentBlock() header := bc.CurrentBlock()
if block := bc.GetBlock(header.Hash(), header.Number.Uint64()); block == nil { if block := bc.GetBlock(header.Hash(), header.Number.Uint64()); block == nil {
// This should never happen. In practice, previously currentBlock // In a pruned node the genesis block will not exist in the freezer.
// contained the entire block whereas now only a "marker", so there // It should not happen that we set head to any other pruned block.
// is an ever so slight chance for a race we should handle. if header.Number.Uint64() > 0 {
log.Error("Current block not found in database", "block", header.Number, "hash", header.Hash()) // This should never happen. In practice, previously currentBlock
return fmt.Errorf("current block missing: #%d [%x..]", header.Number, header.Hash().Bytes()[:4]) // contained the entire block whereas now only a "marker", so there
// is an ever so slight chance for a race we should handle.
log.Error("Current block not found in database", "block", header.Number, "hash", header.Hash())
return fmt.Errorf("current block missing: #%d [%x..]", header.Number, header.Hash().Bytes()[:4])
}
} }
bc.chainHeadFeed.Send(ChainHeadEvent{Header: header}) bc.chainHeadFeed.Send(ChainHeadEvent{Header: header})
return nil return nil