core/blockchain: trigger disk flush near hard fork

This commit is contained in:
Martin Holst Swende 2019-10-04 11:18:10 +02:00
parent a73f3f4518
commit be3ce0815b
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
2 changed files with 27 additions and 1 deletions

View file

@ -1316,7 +1316,9 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
chosen := current - TriesInMemory chosen := current - TriesInMemory
// If we exceeded out time allowance, flush an entire trie to disk // 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 // If the header is missing (canonical chain behind), we're reorging a low
// diff sidechain. Suspend committing until this operation is completed. // diff sidechain. Suspend committing until this operation is completed.
header := bc.GetHeaderByNumber(chosen) header := bc.GetHeaderByNumber(chosen)

View file

@ -469,6 +469,30 @@ func isForked(s, head *big.Int) bool {
return s.Cmp(head) <= 0 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 { func configNumEqual(x, y *big.Int) bool {
if x == nil { if x == nil {
return y == nil return y == nil