@@ -406,6 +406,11 @@ func (bc *BlockChain) SetHead(head uint64) error {
406
406
}
407
407
}
408
408
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.
409
414
bc .currentBlock .Store (newHeadBlock )
410
415
headBlockGauge .Update (int64 (newHeadBlock .NumberU64 ()))
411
416
}
@@ -418,6 +423,11 @@ func (bc *BlockChain) SetHead(head uint64) error {
418
423
newHeadFastBlock = bc .genesisBlock
419
424
}
420
425
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.
421
431
bc .currentFastBlock .Store (newHeadFastBlock )
422
432
headFastBlockGauge .Update (int64 (newHeadFastBlock .NumberU64 ()))
423
433
}
@@ -892,7 +902,7 @@ func (bc *BlockChain) Rollback(chain []common.Hash) {
892
902
for i := len (chain ) - 1 ; i >= 0 ; i -- {
893
903
hash := chain [i ]
894
904
895
- // Degrade the chain markers if they are explictly reverted.
905
+ // Degrade the chain markers if they are explicitly reverted.
896
906
// In thoery we should update all in-memory markers in the
897
907
// last step, however the direction of rollback is from high
898
908
// to low, so it's safe the update in-memory markers directly.
@@ -904,13 +914,13 @@ func (bc *BlockChain) Rollback(chain []common.Hash) {
904
914
}
905
915
if currentFastBlock := bc .CurrentFastBlock (); currentFastBlock .Hash () == hash {
906
916
newFastBlock := bc .GetBlock (currentFastBlock .ParentHash (), currentFastBlock .NumberU64 ()- 1 )
907
- rawdb .WriteHeadFastBlockHash (batch , newFastBlock . Hash ())
917
+ rawdb .WriteHeadFastBlockHash (batch , currentFastBlock . ParentHash ())
908
918
bc .currentFastBlock .Store (newFastBlock )
909
919
headFastBlockGauge .Update (int64 (newFastBlock .NumberU64 ()))
910
920
}
911
921
if currentBlock := bc .CurrentBlock (); currentBlock .Hash () == hash {
912
922
newBlock := bc .GetBlock (currentBlock .ParentHash (), currentBlock .NumberU64 ()- 1 )
913
- rawdb .WriteHeadBlockHash (batch , newBlock . Hash ())
923
+ rawdb .WriteHeadBlockHash (batch , currentBlock . ParentHash ())
914
924
bc .currentBlock .Store (newBlock )
915
925
headBlockGauge .Update (int64 (newBlock .NumberU64 ()))
916
926
}
@@ -1246,7 +1256,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
1246
1256
1247
1257
var lastWrite uint64
1248
1258
1249
- // writeBlockWithState writes only the block and its metadata to the database,
1259
+ // writeBlockWithoutState writes only the block and its metadata to the database,
1250
1260
// but does not write any state. This is used to construct competing side forks
1251
1261
// up to the point where they exceed the canonical total difficulty.
1252
1262
func (bc * BlockChain ) writeBlockWithoutState (block * types.Block , td * big.Int ) (err error ) {
0 commit comments