Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement EIP3554 #1245

Merged
merged 1 commit into from
May 9, 2021
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
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": []
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to remove this field, otherwise the difficulty bomb delay as reported by param() in Common yields the Constantinople one (probably a bug?).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, interesting.

"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()
})
holgerd77 marked this conversation as resolved.
Show resolved Hide resolved
})