aboutsummaryrefslogtreecommitdiffstats
path: root/core/chain_makers.go
diff options
context:
space:
mode:
authorMartin Holst Swende <martin@swende.se>2019-04-03 04:28:48 +0800
committerPéter Szilágyi <peterke@gmail.com>2019-04-08 17:00:42 +0800
commitaf401d03a395c21fdb297edb687edf8af3470cb2 (patch)
treed2ee3476c9005ffe1aca7abbe7152765da0efe32 /core/chain_makers.go
parent80a2a35bc3aaf208b5f91a1fb1d803975d4bb01c (diff)
downloaddexon-af401d03a395c21fdb297edb687edf8af3470cb2.tar
dexon-af401d03a395c21fdb297edb687edf8af3470cb2.tar.gz
dexon-af401d03a395c21fdb297edb687edf8af3470cb2.tar.bz2
dexon-af401d03a395c21fdb297edb687edf8af3470cb2.tar.lz
dexon-af401d03a395c21fdb297edb687edf8af3470cb2.tar.xz
dexon-af401d03a395c21fdb297edb687edf8af3470cb2.tar.zst
dexon-af401d03a395c21fdb297edb687edf8af3470cb2.zip
all: simplify timestamps to uint64 (#19372)
* all: simplify timestamps to uint64 * tests: update definitions * clef, faucet, mobile: leftover uint64 fixups * ethash: fix tests * graphql: update schema for timestamp * ethash: remove unused variable
Diffstat (limited to 'core/chain_makers.go')
-rw-r--r--core/chain_makers.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/core/chain_makers.go b/core/chain_makers.go
index 0b5a3d184..d563d85ee 100644
--- a/core/chain_makers.go
+++ b/core/chain_makers.go
@@ -149,12 +149,12 @@ 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, big.NewInt(seconds))
- if b.header.Time.Cmp(b.parent.Header().Time) <= 0 {
+ b.header.Time += uint64(seconds)
+ if b.header.Time <= b.parent.Header().Time {
panic("block time out of range")
}
chainreader := &fakeChainReader{config: b.config}
- b.header.Difficulty = b.engine.CalcDifficulty(chainreader, b.header.Time.Uint64(), b.parent.Header())
+ b.header.Difficulty = b.engine.CalcDifficulty(chainreader, b.header.Time, b.parent.Header())
}
// GenerateChain creates a chain of n blocks. The first block's
@@ -225,20 +225,20 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
}
func makeHeader(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(10)
+ var time uint64
+ if parent.Time() == 0 {
+ time = 10
} else {
- time = new(big.Int).Add(parent.Time(), big.NewInt(10)) // block time is fixed at 10 seconds
+ time = parent.Time() + 10 // 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{
+ Difficulty: engine.CalcDifficulty(chain, time, &types.Header{
Number: parent.Number(),
- Time: new(big.Int).Sub(time, big.NewInt(10)),
+ Time: time - 10,
Difficulty: parent.Difficulty(),
UncleHash: parent.UncleHash(),
}),