diff options
author | Péter Szilágyi <peterke@gmail.com> | 2019-02-08 17:11:31 +0800 |
---|---|---|
committer | Martin Holst Swende <martin@swende.se> | 2019-02-10 00:45:23 +0800 |
commit | 4da209290831720b0f61754b92dabefd5cb35b6d (patch) | |
tree | d9ceb8d0d69786e604376493a2697c94bc05aa06 /core/chain_makers.go | |
parent | 3ab9dcc3bd17cdbb731ca7da829a3bd7b5e1bc1e (diff) | |
download | dexon-4da209290831720b0f61754b92dabefd5cb35b6d.tar.gz dexon-4da209290831720b0f61754b92dabefd5cb35b6d.tar.zst dexon-4da209290831720b0f61754b92dabefd5cb35b6d.zip |
core: fix pruner panic when importing low-diff-large-sidechain
Diffstat (limited to 'core/chain_makers.go')
-rw-r--r-- | core/chain_makers.go | 59 |
1 files changed, 2 insertions, 57 deletions
diff --git a/core/chain_makers.go b/core/chain_makers.go index 63ca16440..0b5a3d184 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -48,8 +48,6 @@ type BlockGen struct { engine consensus.Engine } -type headerGenFn func(chain consensus.ChainReader, parent *types.Block, state *state.StateDB, engine consensus.Engine) *types.Header - // SetCoinbase sets the coinbase of the generated block. // It can be called at most once. func (b *BlockGen) SetCoinbase(addr common.Address) { @@ -151,7 +149,7 @@ func (b *BlockGen) PrevBlock(index int) *types.Block { // associated difficulty. It's useful to test scenarios where forking is not // tied to chain length directly. func (b *BlockGen) OffsetTime(seconds int64) { - b.header.Time.Add(b.header.Time, new(big.Int).SetInt64(seconds)) + b.header.Time.Add(b.header.Time, big.NewInt(seconds)) if b.header.Time.Cmp(b.parent.Header().Time) <= 0 { panic("block time out of range") } @@ -172,10 +170,6 @@ func (b *BlockGen) OffsetTime(seconds int64) { // values. Inserting them into BlockChain requires use of FakePow or // a similar non-validating proof of work implementation. func GenerateChain(config *params.ChainConfig, parent *types.Block, engine consensus.Engine, db ethdb.Database, n int, gen func(int, *BlockGen)) ([]*types.Block, []types.Receipts) { - return generateChain(config, parent, engine, db, n, gen, makeHeader) -} - -func generateChain(config *params.ChainConfig, parent *types.Block, engine consensus.Engine, db ethdb.Database, n int, gen func(int, *BlockGen), headerGen headerGenFn) ([]*types.Block, []types.Receipts) { if config == nil { config = params.TestChainConfig } @@ -183,8 +177,7 @@ func generateChain(config *params.ChainConfig, parent *types.Block, engine conse chainreader := &fakeChainReader{config: config} genblock := func(i int, parent *types.Block, statedb *state.StateDB) (*types.Block, types.Receipts) { b := &BlockGen{i: i, chain: blocks, parent: parent, statedb: statedb, config: config, engine: engine} - //b.header = makeHeader(chainreader, parent, statedb, b.engine) - b.header = headerGen(chainreader, parent, statedb, b.engine) + b.header = makeHeader(chainreader, parent, statedb, b.engine) // Mutate the state and block according to any hard-fork specs if daoBlock := config.DAOForkBlock; daoBlock != nil { @@ -255,54 +248,6 @@ func makeHeader(chain consensus.ChainReader, parent *types.Block, state *state.S } } -func makeHeaderWithLargeDifficulty(chain consensus.ChainReader, parent *types.Block, state *state.StateDB, engine consensus.Engine) *types.Header { - var time *big.Int - if parent.Time() == nil { - time = big.NewInt(1) - } else { - time = new(big.Int).Add(parent.Time(), big.NewInt(1)) // block time is fixed at 10 seconds - } - - return &types.Header{ - Root: state.IntermediateRoot(chain.Config().IsEIP158(parent.Number())), - ParentHash: parent.Hash(), - Coinbase: parent.Coinbase(), - Difficulty: engine.CalcDifficulty(chain, time.Uint64(), &types.Header{ - Number: parent.Number(), - Time: new(big.Int).Sub(time, big.NewInt(1)), - Difficulty: parent.Difficulty(), - UncleHash: parent.UncleHash(), - }), - GasLimit: CalcGasLimit(parent, parent.GasLimit(), parent.GasLimit()), - Number: new(big.Int).Add(parent.Number(), common.Big1), - Time: time, - } -} - -func makeHeaderWithSmallDifficulty(chain consensus.ChainReader, parent *types.Block, state *state.StateDB, engine consensus.Engine) *types.Header { - var time *big.Int - if parent.Time() == nil { - time = big.NewInt(30) - } else { - time = new(big.Int).Add(parent.Time(), big.NewInt(30)) // block time is fixed at 10 seconds - } - - return &types.Header{ - Root: state.IntermediateRoot(chain.Config().IsEIP158(parent.Number())), - ParentHash: parent.Hash(), - Coinbase: parent.Coinbase(), - Difficulty: engine.CalcDifficulty(chain, time.Uint64(), &types.Header{ - Number: parent.Number(), - Time: new(big.Int).Sub(time, big.NewInt(30)), - Difficulty: parent.Difficulty(), - UncleHash: parent.UncleHash(), - }), - GasLimit: CalcGasLimit(parent, parent.GasLimit(), parent.GasLimit()), - Number: new(big.Int).Add(parent.Number(), common.Big1), - Time: time, - } -} - // makeHeaderChain creates a deterministic chain of headers rooted at parent. func makeHeaderChain(parent *types.Header, n int, engine consensus.Engine, db ethdb.Database, seed int) []*types.Header { blocks := makeBlockChain(types.NewBlockWithHeader(parent), n, engine, db, seed) |