From 35d85e250bc98271d8d9e318fac5ff1a97e97acc Mon Sep 17 00:00:00 2001 From: Nathan <122502194+NathanBSC@users.noreply.github.com> Date: Wed, 11 Oct 2023 16:17:17 +0800 Subject: [PATCH] core: write head block hash when shutdown (#1912) --- core/blockchain.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/blockchain.go b/core/blockchain.go index bb3320d252..ad9c40c190 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -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 { @@ -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()) + }) } } } @@ -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")