|
@@ -63,7 +63,6 @@ var (
|
|
|
// codebase, inherently breaking if the engine is swapped out. Please put common
|
|
// codebase, inherently breaking if the engine is swapped out. Please put common
|
|
|
// error types into the consensus package.
|
|
// error types into the consensus package.
|
|
|
var (
|
|
var (
|
|
|
- errLargeBlockTime = errors.New("timestamp too big")
|
|
|
|
|
errZeroBlockTime = errors.New("timestamp equals parent's")
|
|
errZeroBlockTime = errors.New("timestamp equals parent's")
|
|
|
errTooManyUncles = errors.New("too many uncles")
|
|
errTooManyUncles = errors.New("too many uncles")
|
|
|
errDuplicateUncle = errors.New("duplicate uncle")
|
|
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)
|
|
return fmt.Errorf("extra-data too long: %d > %d", len(header.Extra), params.MaximumExtraDataSize)
|
|
|
}
|
|
}
|
|
|
// Verify the header's timestamp
|
|
// 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
|
|
return consensus.ErrFutureBlock
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if header.Time.Cmp(parent.Time) <= 0 {
|
|
|
|
|
|
|
+ if header.Time <= parent.Time {
|
|
|
return errZeroBlockTime
|
|
return errZeroBlockTime
|
|
|
}
|
|
}
|
|
|
// Verify the block's difficulty based in it's timestamp and parent's difficulty
|
|
// 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 {
|
|
if expected.Cmp(header.Difficulty) != 0 {
|
|
|
return fmt.Errorf("invalid difficulty: have %v, want %v", header.Difficulty, expected)
|
|
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)
|
|
// ) + 2^(periodCount - 2)
|
|
|
|
|
|
|
|
bigTime := new(big.Int).SetUint64(time)
|
|
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
|
|
// holds intermediate values to make the algo easier to read & audit
|
|
|
x := new(big.Int)
|
|
x := new(big.Int)
|
|
@@ -408,7 +403,7 @@ func calcDifficultyHomestead(time uint64, parent *types.Header) *big.Int {
|
|
|
// ) + 2^(periodCount - 2)
|
|
// ) + 2^(periodCount - 2)
|
|
|
|
|
|
|
|
bigTime := new(big.Int).SetUint64(time)
|
|
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
|
|
// holds intermediate values to make the algo easier to read & audit
|
|
|
x := new(big.Int)
|
|
x := new(big.Int)
|
|
@@ -456,7 +451,7 @@ func calcDifficultyFrontier(time uint64, parent *types.Header) *big.Int {
|
|
|
bigParentTime := new(big.Int)
|
|
bigParentTime := new(big.Int)
|
|
|
|
|
|
|
|
bigTime.SetUint64(time)
|
|
bigTime.SetUint64(time)
|
|
|
- bigParentTime.Set(parent.Time)
|
|
|
|
|
|
|
+ bigParentTime.SetUint64(parent.Time)
|
|
|
|
|
|
|
|
if bigTime.Sub(bigTime, bigParentTime).Cmp(params.DurationLimit) < 0 {
|
|
if bigTime.Sub(bigTime, bigParentTime).Cmp(params.DurationLimit) < 0 {
|
|
|
diff.Add(parent.Difficulty, adjust)
|
|
diff.Add(parent.Difficulty, adjust)
|
|
@@ -558,7 +553,7 @@ func (ethash *Ethash) Prepare(chain consensus.ChainReader, header *types.Header)
|
|
|
if parent == nil {
|
|
if parent == nil {
|
|
|
return consensus.ErrUnknownAncestor
|
|
return consensus.ErrUnknownAncestor
|
|
|
}
|
|
}
|
|
|
- header.Difficulty = ethash.CalcDifficulty(chain, header.Time.Uint64(), parent)
|
|
|
|
|
|
|
+ header.Difficulty = ethash.CalcDifficulty(chain, header.Time, parent)
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|