aboutsummaryrefslogtreecommitdiffstats
path: root/core/blockchain.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2019-02-08 17:11:31 +0800
committerMartin Holst Swende <martin@swende.se>2019-02-10 00:45:23 +0800
commit4da209290831720b0f61754b92dabefd5cb35b6d (patch)
treed9ceb8d0d69786e604376493a2697c94bc05aa06 /core/blockchain.go
parent3ab9dcc3bd17cdbb731ca7da829a3bd7b5e1bc1e (diff)
downloaddexon-4da209290831720b0f61754b92dabefd5cb35b6d.tar
dexon-4da209290831720b0f61754b92dabefd5cb35b6d.tar.gz
dexon-4da209290831720b0f61754b92dabefd5cb35b6d.tar.bz2
dexon-4da209290831720b0f61754b92dabefd5cb35b6d.tar.lz
dexon-4da209290831720b0f61754b92dabefd5cb35b6d.tar.xz
dexon-4da209290831720b0f61754b92dabefd5cb35b6d.tar.zst
dexon-4da209290831720b0f61754b92dabefd5cb35b6d.zip
core: fix pruner panic when importing low-diff-large-sidechain
Diffstat (limited to 'core/blockchain.go')
-rw-r--r--core/blockchain.go28
1 files changed, 17 insertions, 11 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index fa1c254b3..0d2d71b4d 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -972,20 +972,26 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
triedb.Cap(limit - ethdb.IdealBatchSize)
}
// Find the next state trie we need to commit
- header := bc.GetHeaderByNumber(current - triesInMemory)
- chosen := header.Number.Uint64()
+ chosen := current - triesInMemory
// If we exceeded out time allowance, flush an entire trie to disk
if bc.gcproc > bc.cacheConfig.TrieTimeLimit {
- // If we're exceeding limits but haven't reached a large enough memory gap,
- // warn the user that the system is becoming unstable.
- if chosen < lastWrite+triesInMemory && bc.gcproc >= 2*bc.cacheConfig.TrieTimeLimit {
- log.Info("State in memory for too long, committing", "time", bc.gcproc, "allowance", bc.cacheConfig.TrieTimeLimit, "optimum", float64(chosen-lastWrite)/triesInMemory)
+ // If the header is missing (canonical chain behind), we're reorging a low
+ // diff sidechain. Suspend committing until this operation is completed.
+ header := bc.GetHeaderByNumber(chosen)
+ if header == nil {
+ log.Warn("Reorg in progress, trie commit postponed", "number", chosen)
+ } else {
+ // If we're exceeding limits but haven't reached a large enough memory gap,
+ // warn the user that the system is becoming unstable.
+ if chosen < lastWrite+triesInMemory && bc.gcproc >= 2*bc.cacheConfig.TrieTimeLimit {
+ log.Info("State in memory for too long, committing", "time", bc.gcproc, "allowance", bc.cacheConfig.TrieTimeLimit, "optimum", float64(chosen-lastWrite)/triesInMemory)
+ }
+ // Flush an entire trie and restart the counters
+ triedb.Commit(header.Root, true)
+ lastWrite = chosen
+ bc.gcproc = 0
}
- // Flush an entire trie and restart the counters
- triedb.Commit(header.Root, true)
- lastWrite = chosen
- bc.gcproc = 0
}
// Garbage collect anything below our required write retention
for !bc.triegc.Empty() {
@@ -1317,7 +1323,7 @@ func (bc *BlockChain) insertSidechain(block *types.Block, it *insertIterator) (i
if err := bc.WriteBlockWithoutState(block, externTd); err != nil {
return it.index, nil, nil, err
}
- log.Debug("Inserted sidechain block", "number", block.Number(), "hash", block.Hash(),
+ log.Debug("Injected sidechain block", "number", block.Number(), "hash", block.Hash(),
"diff", block.Difficulty(), "elapsed", common.PrettyDuration(time.Since(start)),
"txs", len(block.Transactions()), "gas", block.GasUsed(), "uncles", len(block.Uncles()),
"root", block.Root())