Skip to content

Commit f977617

Browse files
committed
Generate hardforks definition from genesis file
1 parent 1fdbd72 commit f977617

File tree

3 files changed

+22
-224
lines changed

3 files changed

+22
-224
lines changed

crates/chainspec/res/genesis/mainnet.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616
"grayGlacierBlock": 0,
1717
"mergeNetsplitBlock": 0,
1818
"shanghaiTime": 0,
19+
"cancunTime": 1717009201,
20+
"pragueTime": 1755716401,
1921
"bedrockBlock": 0,
2022
"regolithTime": 0,
2123
"canyonTime": 0,
2224
"ecotoneTime": 1717009201,
2325
"fjordTime": 1733947201,
2426
"graniteTime": 1738958401,
27+
"holoceneTime": 1744052401,
28+
"isthmusTime": 1755716401,
2529
"terminalTotalDifficulty": 0,
2630
"terminalTotalDifficultyPassed": true,
2731
"optimism": {

crates/chainspec/src/fraxtal.rs

Lines changed: 10 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,17 @@
1-
//! Chain specification for the Base Mainnet network.
1+
//! Chain specification for the Fraxtal Mainnet network.
22
33
use std::sync::{Arc, LazyLock};
44

5-
use alloy_chains::Chain;
6-
use alloy_primitives::b256;
7-
use alloy_primitives::U256;
8-
use reth_chainspec::{BaseFeeParams, BaseFeeParamsKind, ChainHardforks, ChainSpec, ForkCondition};
9-
use reth_ethereum_forks::EthereumHardfork;
10-
use reth_ethereum_forks::Hardfork;
11-
use reth_optimism_chainspec::make_op_genesis_header;
5+
use alloy_genesis::Genesis;
126
use reth_optimism_chainspec::OpChainSpec;
13-
use reth_optimism_forks::OpHardfork;
14-
use reth_primitives_traits::SealedHeader;
157

16-
/// The Base mainnet spec
8+
/// The Fraxtal Mainnet spec.
9+
///
10+
/// This uses `OpChainSpec::from(genesis)` to dynamically extract hardforks
11+
/// from the genesis file instead of hardcoding them, ensuring the computed
12+
/// genesis hash matches the expected value.
1713
pub(crate) static FRAXTAL_MAINNET: LazyLock<Arc<OpChainSpec>> = LazyLock::new(|| {
18-
let genesis = serde_json::from_str(include_str!("../res/genesis/mainnet.json"))
19-
.expect("Can't deserialize Fraxtal genesis json");
20-
let hardforks = FRAXTAL_MAINNET_HARDFORKS.clone();
21-
OpChainSpec {
22-
inner: ChainSpec {
23-
chain: Chain::fraxtal(),
24-
genesis_header: SealedHeader::new(
25-
make_op_genesis_header(&genesis, &hardforks),
26-
b256!("0x521982bd54239dc71269eefb58601762cc15cfb2978e0becb46af7962ed6bfaa"),
27-
),
28-
genesis,
29-
paris_block_and_final_difficulty: Some((0, U256::from(0))),
30-
hardforks,
31-
base_fee_params: BaseFeeParamsKind::Variable(
32-
vec![
33-
(EthereumHardfork::London.boxed(), BaseFeeParams::optimism()),
34-
(
35-
OpHardfork::Canyon.boxed(),
36-
BaseFeeParams {
37-
max_change_denominator: 250,
38-
elasticity_multiplier: 10,
39-
},
40-
),
41-
]
42-
.into(),
43-
),
44-
..Default::default()
45-
},
46-
}
47-
.into()
48-
});
49-
50-
static FRAXTAL_MAINNET_HARDFORKS: LazyLock<ChainHardforks> = LazyLock::new(|| {
51-
ChainHardforks::new(vec![
52-
(EthereumHardfork::Frontier.boxed(), ForkCondition::Block(0)),
53-
(EthereumHardfork::Homestead.boxed(), ForkCondition::Block(0)),
54-
(EthereumHardfork::Tangerine.boxed(), ForkCondition::Block(0)),
55-
(
56-
EthereumHardfork::SpuriousDragon.boxed(),
57-
ForkCondition::Block(0),
58-
),
59-
(EthereumHardfork::Byzantium.boxed(), ForkCondition::Block(0)),
60-
(
61-
EthereumHardfork::Constantinople.boxed(),
62-
ForkCondition::Block(0),
63-
),
64-
(
65-
EthereumHardfork::Petersburg.boxed(),
66-
ForkCondition::Block(0),
67-
),
68-
(EthereumHardfork::Istanbul.boxed(), ForkCondition::Block(0)),
69-
(
70-
EthereumHardfork::MuirGlacier.boxed(),
71-
ForkCondition::Block(0),
72-
),
73-
(EthereumHardfork::Berlin.boxed(), ForkCondition::Block(0)),
74-
(EthereumHardfork::London.boxed(), ForkCondition::Block(0)),
75-
(
76-
EthereumHardfork::ArrowGlacier.boxed(),
77-
ForkCondition::Block(0),
78-
),
79-
(
80-
EthereumHardfork::GrayGlacier.boxed(),
81-
ForkCondition::Block(0),
82-
),
83-
(
84-
EthereumHardfork::Paris.boxed(),
85-
ForkCondition::TTD {
86-
activation_block_number: 0,
87-
fork_block: Some(0),
88-
total_difficulty: U256::ZERO,
89-
},
90-
),
91-
(OpHardfork::Bedrock.boxed(), ForkCondition::Block(0)),
92-
(OpHardfork::Regolith.boxed(), ForkCondition::Timestamp(0)),
93-
(
94-
EthereumHardfork::Shanghai.boxed(),
95-
ForkCondition::Timestamp(0),
96-
),
97-
(OpHardfork::Canyon.boxed(), ForkCondition::Timestamp(0)),
98-
(
99-
EthereumHardfork::Cancun.boxed(),
100-
ForkCondition::Timestamp(1717009201),
101-
),
102-
(
103-
OpHardfork::Ecotone.boxed(),
104-
ForkCondition::Timestamp(1717009201),
105-
),
106-
(
107-
OpHardfork::Fjord.boxed(),
108-
ForkCondition::Timestamp(1733947201),
109-
),
110-
(
111-
OpHardfork::Granite.boxed(),
112-
ForkCondition::Timestamp(1738958401),
113-
),
114-
(
115-
OpHardfork::Holocene.boxed(),
116-
ForkCondition::Timestamp(1744052401),
117-
),
118-
(
119-
EthereumHardfork::Prague.boxed(),
120-
ForkCondition::Timestamp(1755716401),
121-
),
122-
(
123-
OpHardfork::Isthmus.boxed(),
124-
ForkCondition::Timestamp(1755716401),
125-
),
126-
])
14+
let genesis: Genesis = serde_json::from_str(include_str!("../res/genesis/mainnet.json"))
15+
.expect("Can't deserialize Fraxtal mainnet genesis json");
16+
Arc::new(OpChainSpec::from(genesis))
12717
});
Lines changed: 8 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,17 @@
1-
//! Chain specification for the Base Mainnet network.
1+
//! Chain specification for the Fraxtal Hoodi Testnet network.
22
33
use std::sync::{Arc, LazyLock};
44

5-
use alloy_chains::Chain;
65
use alloy_genesis::Genesis;
7-
use alloy_primitives::b256;
8-
use alloy_primitives::U256;
9-
use reth_chainspec::{BaseFeeParams, BaseFeeParamsKind, ChainHardforks, ChainSpec, ForkCondition};
10-
use reth_ethereum_forks::EthereumHardfork;
11-
use reth_ethereum_forks::Hardfork;
12-
use reth_optimism_chainspec::make_op_genesis_header;
136
use reth_optimism_chainspec::OpChainSpec;
14-
use reth_optimism_forks::OpHardfork;
15-
use reth_primitives_traits::SealedHeader;
167

17-
/// The Base mainnet spec
8+
/// The Fraxtal Hoodi Testnet spec.
9+
///
10+
/// This uses `OpChainSpec::from(genesis)` to dynamically extract hardforks
11+
/// from the genesis file instead of hardcoding them, ensuring the computed
12+
/// genesis hash matches the expected value.
1813
pub(crate) static FRAXTAL_HOODI_TESTNET: LazyLock<Arc<OpChainSpec>> = LazyLock::new(|| {
1914
let genesis: Genesis = serde_json::from_str(include_str!("../res/genesis/hoodi-testnet.json"))
20-
.expect("Can't deserialize Fraxtal testnet genesis json");
21-
let hardforks = FRAXTAL_HOODI_TESTNET_HARDFORKS.clone();
22-
OpChainSpec {
23-
inner: ChainSpec {
24-
chain: Chain::from_id(genesis.config.chain_id),
25-
genesis_header: SealedHeader::new(
26-
make_op_genesis_header(&genesis, &hardforks),
27-
b256!("0x910f5c4084b63fd860d0c2f9a04615115a5a991254700b39ba072290dbd77489"),
28-
),
29-
genesis,
30-
paris_block_and_final_difficulty: Some((0, U256::from(0))),
31-
hardforks,
32-
base_fee_params: BaseFeeParamsKind::Variable(
33-
vec![
34-
(EthereumHardfork::London.boxed(), BaseFeeParams::optimism()),
35-
(
36-
OpHardfork::Canyon.boxed(),
37-
BaseFeeParams {
38-
max_change_denominator: 250,
39-
elasticity_multiplier: 10,
40-
},
41-
),
42-
]
43-
.into(),
44-
),
45-
..Default::default()
46-
},
47-
}
48-
.into()
49-
});
50-
51-
static FRAXTAL_HOODI_TESTNET_HARDFORKS: LazyLock<ChainHardforks> = LazyLock::new(|| {
52-
ChainHardforks::new(vec![
53-
(EthereumHardfork::Frontier.boxed(), ForkCondition::Block(0)),
54-
(EthereumHardfork::Homestead.boxed(), ForkCondition::Block(0)),
55-
(EthereumHardfork::Tangerine.boxed(), ForkCondition::Block(0)),
56-
(
57-
EthereumHardfork::SpuriousDragon.boxed(),
58-
ForkCondition::Block(0),
59-
),
60-
(EthereumHardfork::Byzantium.boxed(), ForkCondition::Block(0)),
61-
(
62-
EthereumHardfork::Constantinople.boxed(),
63-
ForkCondition::Block(0),
64-
),
65-
(
66-
EthereumHardfork::Petersburg.boxed(),
67-
ForkCondition::Block(0),
68-
),
69-
(EthereumHardfork::Istanbul.boxed(), ForkCondition::Block(0)),
70-
(
71-
EthereumHardfork::MuirGlacier.boxed(),
72-
ForkCondition::Block(0),
73-
),
74-
(EthereumHardfork::Berlin.boxed(), ForkCondition::Block(0)),
75-
(EthereumHardfork::London.boxed(), ForkCondition::Block(0)),
76-
(
77-
EthereumHardfork::ArrowGlacier.boxed(),
78-
ForkCondition::Block(0),
79-
),
80-
(
81-
EthereumHardfork::GrayGlacier.boxed(),
82-
ForkCondition::Block(0),
83-
),
84-
(
85-
EthereumHardfork::Paris.boxed(),
86-
ForkCondition::TTD {
87-
activation_block_number: 0,
88-
fork_block: Some(0),
89-
total_difficulty: U256::ZERO,
90-
},
91-
),
92-
(OpHardfork::Bedrock.boxed(), ForkCondition::Block(0)),
93-
(OpHardfork::Regolith.boxed(), ForkCondition::Timestamp(0)),
94-
(
95-
EthereumHardfork::Shanghai.boxed(),
96-
ForkCondition::Timestamp(0),
97-
),
98-
(OpHardfork::Canyon.boxed(), ForkCondition::Timestamp(0)),
99-
(
100-
EthereumHardfork::Cancun.boxed(),
101-
ForkCondition::Timestamp(0),
102-
),
103-
(OpHardfork::Ecotone.boxed(), ForkCondition::Timestamp(0)),
104-
(OpHardfork::Fjord.boxed(), ForkCondition::Timestamp(0)),
105-
(OpHardfork::Granite.boxed(), ForkCondition::Timestamp(0)),
106-
(OpHardfork::Holocene.boxed(), ForkCondition::Timestamp(0)),
107-
(
108-
EthereumHardfork::Prague.boxed(),
109-
ForkCondition::Timestamp(0),
110-
),
111-
(OpHardfork::Isthmus.boxed(), ForkCondition::Timestamp(0)),
112-
])
15+
.expect("Can't deserialize Fraxtal hoodi testnet genesis json");
16+
Arc::new(OpChainSpec::from(genesis))
11317
});

0 commit comments

Comments
 (0)