Skip to content

Commit 61ba56f

Browse files
committed
core, light: fix linter
1 parent 51390a5 commit 61ba56f

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

core/blockchain.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -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

12471257
var 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.
12521262
func (bc *BlockChain) writeBlockWithoutState(block *types.Block, td *big.Int) (err error) {

core/headerchain.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,10 @@ func (hc *HeaderChain) SetHead(head uint64, updateFn UpdateHeadBlocksCallback, d
519519
if err := markerBatch.Write(); err != nil {
520520
log.Crit("Failed to update chain markers", "error", err)
521521
}
522+
hc.currentHeader.Store(parent)
523+
hc.currentHeaderHash = parentHash
524+
headHeaderGauge.Update(parent.Number.Int64())
525+
522526
// Remove the relative data from the database.
523527
if delFn != nil {
524528
delFn(batch, hash, num)
@@ -527,10 +531,6 @@ func (hc *HeaderChain) SetHead(head uint64, updateFn UpdateHeadBlocksCallback, d
527531
rawdb.DeleteHeader(batch, hash, num)
528532
rawdb.DeleteTd(batch, hash, num)
529533
rawdb.DeleteCanonicalHash(batch, num)
530-
531-
hc.currentHeader.Store(parent)
532-
hc.currentHeaderHash = parentHash
533-
headHeaderGauge.Update(parent.Number.Int64())
534534
}
535535
// Flush all accumulated deletions.
536536
if err := batch.Write(); err != nil {

light/lightchain.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ func (lc *LightChain) ResetWithGenesisBlock(genesis *types.Block) {
206206
}
207207
lc.genesisBlock = genesis
208208
lc.hc.SetGenesis(lc.genesisBlock.Header())
209+
lc.hc.SetCurrentHeader(lc.genesisBlock.Header())
209210
}
210211

211212
// Accessors
@@ -329,7 +330,7 @@ func (lc *LightChain) Rollback(chain []common.Hash) {
329330
for i := len(chain) - 1; i >= 0; i-- {
330331
hash := chain[i]
331332

332-
// Degrade the chain markers if they are explictly reverted.
333+
// Degrade the chain markers if they are explicitly reverted.
333334
// In thoery we should update all in-memory markers in the
334335
// last step, however the direction of rollback is from high
335336
// to low, so it's safe the update in-memory markers directly.

0 commit comments

Comments
 (0)