@@ -632,19 +632,7 @@ func (bc *BlockChain) SetHead(head uint64) error {
632632 if _ , err := bc .setHeadBeyondRoot (head , 0 , common.Hash {}, false ); err != nil {
633633 return err
634634 }
635- // Send chain head event to update the transaction pool
636- if block := bc .CurrentBlock (); block == nil {
637- if block .Number ().Uint64 () > 0 {
638- // This should never happen. In practice, previously currentBlock
639- // contained the entire block whereas now only a "marker", so there
640- // is an ever so slight chance for a race we should handle.
641- log .Error ("Current block not found in database" , "block" , block .Number (), "hash" , block .Hash ())
642- return fmt .Errorf ("current block missing: #%d [%x..]" , block .Number (), block .Hash ().Bytes ()[:4 ])
643- }
644- } else {
645- bc .chainHeadFeed .Send (ChainHeadEvent {Header : block .Header ()})
646- }
647- return nil
635+ return bc .sendChainHeadEvent ()
648636}
649637
650638// SetHeadWithTimestamp rewinds the local chain to a new head that has at max
@@ -655,9 +643,17 @@ func (bc *BlockChain) SetHeadWithTimestamp(timestamp uint64) error {
655643 if _ , err := bc .setHeadBeyondRoot (0 , timestamp , common.Hash {}, false ); err != nil {
656644 return err
657645 }
658- // Send chain head event to update the transaction pool
659- if block := bc .CurrentBlock (); block == nil {
660- if block .Number ().Uint64 () > 0 {
646+ return bc .sendChainHeadEvent ()
647+ }
648+
649+ // sendChainHeadEvent notifies all subscribers about the new chain head,
650+ // checking first that the current block is actually available.
651+ func (bc * BlockChain ) sendChainHeadEvent () error {
652+ header := bc .CurrentBlock ()
653+ if block := bc .GetBlock (header .Hash (), header .Number ().Uint64 ()); block == nil {
654+ // In a pruned node the genesis block will not exist in the freezer.
655+ // It should not happen that we set head to any other pruned block.
656+ if header .Number ().Uint64 () > 0 {
661657 // This should never happen. In practice, previously currentBlock
662658 // contained the entire block whereas now only a "marker", so there
663659 // is an ever so slight chance for a race we should handle.
0 commit comments