From 7795bf539232fa0bd0c97094e7f276069cd043c7 Mon Sep 17 00:00:00 2001 From: Ikechukwu Ahiara Marvellous Date: Mon, 16 Jan 2023 20:04:07 +0100 Subject: [PATCH] Add a --bootnodes flag for reth node (#867) --- bin/reth/src/config.rs | 5 +++-- bin/reth/src/node/mod.rs | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/bin/reth/src/config.rs b/bin/reth/src/config.rs index f510f023c0..e13818fb59 100644 --- a/bin/reth/src/config.rs +++ b/bin/reth/src/config.rs @@ -6,7 +6,7 @@ use reth_network::{ config::{mainnet_nodes, rng_secret_key}, NetworkConfig, PeersConfig, }; -use reth_primitives::H256; +use reth_primitives::{NodeRecord, H256}; use reth_provider::ProviderImpl; use serde::{Deserialize, Serialize}; @@ -29,12 +29,13 @@ impl Config { chain_id: u64, genesis_hash: H256, disable_discovery: bool, + bootnodes: &Option>, ) -> NetworkConfig> { let peer_config = reth_network::PeersConfig::default() .with_trusted_nodes(self.peers.trusted_nodes.clone()) .with_connect_trusted_nodes_only(self.peers.connect_trusted_nodes_only); NetworkConfig::builder(Arc::new(ProviderImpl::new(db)), rng_secret_key()) - .boot_nodes(mainnet_nodes()) + .boot_nodes(bootnodes.unwrap_or_else(|| mainnet_nodes())) .peer_config(peer_config) .genesis_hash(genesis_hash) .chain_id(chain_id) diff --git a/bin/reth/src/node/mod.rs b/bin/reth/src/node/mod.rs index c4672eac76..c900e27df4 100644 --- a/bin/reth/src/node/mod.rs +++ b/bin/reth/src/node/mod.rs @@ -22,7 +22,7 @@ use reth_executor::Config as ExecutorConfig; use reth_interfaces::consensus::ForkchoiceState; use reth_network::NetworkEvent; use reth_network_api::NetworkInfo; -use reth_primitives::{BlockNumber, H256}; +use reth_primitives::{BlockNumber, NodeRecord, H256}; use reth_stages::{ metrics::HeaderMetrics, stages::{ @@ -84,6 +84,9 @@ pub struct Command { #[clap(flatten)] network: NetworkOpts, + + #[arg(long, value_delimiter = ',')] + bootnodes: Option>, } impl Command { @@ -97,6 +100,7 @@ impl Command { let mut config: Config = confy::load_path(&self.config).wrap_err("Could not load config")?; config.peers.connect_trusted_nodes_only = self.network.trusted_only; + if !self.network.trusted_peers.is_empty() { self.network.trusted_peers.iter().for_each(|peer| { config.peers.trusted_nodes.insert(*peer); @@ -120,7 +124,13 @@ impl Command { let genesis_hash = init_genesis(db.clone(), self.chain.genesis.clone())?; let network = config - .network_config(db.clone(), chain_id, genesis_hash, self.network.disable_discovery) + .network_config( + db.clone(), + chain_id, + genesis_hash, + self.network.disable_discovery, + &self.bootnodes, + ) .start_network() .await?;