aboutsummaryrefslogtreecommitdiffstats
path: root/core/blockchain.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2018-02-23 20:02:33 +0800
committerGitHub <noreply@github.com>2018-02-23 20:02:33 +0800
commit89f914c03075012603267d207de0f433740dcd30 (patch)
treeb238412877c8803159fb0841babc2985ca3cd486 /core/blockchain.go
parentfb5d085234c16f18d27be10043c53da3230cd9a7 (diff)
downloadgo-tangerine-89f914c03075012603267d207de0f433740dcd30.tar
go-tangerine-89f914c03075012603267d207de0f433740dcd30.tar.gz
go-tangerine-89f914c03075012603267d207de0f433740dcd30.tar.bz2
go-tangerine-89f914c03075012603267d207de0f433740dcd30.tar.lz
go-tangerine-89f914c03075012603267d207de0f433740dcd30.tar.xz
go-tangerine-89f914c03075012603267d207de0f433740dcd30.tar.zst
go-tangerine-89f914c03075012603267d207de0f433740dcd30.zip
core: flush out trie cache more meaningfully on stop (#16143)
* core: flush out trie cache more meaningfully on stop * core: upgrade legacy tests to chain maker
Diffstat (limited to 'core/blockchain.go')
-rw-r--r--core/blockchain.go25
1 files changed, 12 insertions, 13 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 644df123c..53fe7ee2e 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -648,22 +648,21 @@ func (bc *BlockChain) Stop() {
bc.wg.Wait()
// Ensure the state of a recent block is also stored to disk before exiting.
- // It is fine if this state does not exist (fast start/stop cycle), but it is
- // advisable to leave an N block gap from the head so 1) a restart loads up
- // the last N blocks as sync assistance to remote nodes; 2) a restart during
- // a (small) reorg doesn't require deep reprocesses; 3) chain "repair" from
- // missing states are constantly tested.
- //
- // This may be tuned a bit on mainnet if its too annoying to reprocess the last
- // N blocks.
+ // We're writing three different states to catch different restart scenarios:
+ // - HEAD: So we don't need to reprocess any blocks in the general case
+ // - HEAD-1: So we don't do large reorgs if our HEAD becomes an uncle
+ // - HEAD-127: So we have a hard limit on the number of blocks reexecuted
if !bc.cacheConfig.Disabled {
triedb := bc.stateCache.TrieDB()
- if number := bc.CurrentBlock().NumberU64(); number >= triesInMemory {
- recent := bc.GetBlockByNumber(bc.CurrentBlock().NumberU64() - triesInMemory + 1)
- log.Info("Writing cached state to disk", "block", recent.Number(), "hash", recent.Hash(), "root", recent.Root())
- if err := triedb.Commit(recent.Root(), true); err != nil {
- log.Error("Failed to commit recent state trie", "err", err)
+ for _, offset := range []uint64{0, 1, triesInMemory - 1} {
+ if number := bc.CurrentBlock().NumberU64(); number > offset {
+ recent := bc.GetBlockByNumber(number - offset)
+
+ log.Info("Writing cached state to disk", "block", recent.Number(), "hash", recent.Hash(), "root", recent.Root())
+ if err := triedb.Commit(recent.Root(), true); err != nil {
+ log.Error("Failed to commit recent state trie", "err", err)
+ }
}
}
for !bc.triegc.Empty() {