diff options
author | Sonic <sonic@dexon.org> | 2018-11-26 14:50:20 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2018-12-19 20:54:27 +0800 |
commit | 4fc432d83179e85489944b454b7dad9cbbf8ab0a (patch) | |
tree | 82d420cad96f9955241d67700b23c70c767884ef | |
parent | 8bf44330423b3a8a6370fdafd11f82a01065e249 (diff) | |
download | dexon-4fc432d83179e85489944b454b7dad9cbbf8ab0a.tar.gz dexon-4fc432d83179e85489944b454b7dad9cbbf8ab0a.tar.zst dexon-4fc432d83179e85489944b454b7dad9cbbf8ab0a.zip |
core: commit states at snapshot height (#49)
-rw-r--r-- | core/blockchain.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/core/blockchain.go b/core/blockchain.go index 2355e9490..34975913c 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 } |