Skip to content

Commit

Permalink
core: write head block hash when shutdown (#1912)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanBSC authored Oct 11, 2023
1 parent 43e2c77 commit 35d85e2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,7 @@ func (bc *BlockChain) Stop() {
// - HEAD-127: So we have a hard limit on the number of blocks reexecuted
if !bc.cacheConfig.TrieDirtyDisabled {
triedb := bc.triedb
var once sync.Once

for _, offset := range []uint64{0, 1, bc.triesInMemory - 1} {
if number := bc.CurrentBlock().Number.Uint64(); number > offset {
Expand All @@ -1133,6 +1134,9 @@ func (bc *BlockChain) Stop() {
log.Error("Failed to commit recent state trie", "err", err)
} else {
rawdb.WriteSafePointBlockNumber(bc.db, recent.NumberU64())
once.Do(func() {
rawdb.WriteHeadBlockHash(bc.db, recent.Hash())
})
}
}
}
Expand All @@ -1145,7 +1149,7 @@ func (bc *BlockChain) Stop() {
}
}
for !bc.triegc.Empty() {
go triedb.Dereference(bc.triegc.PopItem())
triedb.Dereference(bc.triegc.PopItem())
}
if size, _ := triedb.Size(); size != 0 {
log.Error("Dangling trie nodes after full cleanup")
Expand Down

0 comments on commit 35d85e2

Please sign in to comment.