diff --git a/core/blockchain.go b/core/blockchain.go index 9fb02b1482..acc6a4dea0 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1316,7 +1316,9 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. chosen := current - TriesInMemory // If we exceeded out time allowance, flush an entire trie to disk - if bc.gcproc > bc.cacheConfig.TrieTimeLimit { + flushToDisk := bc.gcproc > bc.cacheConfig.TrieTimeLimit || + bc.chainConfig.isForkBlock(current+1) + if flushToDisk { // 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) diff --git a/params/config.go b/params/config.go index a400485248..37becf74e7 100644 --- a/params/config.go +++ b/params/config.go @@ -469,6 +469,30 @@ func isForked(s, head *big.Int) bool { return s.Cmp(head) <= 0 } +// isForkBlock returns whether the given block number designates a fork block +func (c *ChainConfig) isForkBlock(n uint64) bool { + number := big.NewInt(n) + for _, forkNum := range []*big.Int{ + c.HomesteadBlock, + c.DAOForkBlock, + c.EIP150Block, + c.EIP155Block, + c.EIP158Block, + c.ByzantiumBlock, + c.ConstantinopleBlock, + c.PetersburgBlock, + c.IstanbulBlock, + } { + h := forkNum.Cmp(number) + if h < 0 { + return false + } + if h == 0 { + return true + } + } +} + func configNumEqual(x, y *big.Int) bool { if x == nil { return y == nil