Skip to content

Commit 392a7a5

Browse files
lukasz-golebiewskistrauss-m
authored andcommitted
[ETCM-942] Muir Glacier (#1107)
* [ETCM-942] Add Muir Glacier block height to configs * [ETCM-942] Implement Muir Glacier delay * [ETCM-942] Make difficulty costants more readable
1 parent e486b9b commit 392a7a5

File tree

11 files changed

+74
-27
lines changed

11 files changed

+74
-27
lines changed

src/it/scala/io/iohk/ethereum/txExecTest/ECIP1017Test.scala

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,12 @@ class ECIP1017Test extends AnyFlatSpec with Matchers {
2929
maxCodeSize = None,
3030
chainId = 0x3d.toByte,
3131
networkId = 1,
32-
forkBlockNumbers = ForkBlockNumbers(
32+
forkBlockNumbers = ForkBlockNumbers.Empty.copy(
3333
frontierBlockNumber = 0,
3434
homesteadBlockNumber = 1150000,
35-
difficultyBombPauseBlockNumber = Long.MaxValue,
36-
difficultyBombContinueBlockNumber = Long.MaxValue,
37-
difficultyBombRemovalBlockNumber = Long.MaxValue,
38-
eip106BlockNumber = Long.MaxValue,
3935
eip150BlockNumber = 2500000,
4036
eip160BlockNumber = 3000000,
41-
eip155BlockNumber = 3000000,
42-
eip161BlockNumber = Long.MaxValue,
43-
byzantiumBlockNumber = Long.MaxValue,
44-
constantinopleBlockNumber = Long.MaxValue,
45-
istanbulBlockNumber = Long.MaxValue,
46-
atlantisBlockNumber = Long.MaxValue,
47-
aghartaBlockNumber = Long.MaxValue,
48-
phoenixBlockNumber = Long.MaxValue,
49-
petersburgBlockNumber = Long.MaxValue,
50-
ecip1098BlockNumber = Long.MaxValue,
51-
ecip1097BlockNumber = Long.MaxValue,
52-
ecip1099BlockNumber = Long.MaxValue,
53-
ecip1049BlockNumber = None,
54-
magnetoBlockNumber = Long.MaxValue
37+
eip155BlockNumber = 3000000
5538
),
5639
customGenesisFileOpt = None,
5740
customGenesisJsonOpt = None,

src/main/resources/conf/chains/etc-chain.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@
101101
# https://ecips.ethereumclassic.org/ECIPs/ecip-1099
102102
ecip1099-block-number = "11700000"
103103

104+
# Muir Glacier fork block number
105+
# https://eips.ethereum.org/EIPS/eip-2387
106+
muir-glacier-block-number = "1000000000000000000"
107+
104108
# Magneto EVM and Protocol Upgrades
105109
# https://ecips.ethereumclassic.org/ECIPs/ecip-1103
106110
magneto-block-number = "13189133"

src/main/resources/conf/chains/eth-chain.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@
9898
# https://ecips.ethereumclassic.org/ECIPs/ecip-1099
9999
ecip1099-block-number = "1000000000000000000"
100100

101+
# Muir Glacier fork block number
102+
# https://eips.ethereum.org/EIPS/eip-2387
103+
muir-glacier-block-number = "9200000"
104+
101105
# Magneto EVM and Protocol Upgrades
102106
# https://ecips.ethereumclassic.org/ECIPs/ecip-1103
103107
magneto-block-number = "1000000000000000000"

src/main/resources/conf/chains/mordor-chain.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@
9999
# https://ecips.ethereumclassic.org/ECIPs/ecip-1099
100100
ecip1099-block-number = "2520000"
101101

102+
# Muir Glacier fork block number
103+
# https://eips.ethereum.org/EIPS/eip-2387
104+
muir-glacier-block-number = "1000000000000000000"
105+
102106
# Magneto EVM and Protocol Upgrades
103107
# https://ecips.ethereumclassic.org/ECIPs/ecip-1103
104108
magneto-block-number = "3985893"

src/main/resources/conf/chains/ropsten-chain.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@
102102
# https://ecips.ethereumclassic.org/ECIPs/ecip-1099
103103
ecip1099-block-number = "1000000000000000000"
104104

105+
# Muir Glacier fork block number
106+
# https://eips.ethereum.org/EIPS/eip-2387
107+
muir-glacier-block-number = "7117117"
108+
105109
# Magneto EVM and Protocol Upgrades
106110
# https://ecips.ethereumclassic.org/ECIPs/ecip-1103
107111
magneto-block-number = "1000000000000000000"

src/main/resources/conf/chains/test-chain.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@
9999
# https://ecips.ethereumclassic.org/ECIPs/ecip-1099
100100
ecip1099-block-number = "1000000000000000000"
101101

102+
# Muir Glacier fork block number
103+
# https://eips.ethereum.org/EIPS/eip-2387
104+
muir-glacier-block-number = "1000000000000000000"
105+
102106
# Magneto EVM and Protocol Upgrades
103107
# https://ecips.ethereumclassic.org/ECIPs/ecip-1103
104108
magneto-block-number = "1000000000000000000"

src/main/resources/conf/chains/testnet-internal-nomad-chain.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@
9898
# https://ecips.ethereumclassic.org/ECIPs/ecip-1099
9999
ecip1099-block-number = "1000000000000000000"
100100

101+
# Muir Glacier fork block number
102+
# https://eips.ethereum.org/EIPS/eip-2387
103+
muir-glacier-block-number = "1000000000000000000"
104+
101105
# Magneto EVM and Protocol Upgrades
102106
# https://ecips.ethereumclassic.org/ECIPs/ecip-1103
103107
magneto-block-number = "1000000000000000000"

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import io.iohk.ethereum.utils.BlockchainConfig
66

77
object EthashDifficultyCalculator extends DifficultyCalculator {
88
import DifficultyCalculator._
9-
private val ExpDifficultyPeriod: Int = 100000
10-
private val ByzantiumRelaxDifficulty: BigInt = 3000000
11-
private val ConstantinopleRelaxDifficulty: BigInt = 5000000
9+
private val ExpDifficultyPeriod: Int = 100_000
10+
private val ByzantiumRelaxDifficulty: BigInt = 3_000_000
11+
private val ConstantinopleRelaxDifficulty: BigInt = 5_000_000
12+
private val MuirGlacierRelaxDifficulty: BigInt = 9_000_000
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/main/scala/io/iohk/ethereum/utils/BlockchainConfig.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ case class ForkBlockNumbers(
6060
ecip1097BlockNumber: BigInt,
6161
ecip1049BlockNumber: Option[BigInt],
6262
ecip1099BlockNumber: BigInt,
63+
muirGlacierBlockNumber: BigInt,
6364
magnetoBlockNumber: BigInt
6465
) {
6566
def all: List[BigInt] = this.productIterator.toList.flatMap {
@@ -96,6 +97,7 @@ object ForkBlockNumbers {
9697
ecip1097BlockNumber = Long.MaxValue,
9798
ecip1099BlockNumber = Long.MaxValue,
9899
ecip1049BlockNumber = None,
100+
muirGlacierBlockNumber = Long.MaxValue,
99101
magnetoBlockNumber = Long.MaxValue
100102
)
101103
}
@@ -167,6 +169,7 @@ object BlockchainConfig {
167169
val allowedMinersPublicKeys = readPubKeySet(blockchainConfig, "allowed-miners")
168170

169171
val ecip1099BlockNumber: BigInt = BigInt(blockchainConfig.getString("ecip1099-block-number"))
172+
val muirGlacierBlockNumber: BigInt = BigInt(blockchainConfig.getString("muir-glacier-block-number"))
170173
val magnetoBlockNumber: BigInt = BigInt(blockchainConfig.getString("magneto-block-number"))
171174

172175
val capabilities: List[Capability] =
@@ -196,6 +199,7 @@ object BlockchainConfig {
196199
ecip1097BlockNumber = ecip1097BlockNumber,
197200
ecip1049BlockNumber = ecip1049BlockNumber,
198201
ecip1099BlockNumber = ecip1099BlockNumber,
202+
muirGlacierBlockNumber = muirGlacierBlockNumber,
199203
magnetoBlockNumber = magnetoBlockNumber
200204
),
201205
treasuryAddress = treasuryAddress,

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 {

src/test/scala/io/iohk/ethereum/forkid/ForkIdSpec.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ForkIdSpec extends AnyWordSpec with Matchers {
2626

2727
"gatherForks for the eth chain correctly" in {
2828
val res = config.blockchains.map { case (name, conf) => (name, gatherForks(conf)) }
29-
res("eth") shouldBe List(1150000, 1920000, 2463000, 2675000, 4370000, 7280000, 9069000)
29+
res("eth") shouldBe List(1150000, 1920000, 2463000, 2675000, 4370000, 7280000, 9069000, 9200000)
3030
}
3131

3232
"create correct ForkId for ETH mainnet blocks" in {
@@ -51,9 +51,11 @@ class ForkIdSpec extends AnyWordSpec with Matchers {
5151
Some(9069000)
5252
) // First and last Constantinople, first Petersburg block
5353
create(9068999) shouldBe ForkId(0x668db0afL, Some(9069000)) // Last Petersburg block
54-
// TODO: Add Muir Glacier and Berlin
55-
create(9069000) shouldBe ForkId(0x879d6e30L, None) // First Istanbul block
56-
create(12644529) shouldBe ForkId(0x879d6e30L, None) // Today Istanbul block
54+
create(9069000) shouldBe ForkId(0x879d6e30L, Some(9200000)) // First Istanbul block
55+
create(9200000 - 1) shouldBe ForkId(0x879d6e30L, Some(9200000)) // Last Istanbul block
56+
create(9200000) shouldBe ForkId(0xe029e991L, None) // First Muir Glacier block
57+
create(12644529) shouldBe ForkId(0xe029e991L, None) // Today Muir Glacier block
58+
// TODO: Add Berlin
5759
}
5860

5961
"create correct ForkId for ETC mainnet blocks" in {

0 commit comments

Comments
 (0)