mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core/blockchain: trigger disk flush near hard fork
This commit is contained in:
parent
a73f3f4518
commit
be3ce0815b
2 changed files with 27 additions and 1 deletions
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue