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

Remove difficulty bomb for Atlantis difficulty calculation #69

Merged
merged 3 commits into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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