mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-21 06:04:33 +00:00
core: update the fast block on chain import at the end of the fast sync phase (#23576)
This commit is contained in:
parent
2baadc6e87
commit
d03859d49e
1 changed files with 7 additions and 14 deletions
|
|
@ -749,11 +749,10 @@ func (bc *BlockChain) writeHeadBlock(block *types.Block, writeBlock bool) {
|
|||
blockHash := block.Hash()
|
||||
blockNumberU64 := block.NumberU64()
|
||||
|
||||
// If the block is on a side chain or an unknown one, force other heads onto it too
|
||||
updateHeads := rawdb.ReadCanonicalHash(bc.db, blockNumberU64) != blockHash
|
||||
|
||||
// Add the block to the canonical chain number scheme and mark as the head
|
||||
batch := bc.db.NewBatch()
|
||||
rawdb.WriteHeadHeaderHash(batch, blockHash)
|
||||
rawdb.WriteHeadFastBlockHash(batch, blockHash)
|
||||
rawdb.WriteCanonicalHash(batch, blockHash, blockNumberU64)
|
||||
rawdb.WriteTxLookupEntriesByBlock(batch, block)
|
||||
rawdb.WriteHeadBlockHash(batch, blockHash)
|
||||
|
|
@ -761,23 +760,17 @@ func (bc *BlockChain) writeHeadBlock(block *types.Block, writeBlock bool) {
|
|||
rawdb.WriteBlock(batch, block)
|
||||
}
|
||||
|
||||
// If the block is better than our head or is on a different chain, force update heads
|
||||
if updateHeads {
|
||||
rawdb.WriteHeadHeaderHash(batch, blockHash)
|
||||
rawdb.WriteHeadFastBlockHash(batch, blockHash)
|
||||
}
|
||||
|
||||
// Flush the whole batch into the disk, exit the node if failed
|
||||
if err := batch.Write(); err != nil {
|
||||
log.Crit("Failed to update chain indexes and markers", "err", err)
|
||||
}
|
||||
|
||||
// Update all in-memory chain markers in the last step
|
||||
if updateHeads {
|
||||
bc.hc.SetCurrentHeader(block.Header())
|
||||
bc.currentFastBlock.Store(block)
|
||||
headFastBlockGauge.Update(int64(blockNumberU64))
|
||||
}
|
||||
bc.hc.SetCurrentHeader(block.Header())
|
||||
|
||||
bc.currentFastBlock.Store(block)
|
||||
headFastBlockGauge.Update(int64(blockNumberU64))
|
||||
|
||||
bc.currentBlock.Store(block)
|
||||
headBlockGauge.Update(int64(block.NumberU64()))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue