aboutsummaryrefslogtreecommitdiffstats
path: root/core/chain_makers.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2017-02-02 05:36:51 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2017-05-18 15:05:58 +0800
commit10a57fc3d45cbc59d6c8eeb0f7f2b93a71e8f4c9 (patch)
tree170eb09bf51c802894d9335570d7319a2f86ef15 /core/chain_makers.go
parenta2f23ca9b181fa4409fdee3076316f3127038b9b (diff)
downloaddexon-10a57fc3d45cbc59d6c8eeb0f7f2b93a71e8f4c9.tar
dexon-10a57fc3d45cbc59d6c8eeb0f7f2b93a71e8f4c9.tar.gz
dexon-10a57fc3d45cbc59d6c8eeb0f7f2b93a71e8f4c9.tar.bz2
dexon-10a57fc3d45cbc59d6c8eeb0f7f2b93a71e8f4c9.tar.lz
dexon-10a57fc3d45cbc59d6c8eeb0f7f2b93a71e8f4c9.tar.xz
dexon-10a57fc3d45cbc59d6c8eeb0f7f2b93a71e8f4c9.tar.zst
dexon-10a57fc3d45cbc59d6c8eeb0f7f2b93a71e8f4c9.zip
consensus, core/*, params: metropolis preparation refactor
This commit is a preparation for the upcoming metropolis hardfork. It prepares the state, core and vm packages such that integration with metropolis becomes less of a hassle. * Difficulty calculation requires header instead of individual parameters * statedb.StartRecord renamed to statedb.Prepare and added Finalise method required by metropolis, which removes unwanted accounts from the state (i.e. selfdestruct) * State keeps record of destructed objects (in addition to dirty objects) * core/vm pre-compiles may now return errors * core/vm pre-compiles gas check now take the full byte slice as argument instead of just the size * core/vm now keeps several hard-fork instruction tables instead of a single instruction table and removes the need for hard-fork checks in the instructions * core/vm contains a empty restruction function which is added in preparation of metropolis write-only mode operations * Adds the bn256 curve * Adds and sets the metropolis chain config block parameters (2^64-1)
Diffstat (limited to 'core/chain_makers.go')
-rw-r--r--core/chain_makers.go22
1 files changed, 15 insertions, 7 deletions
diff --git a/core/chain_makers.go b/core/chain_makers.go
index f34279ba0..967744282 100644
--- a/core/chain_makers.go
+++ b/core/chain_makers.go
@@ -84,7 +84,7 @@ func (b *BlockGen) AddTx(tx *types.Transaction) {
if b.gasPool == nil {
b.SetCoinbase(common.Address{})
}
- b.statedb.StartRecord(tx.Hash(), common.Hash{}, len(b.txs))
+ b.statedb.Prepare(tx.Hash(), common.Hash{}, len(b.txs))
receipt, _, err := ApplyTransaction(b.config, nil, &b.header.Coinbase, b.gasPool, b.statedb, b.header, tx, b.header.GasUsed, vm.Config{})
if err != nil {
panic(err)
@@ -142,7 +142,7 @@ func (b *BlockGen) OffsetTime(seconds int64) {
if b.header.Time.Cmp(b.parent.Header().Time) <= 0 {
panic("block time out of range")
}
- b.header.Difficulty = ethash.CalcDifficulty(b.config, b.header.Time.Uint64(), b.parent.Time().Uint64(), b.parent.Number(), b.parent.Difficulty())
+ b.header.Difficulty = ethash.CalcDifficulty(b.config, b.header.Time.Uint64(), b.parent.Header())
}
// GenerateChain creates a chain of n blocks. The first block's
@@ -209,15 +209,23 @@ func makeHeader(config *params.ChainConfig, parent *types.Block, state *state.St
} else {
time = new(big.Int).Add(parent.Time(), big.NewInt(10)) // block time is fixed at 10 seconds
}
+ parentHeader := parent.Header()
+ // adjust the parent time
+ parentHeader.Time = new(big.Int).Sub(time, big.NewInt(10))
+
return &types.Header{
Root: state.IntermediateRoot(config.IsEIP158(parent.Number())),
ParentHash: parent.Hash(),
Coinbase: parent.Coinbase(),
- Difficulty: ethash.CalcDifficulty(config, time.Uint64(), new(big.Int).Sub(time, big.NewInt(10)).Uint64(), parent.Number(), parent.Difficulty()),
- GasLimit: CalcGasLimit(parent),
- GasUsed: new(big.Int),
- Number: new(big.Int).Add(parent.Number(), common.Big1),
- Time: time,
+ Difficulty: ethash.CalcDifficulty(config, time.Uint64(), &types.Header{
+ Number: parent.Number(),
+ Time: new(big.Int).Sub(time, big.NewInt(10)),
+ Difficulty: parent.Difficulty(),
+ }),
+ GasLimit: CalcGasLimit(parent),
+ GasUsed: new(big.Int),
+ Number: new(big.Int).Add(parent.Number(), common.Big1),
+ Time: time,
}
}