aboutsummaryrefslogtreecommitdiffstats
path: root/consensus/ethash
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 /consensus/ethash
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 'consensus/ethash')
-rw-r--r--consensus/ethash/algorithm_test.go2
-rw-r--r--consensus/ethash/consensus.go21
-rw-r--r--consensus/ethash/consensus_test.go2
3 files changed, 10 insertions, 15 deletions
diff --git a/consensus/ethash/algorithm_test.go b/consensus/ethash/algorithm_test.go
index c58479e28..cf8552f3a 100644
--- a/consensus/ethash/algorithm_test.go
+++ b/consensus/ethash/algorithm_test.go
@@ -716,7 +716,7 @@ func TestConcurrentDiskCacheGeneration(t *testing.T) {
Difficulty: big.NewInt(167925187834220),
GasLimit: 4015682,
GasUsed: 0,
- Time: big.NewInt(1488928920),
+ Time: 1488928920,
Extra: []byte("www.bw.com"),
MixDigest: common.HexToHash("0x3e140b0784516af5e5ec6730f2fb20cca22f32be399b9e4ad77d32541f798cd0"),
Nonce: types.EncodeNonce(0xf400cd0006070c49),
diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go
index 62e3f8fca..fb9a396ae 100644
--- a/consensus/ethash/consensus.go
+++ b/consensus/ethash/consensus.go
@@ -63,7 +63,6 @@ var (
// codebase, inherently breaking if the engine is swapped out. Please put common
// error types into the consensus package.
var (
- errLargeBlockTime = errors.New("timestamp too big")
errZeroBlockTime = errors.New("timestamp equals parent's")
errTooManyUncles = errors.New("too many uncles")
errDuplicateUncle = errors.New("duplicate uncle")
@@ -242,20 +241,16 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
return fmt.Errorf("extra-data too long: %d > %d", len(header.Extra), params.MaximumExtraDataSize)
}
// Verify the header's timestamp
- if uncle {
- if header.Time.Cmp(math.MaxBig256) > 0 {
- return errLargeBlockTime
- }
- } else {
- if header.Time.Cmp(big.NewInt(time.Now().Add(allowedFutureBlockTime).Unix())) > 0 {
+ if !uncle {
+ if header.Time > uint64(time.Now().Add(allowedFutureBlockTime).Unix()) {
return consensus.ErrFutureBlock
}
}
- if header.Time.Cmp(parent.Time) <= 0 {
+ if header.Time <= parent.Time {
return errZeroBlockTime
}
// Verify the block's difficulty based in it's timestamp and parent's difficulty
- expected := ethash.CalcDifficulty(chain, header.Time.Uint64(), parent)
+ expected := ethash.CalcDifficulty(chain, header.Time, parent)
if expected.Cmp(header.Difficulty) != 0 {
return fmt.Errorf("invalid difficulty: have %v, want %v", header.Difficulty, expected)
@@ -349,7 +344,7 @@ func makeDifficultyCalculator(bombDelay *big.Int) func(time uint64, parent *type
// ) + 2^(periodCount - 2)
bigTime := new(big.Int).SetUint64(time)
- bigParentTime := new(big.Int).Set(parent.Time)
+ bigParentTime := new(big.Int).SetUint64(parent.Time)
// holds intermediate values to make the algo easier to read & audit
x := new(big.Int)
@@ -408,7 +403,7 @@ func calcDifficultyHomestead(time uint64, parent *types.Header) *big.Int {
// ) + 2^(periodCount - 2)
bigTime := new(big.Int).SetUint64(time)
- bigParentTime := new(big.Int).Set(parent.Time)
+ bigParentTime := new(big.Int).SetUint64(parent.Time)
// holds intermediate values to make the algo easier to read & audit
x := new(big.Int)
@@ -456,7 +451,7 @@ func calcDifficultyFrontier(time uint64, parent *types.Header) *big.Int {
bigParentTime := new(big.Int)
bigTime.SetUint64(time)
- bigParentTime.Set(parent.Time)
+ bigParentTime.SetUint64(parent.Time)
if bigTime.Sub(bigTime, bigParentTime).Cmp(params.DurationLimit) < 0 {
diff.Add(parent.Difficulty, adjust)
@@ -558,7 +553,7 @@ func (ethash *Ethash) Prepare(chain consensus.ChainReader, header *types.Header)
if parent == nil {
return consensus.ErrUnknownAncestor
}
- header.Difficulty = ethash.CalcDifficulty(chain, header.Time.Uint64(), parent)
+ header.Difficulty = ethash.CalcDifficulty(chain, header.Time, parent)
return nil
}
diff --git a/consensus/ethash/consensus_test.go b/consensus/ethash/consensus_test.go
index 438a99dd6..675737d9e 100644
--- a/consensus/ethash/consensus_test.go
+++ b/consensus/ethash/consensus_test.go
@@ -76,7 +76,7 @@ func TestCalcDifficulty(t *testing.T) {
number := new(big.Int).Sub(test.CurrentBlocknumber, big.NewInt(1))
diff := CalcDifficulty(config, test.CurrentTimestamp, &types.Header{
Number: number,
- Time: new(big.Int).SetUint64(test.ParentTimestamp),
+ Time: test.ParentTimestamp,
Difficulty: test.ParentDifficulty,
})
if diff.Cmp(test.CurrentDifficulty) != 0 {