Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Commit

Permalink
Remove difficulty bomb for Atlantis difficulty calculation (#69)
Browse files Browse the repository at this point in the history
* Removed difficulty bomb for atlantis difficulty calculation

* Skipped tests that include difficulty change from non-existant difficulty bomb ETH -> ETC
  • Loading branch information
austinabell authored and noot committed Jun 18, 2019
1 parent 19664f5 commit d8c1243
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
19 changes: 0 additions & 19 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ func CalcDifficulty(config *ChainConfig, time uint64, parent *types.Header) *big

// Some weird constants to avoid constant memory allocs for them.
var (
expDiffPeriod = big.NewInt(100000)
big1 = big.NewInt(1)
big2 = big.NewInt(2)
big9 = big.NewInt(9)
Expand All @@ -323,7 +322,6 @@ var (
)

func calcDifficultyAtlantis(time uint64, parent *types.Header) *big.Int {
bombDelayFromParent := new(big.Int).Sub(big.NewInt(3000000), big1)
// https://github.com/ethereum/EIPs/issues/100.
// algorithm:
// diff = (parent_diff +
Expand Down Expand Up @@ -358,23 +356,6 @@ func calcDifficultyAtlantis(time uint64, parent *types.Header) *big.Int {
if x.Cmp(params.MinimumDifficulty) < 0 {
x.Set(params.MinimumDifficulty)
}
// calculate a fake block number for the ice-age delay
// Specification: https://eips.ethereum.org/EIPS/eip-1234
fakeBlockNumber := new(big.Int)
if parent.Number.Cmp(bombDelayFromParent) >= 0 {
fakeBlockNumber = fakeBlockNumber.Sub(parent.Number, bombDelayFromParent)
}
// for the exponential factor
periodCount := fakeBlockNumber
periodCount.Div(periodCount, expDiffPeriod)

// the exponential factor, commonly referred to as "the bomb"
// diff = diff + 2^(periodCount - 2)
if periodCount.Cmp(big1) > 0 {
y.Sub(periodCount, big2)
y.Exp(big2, y, nil)
x.Add(x, y)
}
return x
}

Expand Down
4 changes: 4 additions & 0 deletions tests/difficulty_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ func (test *DifficultyTest) runDifficulty(t *testing.T, config *core.ChainConfig
UncleHash: test.UncleHash,
}

if config.IsAtlantis(parentNumber) && parent.Number.Cmp(big.NewInt(3199999)) >= 0 {
return nil
}

// Check to make sure difficulty is above minimum
if parentDifficulty.Cmp(params.MinimumDifficulty) < 0 {
t.Skip("difficulty below minimum")
Expand Down

0 comments on commit d8c1243

Please sign in to comment.