aboutsummaryrefslogtreecommitdiffstats
path: root/core/chain_makers.go
diff options
context:
space:
mode:
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,
}
}