diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-07-14 23:17:03 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-07-15 21:52:55 +0800 |
commit | 3291235711082759cd7b70253c02150a80d57011 (patch) | |
tree | d8124891fb563f5143a156f415ae7ee7e6a30683 /core/chain_makers.go | |
parent | 461cdb593b9e5bd9ae9ac35c68809a3a29290dcb (diff) | |
download | dexon-3291235711082759cd7b70253c02150a80d57011.tar.gz dexon-3291235711082759cd7b70253c02150a80d57011.tar.zst dexon-3291235711082759cd7b70253c02150a80d57011.zip |
accounts, core, eth: pass chain config for chain maker to test DAO
Diffstat (limited to 'core/chain_makers.go')
-rw-r--r-- | core/chain_makers.go | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/core/chain_makers.go b/core/chain_makers.go index ef0ac66d1..0b9a5f75d 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -26,6 +26,7 @@ import ( "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" + "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/pow" ) @@ -35,7 +36,11 @@ import ( // MakeChainConfig returns a new ChainConfig with the ethereum default chain settings. func MakeChainConfig() *ChainConfig { - return &ChainConfig{HomesteadBlock: big.NewInt(0)} + return &ChainConfig{ + HomesteadBlock: big.NewInt(0), + DAOForkBlock: nil, + DAOForkSupport: true, + } } // FakePow is a non-validating proof of work implementation. @@ -173,10 +178,27 @@ func (b *BlockGen) OffsetTime(seconds int64) { // Blocks created by GenerateChain do not contain valid proof of work // values. Inserting them into BlockChain requires use of FakePow or // a similar non-validating proof of work implementation. -func GenerateChain(parent *types.Block, db ethdb.Database, n int, gen func(int, *BlockGen)) ([]*types.Block, []types.Receipts) { +func GenerateChain(config *ChainConfig, parent *types.Block, db ethdb.Database, n int, gen func(int, *BlockGen)) ([]*types.Block, []types.Receipts) { blocks, receipts := make(types.Blocks, n), make([]types.Receipts, n) genblock := func(i int, h *types.Header, statedb *state.StateDB) (*types.Block, types.Receipts) { b := &BlockGen{parent: parent, i: i, chain: blocks, header: h, statedb: statedb} + + // Mutate the state and block according to any hard-fork specs + if config == nil { + config = MakeChainConfig() + } + if daoBlock := config.DAOForkBlock; daoBlock != nil { + limit := new(big.Int).Add(daoBlock, params.DAOForkExtraRange) + if h.Number.Cmp(daoBlock) >= 0 && h.Number.Cmp(limit) < 0 { + if config.DAOForkSupport { + h.Extra = common.CopyBytes(params.DAOForkBlockExtra) + } + } + } + if config.DAOForkSupport && config.DAOForkBlock != nil && config.DAOForkBlock.Cmp(h.Number) == 0 { + ApplyDAOHardFork(statedb) + } + // Execute any user modifications to the block and finalize it if gen != nil { gen(i, b) } @@ -261,7 +283,7 @@ func makeHeaderChain(parent *types.Header, n int, db ethdb.Database, seed int) [ // makeBlockChain creates a deterministic chain of blocks rooted at parent. func makeBlockChain(parent *types.Block, n int, db ethdb.Database, seed int) []*types.Block { - blocks, _ := GenerateChain(parent, db, n, func(i int, b *BlockGen) { + blocks, _ := GenerateChain(nil, parent, db, n, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{0: byte(seed), 19: byte(i)}) }) return blocks |