Skip to content

Commit c3c2dde

Browse files
georgehaoThegaram
andauthored
Feat/add chain spec hardfork (#56)
* add hardfork * complete hardfork lib.rs * complete * add scroll bootnode * remove duplicated code * update * tweak a comment * format * fix hardfork * fix format * fix genesis hash error * update unit test * update * update * remove unused dependence * fix * add std * update * Update crates/net/peers/src/bootnodes/mod.rs Co-authored-by: Péter Garamvölgyi <[email protected]> * address comment * update hardfork * update * fix comment * address comment * address comment * address comment * fix unit test * fix unit test * address comments * fix scroll genesis baseFee * address comments * fix unit test * fix unit test * address comments * address comments * resolve conflct * add hardforks doc * update the doc --------- Co-authored-by: Péter Garamvölgyi <[email protected]>
1 parent 883d508 commit c3c2dde

File tree

19 files changed

+1758
-4
lines changed

19 files changed

+1758
-4
lines changed

Cargo.lock

Lines changed: 35 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ members = [
100100
"crates/rpc/rpc-testing-util/",
101101
"crates/rpc/rpc-types-compat/",
102102
"crates/rpc/rpc/",
103+
"crates/scroll/chainspec",
103104
"crates/scroll/execution",
105+
"crates/scroll/hardforks",
104106
"crates/scroll/primitives",
105107
"crates/scroll/revm",
106108
"crates/scroll/storage",
@@ -415,6 +417,7 @@ reth-scroll-state-commitment = { path = "crates/scroll/state-commitment" }
415417
reth-scroll-trie = { path = "crates/scroll/trie" }
416418
reth-scroll-revm = { path = "crates/scroll/revm" }
417419
reth-scroll-storage = { path = "crates/scroll/storage" }
420+
reth-scroll-forks = { path = "crates/scroll/hardforks" }
418421
reth-stages = { path = "crates/stages/stages" }
419422
reth-stages-api = { path = "crates/stages/api" }
420423
reth-stages-types = { path = "crates/stages/types" }

crates/chainspec/src/spec.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use reth_ethereum_forks::{
2424
};
2525
use reth_network_peers::{
2626
base_nodes, base_testnet_nodes, holesky_nodes, mainnet_nodes, op_nodes, op_testnet_nodes,
27-
sepolia_nodes, NodeRecord,
27+
scroll_nodes, scroll_sepolia_nodes, sepolia_nodes, NodeRecord,
2828
};
2929
use reth_primitives_traits::SealedHeader;
3030
use reth_trie_common::root::state_root_ref_unhashed;
@@ -317,6 +317,13 @@ impl ChainSpec {
317317

318318
/// Get the initial base fee of the genesis block.
319319
pub fn initial_base_fee(&self) -> Option<u64> {
320+
// TODO(scroll): migrate to Chain::scroll() (introduced in https://github.com/alloy-rs/chains/pull/112) when alloy-chains is bumped to version 0.1.48
321+
if self.chain == Chain::from_named(NamedChain::Scroll) ||
322+
self.chain == Chain::from_named(NamedChain::ScrollSepolia)
323+
{
324+
return None
325+
}
326+
320327
// If the base fee is set in the genesis block, we use that instead of the default.
321328
let genesis_base_fee =
322329
self.genesis.base_fee_per_gas.map(|fee| fee as u64).unwrap_or(INITIAL_BASE_FEE);
@@ -571,8 +578,10 @@ impl ChainSpec {
571578
C::Holesky => Some(holesky_nodes()),
572579
C::Base => Some(base_nodes()),
573580
C::Optimism => Some(op_nodes()),
581+
C::Scroll => Some(scroll_nodes()),
574582
C::BaseGoerli | C::BaseSepolia => Some(base_testnet_nodes()),
575583
C::OptimismSepolia | C::OptimismGoerli | C::OptimismKovan => Some(op_testnet_nodes()),
584+
C::ScrollSepolia => Some(scroll_sepolia_nodes()),
576585
_ => None,
577586
}
578587
}

crates/net/peers/src/bootnodes/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ pub use ethereum::*;
88
mod optimism;
99
pub use optimism::*;
1010

11+
mod scroll;
12+
pub use scroll::*;
13+
1114
/// Returns parsed mainnet nodes
1215
pub fn mainnet_nodes() -> Vec<NodeRecord> {
1316
parse_nodes(&MAINNET_BOOTNODES[..])
@@ -43,6 +46,16 @@ pub fn base_testnet_nodes() -> Vec<NodeRecord> {
4346
parse_nodes(OP_TESTNET_BOOTNODES)
4447
}
4548

49+
/// Returns parsed scroll mainnet nodes
50+
pub fn scroll_nodes() -> Vec<NodeRecord> {
51+
parse_nodes(SCROLL_BOOTNODES)
52+
}
53+
54+
/// Returns parsed scroll seplo nodes
55+
pub fn scroll_sepolia_nodes() -> Vec<NodeRecord> {
56+
parse_nodes(SCROLL_SEPOLIA_BOOTNODES)
57+
}
58+
4659
/// Parses all the nodes
4760
pub fn parse_nodes(nodes: impl IntoIterator<Item = impl AsRef<str>>) -> Vec<NodeRecord> {
4861
nodes.into_iter().map(|s| s.as_ref().parse().unwrap()).collect()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! Scroll bootnodes come from <https://github.com/scroll-tech/go-ethereum/blob/develop/params/bootnodes.go>
2+
3+
/// Scroll mainnet boot nodes.
4+
pub static SCROLL_BOOTNODES: &[&str] = &[
5+
"enode://c6ac91f43df3d63916ac1ae411cdd5ba249d55d48a7bec7f8cd5bb351a31aba437e5a69e8a1de74d73fdfeba8af1cfe9caf9846ecd3abf60d1ffdf4925b55b23@54.186.123.248:30303",
6+
"enode://fdcc807b5d1353f3a1e98b90208ce6ef1b7d446136e51eaa8ad657b55518a2f8b37655e42375d61622e6ea18f3faf9d070c9bbdf012cf5484bcbad33b7a15fb1@44.227.91.206:30303",
7+
"enode://6beb5a3efbb39be73d17630b6da48e94c0ce7ec665172111463cb470197b20c12faa1fa6f835b81c28571277d1017e65c4e426cc92a46141cf69118ecf28ac03@44.237.194.52:30303",
8+
"enode://7cf893d444eb8e129dca0f6485b3df579911606e7c728be4fa55fcc5f155a37c3ce07d217ccec5447798bde465ac2bdba2cb8763d107e9f3257e787579e9f27e@52.35.203.107:30303",
9+
"enode://c7b2d94e95da343db6e667a01cef90376a592f2d277fbcbf6e9c9186734ed8003d01389571bd10cdbab7a6e5adfa6f0c7b55644d0db24e0b9deb4ec80f842075@54.70.236.187:30303",
10+
];
11+
12+
/// Scroll sepolia boot nodes.
13+
pub static SCROLL_SEPOLIA_BOOTNODES: &[&str] = &[
14+
"enode://ceb1636bac5cbb262e5ad5b2cd22014bdb35ffe7f58b3506970d337a63099481814a338dbcd15f2d28757151e3ecd40ba38b41350b793cd0d910ff0436654f8c@35.85.84.250:30303",
15+
"enode://29cee709c400533ae038a875b9ca975c8abef9eade956dcf3585e940acd5c0ae916968f514bd37d1278775aad1b7db30f7032a70202a87fd7365bd8de3c9f5fc@44.242.39.33:30303",
16+
"enode://dd1ac5433c5c2b04ca3166f4cb726f8ff6d2da83dbc16d9b68b1ea83b7079b371eb16ef41c00441b6e85e32e33087f3b7753ea9e8b1e3f26d3e4df9208625e7f@54.148.111.168:30303",
17+
];

crates/scroll/chainspec/Cargo.toml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[package]
2+
name = "reth-scroll-chainspec"
3+
version.workspace = true
4+
edition.workspace = true
5+
rust-version.workspace = true
6+
license.workspace = true
7+
homepage.workspace = true
8+
repository.workspace = true
9+
description = "EVM chain spec implementation for scroll."
10+
11+
[lints]
12+
workspace = true
13+
14+
[dependencies]
15+
# reth
16+
reth-chainspec.workspace = true
17+
reth-ethereum-forks.workspace = true
18+
reth-primitives-traits.workspace = true
19+
reth-network-peers.workspace = true
20+
21+
# scroll-reth
22+
reth-scroll-forks.workspace = true
23+
24+
# ethereum
25+
alloy-chains.workspace = true
26+
alloy-genesis.workspace = true
27+
alloy-primitives.workspace = true
28+
alloy-consensus.workspace = true
29+
alloy-eips.workspace = true
30+
alloy-serde.workspace = true
31+
32+
# io
33+
serde_json.workspace = true
34+
serde = { workspace = true, features = ["derive"] }
35+
36+
# misc
37+
derive_more.workspace = true
38+
once_cell.workspace = true
39+
40+
[dev-dependencies]
41+
reth-chainspec = { workspace = true, features = ["test-utils"] }
42+
alloy-genesis.workspace = true
43+
44+
[features]
45+
default = ["std"]
46+
std = [
47+
"alloy-chains/std",
48+
"alloy-genesis/std",
49+
"alloy-primitives/std",
50+
"alloy-eips/std",
51+
"alloy-serde/std",
52+
"reth-chainspec/std",
53+
"reth-ethereum-forks/std",
54+
"reth-primitives-traits/std",
55+
"reth-scroll-forks/std",
56+
"alloy-consensus/std",
57+
"once_cell/std",
58+
"serde/std"
59+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"nonce":"0x0","timestamp":"0x6490fdd2","extraData":"0x","gasLimit":"0x1c9c380","difficulty":"0x0","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","coinbase":"0x0000000000000000000000000000000000000000","stateRoot":"0x5eb6e371a698b8d68f665192350ffcecbbbf322916f4b51bd79bb6887da3f494","alloc":{"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266":{"balance":"0xD3C21BCECCEDA1000000"},"0x70997970C51812dc3A010C7d01b50e0d17dc79C8":{"balance":"0xD3C21BCECCEDA1000000"},"0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC":{"balance":"0xD3C21BCECCEDA1000000"},"0x90F79bf6EB2c4f870365E785982E1f101E93b906":{"balance":"0xD3C21BCECCEDA1000000"},"0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65":{"balance":"0xD3C21BCECCEDA1000000"},"0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc":{"balance":"0xD3C21BCECCEDA1000000"},"0x976EA74026E726554dB657fA54763abd0C3a0aa9":{"balance":"0xD3C21BCECCEDA1000000"},"0x14dC79964da2C08b23698B3D3cc7Ca32193d9955":{"balance":"0xD3C21BCECCEDA1000000"},"0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f":{"balance":"0xD3C21BCECCEDA1000000"},"0xa0Ee7A142d267C1f36714E4a8F75612F20a79720":{"balance":"0xD3C21BCECCEDA1000000"},"0xBcd4042DE499D14e55001CcbB24a551F3b954096":{"balance":"0xD3C21BCECCEDA1000000"},"0x71bE63f3384f5fb98995898A86B02Fb2426c5788":{"balance":"0xD3C21BCECCEDA1000000"},"0xFABB0ac9d68B0B445fB7357272Ff202C5651694a":{"balance":"0xD3C21BCECCEDA1000000"},"0x1CBd3b2770909D4e10f157cABC84C7264073C9Ec":{"balance":"0xD3C21BCECCEDA1000000"},"0xdF3e18d64BC6A983f673Ab319CCaE4f1a57C7097":{"balance":"0xD3C21BCECCEDA1000000"},"0xcd3B766CCDd6AE721141F452C550Ca635964ce71":{"balance":"0xD3C21BCECCEDA1000000"},"0x2546BcD3c84621e976D8185a91A922aE77ECEc30":{"balance":"0xD3C21BCECCEDA1000000"},"0xbDA5747bFD65F08deb54cb465eB87D40e51B197E":{"balance":"0xD3C21BCECCEDA1000000"},"0xdD2FD4581271e230360230F9337D5c0430Bf44C0":{"balance":"0xD3C21BCECCEDA1000000"},"0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199":{"balance":"0xD3C21BCECCEDA1000000"}},"number":"0x0","gasUsed":"0x0","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000"}

crates/scroll/chainspec/res/genesis/scroll.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

crates/scroll/chainspec/res/genesis/sepolia_scroll.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

crates/scroll/chainspec/src/dev.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//! Chain specification in dev mode for custom chain.
2+
3+
use alloc::sync::Arc;
4+
5+
use alloy_chains::Chain;
6+
use alloy_consensus::constants::DEV_GENESIS_HASH;
7+
use alloy_primitives::U256;
8+
use reth_chainspec::{once_cell_set, BaseFeeParams, BaseFeeParamsKind, ChainSpec};
9+
use reth_scroll_forks::DEV_HARDFORKS;
10+
11+
use crate::{LazyLock, ScrollChainSpec};
12+
13+
/// Scroll dev testnet specification
14+
///
15+
/// Includes 20 prefunded accounts with `10_000` ETH each derived from mnemonic "test test test test
16+
/// test test test test test test test junk".
17+
pub static SCROLL_DEV: LazyLock<Arc<ScrollChainSpec>> = LazyLock::new(|| {
18+
ScrollChainSpec {
19+
inner: ChainSpec {
20+
chain: Chain::dev(),
21+
genesis: serde_json::from_str(include_str!("../res/genesis/dev.json"))
22+
.expect("Can't deserialize Dev testnet genesis json"),
23+
genesis_hash: once_cell_set(DEV_GENESIS_HASH),
24+
paris_block_and_final_difficulty: Some((0, U256::from(0))),
25+
hardforks: DEV_HARDFORKS.clone(),
26+
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
27+
..Default::default()
28+
},
29+
}
30+
.into()
31+
});

0 commit comments

Comments
 (0)