Skip to content

Commit

Permalink
Merge pull request ethereum#25 from karalabe/merge-interop-spec-sync6
Browse files Browse the repository at this point in the history
core: overwrite head header and fast block too on block sethead
  • Loading branch information
MariusVanDerWijden committed Oct 5, 2021
2 parents 1216abb + 9562d10 commit 1758b1a
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions core/blockchain.go
Expand Up @@ -717,32 +717,24 @@ func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error {
//
// Note, this function assumes that the `mu` mutex is held!
func (bc *BlockChain) writeHeadBlock(block *types.Block) {
// If the block is on a side chain or an unknown one, force other heads onto it too
updateHeads := rawdb.ReadCanonicalHash(bc.db, block.NumberU64()) != block.Hash()

// Add the block to the canonical chain number scheme and mark as the head
batch := bc.db.NewBatch()
rawdb.WriteHeadHeaderHash(batch, block.Hash())
rawdb.WriteHeadFastBlockHash(batch, block.Hash())
rawdb.WriteCanonicalHash(batch, block.Hash(), block.NumberU64())
rawdb.WriteTxLookupEntriesByBlock(batch, block)
rawdb.WriteHeadBlockHash(batch, block.Hash())

// If the block is better than our head or is on a different chain, force update heads
// TODO(rjl493456442) What if the (header head/fast block head) is lower than the chain
// head? Is it possible in practise?
if updateHeads {
rawdb.WriteHeadHeaderHash(batch, block.Hash())
rawdb.WriteHeadFastBlockHash(batch, block.Hash())
}
// 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(block.NumberU64()))
}
bc.hc.SetCurrentHeader(block.Header())

bc.currentFastBlock.Store(block)
headFastBlockGauge.Update(int64(block.NumberU64()))

bc.currentBlock.Store(block)
headBlockGauge.Update(int64(block.NumberU64()))
}
Expand Down

0 comments on commit 1758b1a

Please sign in to comment.