@@ -717,32 +717,24 @@ func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error {
717717//
718718// Note, this function assumes that the `mu` mutex is held!
719719func (bc * BlockChain ) writeHeadBlock (block * types.Block ) {
720- // If the block is on a side chain or an unknown one, force other heads onto it too
721- updateHeads := rawdb .ReadCanonicalHash (bc .db , block .NumberU64 ()) != block .Hash ()
722-
723720 // Add the block to the canonical chain number scheme and mark as the head
724721 batch := bc .db .NewBatch ()
722+ rawdb .WriteHeadHeaderHash (batch , block .Hash ())
723+ rawdb .WriteHeadFastBlockHash (batch , block .Hash ())
725724 rawdb .WriteCanonicalHash (batch , block .Hash (), block .NumberU64 ())
726725 rawdb .WriteTxLookupEntriesByBlock (batch , block )
727726 rawdb .WriteHeadBlockHash (batch , block .Hash ())
728727
729- // If the block is better than our head or is on a different chain, force update heads
730- // TODO(rjl493456442) What if the (header head/fast block head) is lower than the chain
731- // head? Is it possible in practise?
732- if updateHeads {
733- rawdb .WriteHeadHeaderHash (batch , block .Hash ())
734- rawdb .WriteHeadFastBlockHash (batch , block .Hash ())
735- }
736728 // Flush the whole batch into the disk, exit the node if failed
737729 if err := batch .Write (); err != nil {
738730 log .Crit ("Failed to update chain indexes and markers" , "err" , err )
739731 }
740732 // Update all in-memory chain markers in the last step
741- if updateHeads {
742- bc . hc . SetCurrentHeader ( block . Header ())
743- bc .currentFastBlock .Store (block )
744- headFastBlockGauge .Update (int64 (block .NumberU64 ()))
745- }
733+ bc . hc . SetCurrentHeader ( block . Header ())
734+
735+ bc .currentFastBlock .Store (block )
736+ headFastBlockGauge .Update (int64 (block .NumberU64 ()))
737+
746738 bc .currentBlock .Store (block )
747739 headBlockGauge .Update (int64 (block .NumberU64 ()))
748740}
0 commit comments