mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
Remove calcDifficultyFrontier
This commit is contained in:
parent
c0ef263663
commit
010d757e2e
1 changed files with 0 additions and 39 deletions
|
|
@ -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
|
// the difficulty that a new block should have when created at time
|
||||||
// given the parent block's time and difficulty.
|
// given the parent block's time and difficulty.
|
||||||
func CalcDifficulty(config *params.ChainConfig, time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int {
|
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
|
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2.mediawiki
|
||||||
// algorithm:
|
// algorithm:
|
||||||
// diff = (parent_diff +
|
// diff = (parent_diff +
|
||||||
|
|
@ -315,37 +307,6 @@ func calcDifficultyHomestead(time, parentTime uint64, parentNumber, parentDiff *
|
||||||
return x
|
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.
|
// CalcGasLimit computes the gas limit of the next block after parent.
|
||||||
// The result may be modified by the caller.
|
// The result may be modified by the caller.
|
||||||
// This is miner strategy, not consensus protocol.
|
// This is miner strategy, not consensus protocol.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue