Skip to content

Commit 7edc71c

Browse files
[ETCM-942] Implement Muir Glacier delay
1 parent 1baa951 commit 7edc71c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,23 @@ 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(_.copy(difficultyBombRemovalBlockNumber = BigInt("1000000000000"), difficultyBombPauseBlockNumber = 0, difficultyBombContinueBlockNumber = 0, muirGlacierBlockNumber = 9200000))
260+
261+
val parentHeader: BlockHeader =
262+
validParentBlockHeader.copy(number = 9200000 - 1, unixTimestamp = 1525176000, difficulty = BigInt("22627021745803"))
263+
val parent = Block(parentHeader, parentBody)
264+
265+
val blockNumber: BigInt = parentHeader.number + 1
266+
val blockTimestamp: Long = parentHeader.unixTimestamp + 6
267+
268+
val difficulty: BigInt = EthashDifficultyCalculator.calculateDifficulty(blockNumber, blockTimestamp, parent.header)(blockchainConfigWithoutDifficultyBombRemoval)
269+
val blockDifficultyWihtoutBomb = BigInt("22638070096265")
270+
271+
difficulty shouldBe blockDifficultyWihtoutBomb
272+
}
273+
257274
// FIXME: Replace with mocked miner validators once we have them
258275
object BlockValidatorWithPowMocked extends BlockHeaderValidatorSkeleton() {
259276

@@ -388,6 +405,7 @@ class EthashBlockHeaderValidatorSpec
388405
byzantiumBlockNumber = 4370000,
389406
constantinopleBlockNumber = 7280000,
390407
istanbulBlockNumber = 9069000,
408+
muirGlacierBlockNumber = 9200000,
391409
eip106BlockNumber = 0
392410
),
393411
daoForkConfig = Some(new DaoForkConfig {

0 commit comments

Comments
 (0)