@@ -406,6 +406,11 @@ func (bc *BlockChain) SetHead(head uint64) error {
406406 }
407407 }
408408 rawdb .WriteHeadBlockHash (db , newHeadBlock .Hash ())
409+
410+ // Degrade the chain markers if they are explicitly reverted.
411+ // In thoery we should update all in-memory markers in the
412+ // last step, however the direction of SetHead is from high
413+ // to low, so it's safe the update in-memory markers directly.
409414 bc .currentBlock .Store (newHeadBlock )
410415 headBlockGauge .Update (int64 (newHeadBlock .NumberU64 ()))
411416 }
@@ -418,6 +423,11 @@ func (bc *BlockChain) SetHead(head uint64) error {
418423 newHeadFastBlock = bc .genesisBlock
419424 }
420425 rawdb .WriteHeadFastBlockHash (db , newHeadFastBlock .Hash ())
426+
427+ // Degrade the chain markers if they are explicitly reverted.
428+ // In thoery we should update all in-memory markers in the
429+ // last step, however the direction of SetHead is from high
430+ // to low, so it's safe the update in-memory markers directly.
421431 bc .currentFastBlock .Store (newHeadFastBlock )
422432 headFastBlockGauge .Update (int64 (newHeadFastBlock .NumberU64 ()))
423433 }
@@ -892,7 +902,7 @@ func (bc *BlockChain) Rollback(chain []common.Hash) {
892902 for i := len (chain ) - 1 ; i >= 0 ; i -- {
893903 hash := chain [i ]
894904
895- // Degrade the chain markers if they are explictly reverted.
905+ // Degrade the chain markers if they are explicitly reverted.
896906 // In thoery we should update all in-memory markers in the
897907 // last step, however the direction of rollback is from high
898908 // to low, so it's safe the update in-memory markers directly.
@@ -904,13 +914,13 @@ func (bc *BlockChain) Rollback(chain []common.Hash) {
904914 }
905915 if currentFastBlock := bc .CurrentFastBlock (); currentFastBlock .Hash () == hash {
906916 newFastBlock := bc .GetBlock (currentFastBlock .ParentHash (), currentFastBlock .NumberU64 ()- 1 )
907- rawdb .WriteHeadFastBlockHash (batch , newFastBlock . Hash ())
917+ rawdb .WriteHeadFastBlockHash (batch , currentFastBlock . ParentHash ())
908918 bc .currentFastBlock .Store (newFastBlock )
909919 headFastBlockGauge .Update (int64 (newFastBlock .NumberU64 ()))
910920 }
911921 if currentBlock := bc .CurrentBlock (); currentBlock .Hash () == hash {
912922 newBlock := bc .GetBlock (currentBlock .ParentHash (), currentBlock .NumberU64 ()- 1 )
913- rawdb .WriteHeadBlockHash (batch , newBlock . Hash ())
923+ rawdb .WriteHeadBlockHash (batch , currentBlock . ParentHash ())
914924 bc .currentBlock .Store (newBlock )
915925 headBlockGauge .Update (int64 (newBlock .NumberU64 ()))
916926 }
@@ -1246,7 +1256,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
12461256
12471257var lastWrite uint64
12481258
1249- // writeBlockWithState writes only the block and its metadata to the database,
1259+ // writeBlockWithoutState writes only the block and its metadata to the database,
12501260// but does not write any state. This is used to construct competing side forks
12511261// up to the point where they exceed the canonical total difficulty.
12521262func (bc * BlockChain ) writeBlockWithoutState (block * types.Block , td * big.Int ) (err error ) {
0 commit comments