aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSonic <sonic@dexon.org>2018-11-26 14:50:20 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:54 +0800
commitb77acf8ef9f095183b1b4780bc9c57673971ce15 (patch)
tree32c61a9174b9bb3e3074f64af64584bc27d48062
parenteed3c4057d4fa453eedbe4560a7e9367ffcdd1fa (diff)
downloaddexon-b77acf8ef9f095183b1b4780bc9c57673971ce15.tar.gz
dexon-b77acf8ef9f095183b1b4780bc9c57673971ce15.tar.zst
dexon-b77acf8ef9f095183b1b4780bc9c57673971ce15.zip
core: commit states at snapshot height (#49)
-rw-r--r--core/blockchain.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 81e9f05b2..2b172b15c 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -1093,8 +1093,13 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
}
triedb := bc.stateCache.TrieDB()
- // If we're running an archive node, always flush
- if bc.cacheConfig.Disabled {
+ if _, ok := bc.GetRoundHeight(block.Round()); !ok {
+ bc.storeRoundHeight(block.Round(), block.NumberU64())
+ }
+ height, _ := bc.GetRoundHeight(block.Round())
+
+ // If we're running an archive node or the block is snapshot height, always flush
+ if bc.cacheConfig.Disabled || height == block.NumberU64() {
if err := triedb.Commit(root, false); err != nil {
return NonStatTy, err
}