Skip to content

Commit 698550f

Browse files
[ETCM-942] Implement Muir Glacier delay
1 parent 5f9d97e commit 698550f

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/main/scala/io/iohk/ethereum/consensus/pow/difficulty/EthashDifficultyCalculator.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ object EthashDifficultyCalculator extends DifficultyCalculator {
99
private val ExpDifficultyPeriod: Int = 100000
1010
private val ByzantiumRelaxDifficulty: BigInt = 3000000
1111
private val ConstantinopleRelaxDifficulty: BigInt = 5000000
12+
private val MuirGlacierRelaxDifficulty: BigInt = 9000000
1213

1314
def calculateDifficulty(blockNumber: BigInt, blockTimestamp: Long, parentHeader: BlockHeader)(implicit
1415
blockchainConfig: BlockchainConfig
@@ -32,8 +33,10 @@ object EthashDifficultyCalculator extends DifficultyCalculator {
3233
if (blockNumber < difficultyBombRemovalBlockNumber) {
3334
// calculate a fake block number for the ice-age delay
3435
val fakeBlockNumber: BigInt =
36+
// https://eips.ethereum.org/EIPS/eip-2384
37+
if (blockNumber >= muirGlacierBlockNumber) (blockNumber - MuirGlacierRelaxDifficulty).max(0)
3538
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1234.md
36-
if (blockNumber >= constantinopleBlockNumber) (blockNumber - ConstantinopleRelaxDifficulty).max(0)
39+
else if (blockNumber >= constantinopleBlockNumber) (blockNumber - ConstantinopleRelaxDifficulty).max(0)
3740
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-649.md
3841
else if (blockNumber >= byzantiumBlockNumber) (blockNumber - ByzantiumRelaxDifficulty).max(0)
3942
else blockNumber

src/test/scala/io/iohk/ethereum/consensus/pow/validators/EthashBlockHeaderValidatorSpec.scala

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,36 @@ class EthashBlockHeaderValidatorSpec
254254
difficulty shouldBe afterRewardReductionBlockHeader.difficulty
255255
}
256256

257+
it should "properly calculate the difficulty after muir glacier delay" in new EphemBlockchainTestSetup {
258+
val blockchainConfigWithoutDifficultyBombRemoval: BlockchainConfig =
259+
blockchainConfig.withUpdatedForkBlocks(
260+
_.copy(
261+
difficultyBombRemovalBlockNumber = BigInt("1000000000000"),
262+
difficultyBombPauseBlockNumber = 0,
263+
difficultyBombContinueBlockNumber = 0,
264+
muirGlacierBlockNumber = 9200000
265+
)
266+
)
267+
268+
val parentHeader: BlockHeader =
269+
validParentBlockHeader.copy(
270+
number = 9200000 - 1,
271+
unixTimestamp = 1525176000,
272+
difficulty = BigInt("22627021745803")
273+
)
274+
val parent = Block(parentHeader, parentBody)
275+
276+
val blockNumber: BigInt = parentHeader.number + 1
277+
val blockTimestamp: Long = parentHeader.unixTimestamp + 6
278+
279+
val difficulty: BigInt = EthashDifficultyCalculator.calculateDifficulty(blockNumber, blockTimestamp, parent.header)(
280+
blockchainConfigWithoutDifficultyBombRemoval
281+
)
282+
val blockDifficultyWihtoutBomb = BigInt("22638070096265")
283+
284+
difficulty shouldBe blockDifficultyWihtoutBomb
285+
}
286+
257287
// FIXME: Replace with mocked miner validators once we have them
258288
object BlockValidatorWithPowMocked extends BlockHeaderValidatorSkeleton() {
259289

@@ -388,6 +418,7 @@ class EthashBlockHeaderValidatorSpec
388418
byzantiumBlockNumber = 4370000,
389419
constantinopleBlockNumber = 7280000,
390420
istanbulBlockNumber = 9069000,
421+
muirGlacierBlockNumber = 9200000,
391422
eip106BlockNumber = 0
392423
),
393424
daoForkConfig = Some(new DaoForkConfig {

0 commit comments

Comments
 (0)