wip: prevent nodes from regenerating from genesis

This commit is contained in:
Martin Holst Swende 2019-10-04 11:44:55 +02:00
parent be3ce0815b
commit 03c5a021d8
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
2 changed files with 20 additions and 4 deletions

View file

@ -1317,7 +1317,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
// If we exceeded out time allowance, flush an entire trie to disk // If we exceeded out time allowance, flush an entire trie to disk
flushToDisk := bc.gcproc > bc.cacheConfig.TrieTimeLimit || flushToDisk := bc.gcproc > bc.cacheConfig.TrieTimeLimit ||
bc.chainConfig.isForkBlock(current+1) bc.chainConfig.IsForkBlock(current+1)
if flushToDisk { 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.
@ -1824,6 +1824,21 @@ func (bc *BlockChain) insertSideChain(block *types.Block, it *insertIterator) (i
if parent == nil { if parent == nil {
return it.index, nil, nil, errors.New("missing parent") return it.index, nil, nil, errors.New("missing parent")
} }
if parent.Number.Cmp(common.Big1) <= 0 {
// What most likely happened, is that the even though the common ancestor
// is not that far back, it is still earlier than the fast-sync pivot point.
// In that scenario, the only place from where we can start restoring
// the state is the genesis, which is probably not what the user
// wants, or expects: a fast-sync that switches over to a full-sync.
//
// There is a high likelihood that this sidechain is actually an invalid
// chain, but for some reason longer. If the user actually wants to land
// on the other chain, it would be better to do a fast-sync to that one,
// instead of progressing further via sidechain import
log.Warn("Sidechain import aborted, due to extreme size. Please re-sync if you believe this is in error",
"start", numbers[len(numbers)-1], "count", len(numbers))
return it.index, nil, nil, errors.New("state regeneration task too large")
}
// Import all the pruned blocks to make the state available // Import all the pruned blocks to make the state available
var ( var (
blocks []*types.Block blocks []*types.Block

View file

@ -470,8 +470,8 @@ func isForked(s, head *big.Int) bool {
} }
// isForkBlock returns whether the given block number designates a fork block // isForkBlock returns whether the given block number designates a fork block
func (c *ChainConfig) isForkBlock(n uint64) bool { func (c *ChainConfig) IsForkBlock(n uint64) bool {
number := big.NewInt(n) number := new(big.Int).SetUint64(n)
for _, forkNum := range []*big.Int{ for _, forkNum := range []*big.Int{
c.HomesteadBlock, c.HomesteadBlock,
c.DAOForkBlock, c.DAOForkBlock,
@ -483,7 +483,7 @@ func (c *ChainConfig) isForkBlock(n uint64) bool {
c.PetersburgBlock, c.PetersburgBlock,
c.IstanbulBlock, c.IstanbulBlock,
} { } {
h := forkNum.Cmp(number) h := number.Cmp(forkNum)
if h < 0 { if h < 0 {
return false return false
} }
@ -491,6 +491,7 @@ func (c *ChainConfig) isForkBlock(n uint64) bool {
return true return true
} }
} }
return false
} }
func configNumEqual(x, y *big.Int) bool { func configNumEqual(x, y *big.Int) bool {