From de6031e18c5a134fc6a4d72fdd1237201e42b720 Mon Sep 17 00:00:00 2001 From: Sonic Date: Mon, 26 Nov 2018 14:50:20 +0800 Subject: core: commit states at snapshot height (#49) --- core/blockchain.go | 9 +++++++-- 1 file 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 } -- cgit v1.2.3