Add a --bootnodes flag for reth node (#867)

This commit is contained in:
Ikechukwu Ahiara Marvellous
2023-01-16 20:04:07 +01:00
committed by GitHub
parent 42f7936470
commit 7795bf5392
2 changed files with 15 additions and 4 deletions

View File

@ -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<Vec<NodeRecord>>,
) -> NetworkConfig<ProviderImpl<DB>> {
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)

View File

@ -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<Vec<NodeRecord>>,
}
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?;