Update blockchain.go

This commit is contained in:
Justin 2025-11-24 23:15:23 +01:00 committed by GitHub
parent 5748dd18e7
commit 51d742510b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -739,15 +739,17 @@ func (bc *BlockChain) SetHead(head uint64) error {
}
// Send chain head event to update the transaction pool
header := bc.CurrentBlock()
if block := bc.GetBlock(header.Hash(), header.Number.Uint64()); block == nil {
hash := header.Hash()
number := header.Number.Uint64()
if block := bc.GetBlock(hash, number); block == nil {
// In a pruned node the genesis block will not exist in the freezer.
// It should not happen that we set head to any other pruned block.
if header.Number.Uint64() > 0 {
if number > 0 {
// This should never happen. In practice, previously currentBlock
// 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])
log.Error("Current block not found in database", "block", header.Number, "hash", hash)
return fmt.Errorf("current block missing: #%d [%x..]", header.Number, hash.Bytes()[:4])
}
}
bc.chainHeadFeed.Send(ChainHeadEvent{Header: header})
@ -764,15 +766,17 @@ func (bc *BlockChain) SetHeadWithTimestamp(timestamp uint64) error {
}
// Send chain head event to update the transaction pool
header := bc.CurrentBlock()
if block := bc.GetBlock(header.Hash(), header.Number.Uint64()); block == nil {
hash := header.Hash()
number := header.Number.Uint64()
if block := bc.GetBlock(hash, number); block == nil {
// In a pruned node the genesis block will not exist in the freezer.
// It should not happen that we set head to any other pruned block.
if header.Number.Uint64() > 0 {
if number > 0 {
// This should never happen. In practice, previously currentBlock
// 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])
log.Error("Current block not found in database", "block", header.Number, "hash", hash)
return fmt.Errorf("current block missing: #%d [%x..]", header.Number, hash.Bytes()[:4])
}
}
bc.chainHeadFeed.Send(ChainHeadEvent{Header: header})