Skip to content

Commit 5aa86f0

Browse files
authored
feat(l1): add mainnet as preset network (#2459)
**Motivation** Adds mainnet bootnodes & genesis file so we can connect to mainnet by passing `--network mainnet` <!-- Why does this pull request exist? What are its goals? --> **Description** * add mainnet bootnodes & genesis file * recognize mainnet as preset network * update docs <!-- A clear and concise general description of the changes this PR introduces --> <!-- Link to issues: Resolves #111, Resolves #222 --> Contributes to #72 **Notes** Mainnet genesis file is quite large, it is copied from [here](https://github.com/eth-clients/mainnet/blob/main/metadata/genesis.json)
1 parent 3bbb56e commit 5aa86f0

File tree

6 files changed

+26755
-2
lines changed

6 files changed

+26755
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ Options:
205205
206206
Node options:
207207
--network <GENESIS_FILE_PATH>
208-
Alternatively, the name of a known network can be provided instead to use its preset genesis file and include its preset bootnodes. The networks currently supported include holesky, sepolia and hoodi.
208+
Alternatively, the name of a known network can be provided instead to use its preset genesis file and include its preset bootnodes. The networks currently supported include holesky, sepolia, hoodi and mainnet.
209209
210210
--datadir <DATABASE_DIRECTORY>
211211
If the datadir is the word `memory`, ethrex will use the `InMemory Engine`.

cmd/ethrex/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub struct Options {
3636
long = "network",
3737
value_name = "GENESIS_FILE_PATH",
3838
help = "Receives a `Genesis` struct in json format. This is the only argument which is required. You can look at some example genesis files at `test_data/genesis*`.",
39-
long_help = "Alternatively, the name of a known network can be provided instead to use its preset genesis file and include its preset bootnodes. The networks currently supported include holesky, sepolia and hoodi.",
39+
long_help = "Alternatively, the name of a known network can be provided instead to use its preset genesis file and include its preset bootnodes. The networks currently supported include holesky, sepolia, hoodi and mainnet.",
4040
help_heading = "Node options"
4141
)]
4242
pub network: Option<String>,

cmd/ethrex/initializers.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ pub fn get_network(opts: &Options) -> String {
257257
if network == "hoodi" {
258258
network = String::from(networks::HOODI_GENESIS_PATH);
259259
}
260+
if network == "mainnet" {
261+
network = String::from(networks::MAINNET_GENESIS_PATH);
262+
}
260263

261264
network
262265
}
@@ -280,6 +283,11 @@ pub fn get_bootnodes(opts: &Options, network: &str, data_dir: &str) -> Vec<Node>
280283
bootnodes.extend(networks::HOODI_BOOTNODES.iter());
281284
}
282285

286+
if network == networks::MAINNET_GENESIS_PATH {
287+
info!("Adding mainnet preset bootnodes");
288+
bootnodes.extend(networks::MAINNET_BOOTNODES.iter());
289+
}
290+
283291
if bootnodes.is_empty() {
284292
warn!("No bootnodes specified. This node will not be able to connect to the network.");
285293
}

cmd/ethrex/networks.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const SEPOLIA_BOOTNODES_PATH: &str = "cmd/ethrex/networks/sepolia/bootnodes.json
1010
pub const HOODI_GENESIS_PATH: &str = "cmd/ethrex/networks/hoodi/genesis.json";
1111
const HOODI_BOOTNODES_PATH: &str = "cmd/ethrex/networks/hoodi/bootnodes.json";
1212

13+
pub const MAINNET_GENESIS_PATH: &str = "cmd/ethrex/networks/mainnet/genesis.json";
14+
const MAINNET_BOOTNODES_PATH: &str = "cmd/ethrex/networks/mainnet/bootnodes.json";
15+
1316
lazy_static! {
1417
pub static ref HOLESKY_BOOTNODES: Vec<Node> = serde_json::from_reader(
1518
std::fs::File::open(HOLESKY_BOOTNODES_PATH).expect("Failed to open holesky bootnodes file")
@@ -23,4 +26,8 @@ lazy_static! {
2326
std::fs::File::open(HOODI_BOOTNODES_PATH).expect("Failed to open hoodi bootnodes file")
2427
)
2528
.expect("Failed to parse hoodi bootnodes file");
29+
pub static ref MAINNET_BOOTNODES: Vec<Node> = serde_json::from_reader(
30+
std::fs::File::open(MAINNET_BOOTNODES_PATH).expect("Failed to open mainnet bootnodes file")
31+
)
32+
.expect("Failed to parse mainnet bootnodes file");
2633
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
"enode://d860a01f9722d78051619d1e2351aba3f43f943f6f00718d1b9baa4101932a1f5011f16bb2b1bb35db20d6fe28fa0bf09636d26a87d31de9ec6203eeedb1f666@18.138.108.67:30303",
3+
"enode://22a8232c3abc76a16ae9d6c3b164f98775fe226f0917b0ca871128a74a8e9630b458460865bab457221f1d448dd9791d24c4e5d88786180ac185df813a68d4de@3.209.45.79:30303",
4+
"enode://2b252ab6a1d0f971d9722cb839a42cb81db019ba44c08754628ab4a823487071b5695317c8ccd085219c3a03af063495b2f1da8d18218da2d6a82981b45e6ffc@65.108.70.101:30303",
5+
"enode://4aeb4ab6c14b23e2c4cfdce879c04b0748a20d8e9b59e25ded2a08143e265c6c25936e74cbc8e641e3312ca288673d91f2f93f8e277de3cfa444ecdaaf982052@157.90.35.166:30303"
6+
]

0 commit comments

Comments
 (0)