Skip to content

Commit

Permalink
Merge pull request #1245 from ethereumjs/eip3554
Browse files Browse the repository at this point in the history
Implement EIP3554
  • Loading branch information
holgerd77 authored May 9, 2021
2 parents dfc25ee + b2d13a9 commit da5919f
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 16 deletions.
18 changes: 3 additions & 15 deletions packages/block/src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,21 +344,9 @@ export class BlockHeader {
dif = parentDif.add(offset.mul(a))
}

if (this._common.hardforkGteHardfork(hardfork, 'muirGlacier')) {
// Istanbul/Berlin difficulty bomb delay (EIP2384)
num.isubn(9000000)
if (num.ltn(0)) {
num = new BN(0)
}
} else if (this._common.hardforkGteHardfork(hardfork, 'constantinople')) {
// Constantinople difficulty bomb delay (EIP1234)
num.isubn(5000000)
if (num.ltn(0)) {
num = new BN(0)
}
} else if (this._common.hardforkGteHardfork(hardfork, 'byzantium')) {
// Byzantium difficulty bomb delay (EIP649)
num.isubn(3000000)
if (this._common.hardforkGteHardfork(hardfork, 'byzantium')) {
// Get delay as parameter from common
num.isubn(this._common.param('pow', 'difficultyBombDelay'))
if (num.ltn(0)) {
num = new BN(0)
}
Expand Down
18 changes: 18 additions & 0 deletions packages/common/src/eips/3554.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "EIP-3554",
"comment": "Reduction in refunds",
"url": "Difficulty Bomb Delay to December 1st 2021",
"status": "Draft",
"minimumHardfork": "muirGlacier",
"requiredEIPs": [],
"gasConfig": {},
"gasPrices": {},
"vm": {},
"pow": {
"difficultyBombDelay": {
"v": 9500000,
"d": "the amount of blocks to delay the difficulty bomb with"
}
}
}

1 change: 1 addition & 0 deletions packages/common/src/eips/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export const EIPs: eipsType = {
2930: require('./2930.json'),
3529: require('./3529.json'),
3541: require('./3541.json'),
3554: require('./3554.json'),
}
4 changes: 4 additions & 0 deletions packages/common/src/hardforks/byzantium.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
"minerReward": {
"v": "3000000000000000000",
"d": "the amount a miner get rewarded for mining a block"
},
"difficultyBombDelay": {
"v": 3000000,
"d": "the amount of blocks to delay the difficulty bomb with"
}
}
}
4 changes: 4 additions & 0 deletions packages/common/src/hardforks/chainstart.json
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@
"minerReward": {
"v": "5000000000000000000",
"d": "the amount a miner get rewarded for mining a block"
},
"difficultyBombDelay": {
"v": 0,
"d": "the amount of blocks to delay the difficulty bomb with"
}
}
}
4 changes: 4 additions & 0 deletions packages/common/src/hardforks/constantinople.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
"minerReward": {
"v": "2000000000000000000",
"d": "The amount a miner gets rewarded for mining a block"
},
"difficultyBombDelay": {
"v": 5000000,
"d": "the amount of blocks to delay the difficulty bomb with"
}
}
}
10 changes: 9 additions & 1 deletion packages/common/src/hardforks/muirGlacier.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,13 @@
"comment": "HF to delay the difficulty bomb",
"url": "https://eips.ethereum.org/EIPS/eip-2384",
"status": "Final",
"eips": []
"gasConfig": {},
"gasPrices": {},
"vm": {},
"pow": {
"difficultyBombDelay": {
"v": 9000000,
"d": "the amount of blocks to delay the difficulty bomb with"
}
}
}
12 changes: 12 additions & 0 deletions packages/common/tests/eips.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,16 @@ tape('[Common]: Initialization / Chain params', function (t: tape.Test) {

st.end()
})

t.test('returns the right block delay for EIP3554', function (st) {
for (const fork of ['muirGlacier', 'berlin']) {
const c = new Common({ chain: 'mainnet', hardfork: fork })
let delay = c.param('pow', 'difficultyBombDelay')
st.equal(delay, 9000000)
c.setEIPs([3554])
delay = c.param('pow', 'difficultyBombDelay')
st.equal(delay, 9500000)
}
st.end()
})
})

0 comments on commit da5919f

Please sign in to comment.