From 92b83a260bd7030e1709277a14f4b23d922422ab Mon Sep 17 00:00:00 2001 From: Derek May <32908855+riddlez666@users.noreply.github.com> Date: Thu, 15 Mar 2018 09:08:35 -0700 Subject: [PATCH] Test of EXPDiff --- consensus/ethash/consensus.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 422d8e0049..59712f45d9 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -298,11 +298,11 @@ func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Heade next := new(big.Int).Add(parent.Number, big1) switch { case config.IsByzantium(next): - return calcDifficultyByzantium(time, parent) + return calcDifficultyEGEM(time, parent) case config.IsHomestead(next): - return calcDifficultyHomestead(time, parent) + return calcDifficultyEGEM(time, parent) default: - return calcDifficultyFrontier(time, parent) + return calcDifficultyEGEM(time, parent) } } @@ -458,6 +458,26 @@ func calcDifficultyFrontier(time uint64, parent *types.Header) *big.Int { return diff } +func calcDifficultyEGEM(time uint64, parent *types.Header) *big.Int { + diff := new(big.Int) + adjust := new(big.Int).Div(parent.Difficulty, big10) + bigTime := new(big.Int) + bigParentTime := new(big.Int) + + bigTime.SetUint64(time) + bigParentTime.Set(parent.Time) + + if bigTime.Sub(bigTime, bigParentTime).Cmp(params.DurationLimit) < 0 { + diff.Add(parent.Difficulty, adjust) + } else { + diff.Sub(parent.Difficulty, adjust) + } + if diff.Cmp(params.MinimumDifficulty) < 0 { + diff.Set(params.MinimumDifficulty) + } + return diff +} + // VerifySeal implements consensus.Engine, checking whether the given block satisfies // the PoW difficulty requirements. func (ethash *Ethash) VerifySeal(chain consensus.ChainReader, header *types.Header) error {