Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

[Constantinople] Added difficulty bomb delay (EIP1234) #54

Merged
merged 2 commits into from
Oct 18, 2018
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
12 changes: 10 additions & 2 deletions header.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ BlockHeader.prototype.canonicalDifficulty = function (parentBlock) {
var dif

if (this._common.hardforkGteHardfork(hardfork, 'byzantium')) {
// max((2 if len(parent.uncles) else 1) - ((timestamp - parent.timestamp) // 9), -99)
// max((2 if len(parent.uncles) else 1) - ((timestamp - parent.timestamp) // 9), -99) (EIP100)
var uncleAddend = parentBlock.header.uncleHash.equals(utils.SHA3_RLP_ARRAY) ? 1 : 2
a = blockTs.sub(parentTs).idivn(9).ineg().iaddn(uncleAddend)
cutoff = new BN(-99)
Expand All @@ -125,8 +125,16 @@ BlockHeader.prototype.canonicalDifficulty = function (parentBlock) {
a = cutoff
}
dif = parentDif.add(offset.mul(a))
}

// Byzantium difficulty bomb delay
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 (num.ltn(0)) {
num = new BN(0)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"homepage": "https://github.com/ethereumjs/ethereumjs-block#readme",
"dependencies": {
"async": "^2.0.1",
"ethereumjs-common": "^0.5.0",
"ethereumjs-common": "^0.6.0",
"ethereumjs-tx": "^1.2.2",
"ethereumjs-util": "^5.0.0",
"merkle-patricia-tree": "^2.1.2"
Expand Down
3 changes: 2 additions & 1 deletion tests/difficulty.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ tape('[Header]: difficulty tests', t => {
const hardforkTestData = {
'chainstart': require('./difficultyFrontier.json').tests,
'homestead': require('./difficultyHomestead.json').tests,
'byzantium': require('./difficultyByzantium.json').tests
'byzantium': require('./difficultyByzantium.json').tests,
'constantinople': require('./difficultyConstantinople.json').tests
}
for (let hardfork in hardforkTestData) {
const testData = hardforkTestData[hardfork]
Expand Down
Loading