From 010d757e2e69c3196f78722096e74cc0be317fdf Mon Sep 17 00:00:00 2001 From: Julian Yap Date: Fri, 2 Dec 2016 22:23:20 -1000 Subject: [PATCH] Remove calcDifficultyFrontier --- core/block_validator.go | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/core/block_validator.go b/core/block_validator.go index dbc98c88a7..6eac3d5133 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -259,14 +259,6 @@ func ValidateHeader(config *params.ChainConfig, pow pow.PoW, header *types.Heade // the difficulty that a new block should have when created at time // given the parent block's time and difficulty. func CalcDifficulty(config *params.ChainConfig, time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int { - if config.IsHomestead(new(big.Int).Add(parentNumber, common.Big1)) { - return calcDifficultyHomestead(time, parentTime, parentNumber, parentDiff) - } else { - return calcDifficultyFrontier(time, parentTime, parentNumber, parentDiff) - } -} - -func calcDifficultyHomestead(time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int { // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2.mediawiki // algorithm: // diff = (parent_diff + @@ -315,37 +307,6 @@ func calcDifficultyHomestead(time, parentTime uint64, parentNumber, parentDiff * return x } -func calcDifficultyFrontier(time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int { - diff := new(big.Int) - adjust := new(big.Int).Div(parentDiff, params.DifficultyBoundDivisor) - bigTime := new(big.Int) - bigParentTime := new(big.Int) - - bigTime.SetUint64(time) - bigParentTime.SetUint64(parentTime) - - if bigTime.Sub(bigTime, bigParentTime).Cmp(params.DurationLimit) < 0 { - diff.Add(parentDiff, adjust) - } else { - diff.Sub(parentDiff, adjust) - } - if diff.Cmp(params.MinimumDifficulty) < 0 { - diff.Set(params.MinimumDifficulty) - } - - periodCount := new(big.Int).Add(parentNumber, common.Big1) - periodCount.Div(periodCount, ExpDiffPeriod) - if periodCount.Cmp(common.Big1) > 0 { - // diff = diff + 2^(periodCount - 2) - expDiff := periodCount.Sub(periodCount, common.Big2) - expDiff.Exp(common.Big2, expDiff, nil) - diff.Add(diff, expDiff) - diff = common.BigMax(diff, params.MinimumDifficulty) - } - - return diff -} - // CalcGasLimit computes the gas limit of the next block after parent. // The result may be modified by the caller. // This is miner strategy, not consensus protocol.