Skip to content

Commit

Permalink
feat(node): allow config'ing trusted nodes from cli (paradigmxyz#728)
Browse files Browse the repository at this point in the history
  • Loading branch information
gakonst committed Jan 5, 2023
1 parent e4bd5b4 commit fe5e3bd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
20 changes: 20 additions & 0 deletions bin/reth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,23 @@ pub mod prometheus_exporter;
pub mod stage;
pub mod test_eth_chain;
pub mod util;

use clap::Parser;
use reth_primitives::NodeRecord;

#[derive(Debug, Parser)]
/// Parameters for configuring the network more granularly via CLI
struct NetworkOpts {
/// Disable the discovery service.
#[arg(short, long)]
disable_discovery: bool,

/// Target trusted peer enodes
/// --trusted-peers enode://abcd@192.168.0.1:30303
#[arg(long)]
trusted_peers: Vec<NodeRecord>,

/// Connect only to trusted peers
#[arg(long)]
trusted_only: bool,
}
17 changes: 12 additions & 5 deletions bin/reth/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
chainspec::{chain_spec_value_parser, ChainSpecification},
init::{init_db, init_genesis},
},
NetworkOpts,
};
use clap::{crate_version, Parser};
use fdlimit::raise_fd_limit;
Expand Down Expand Up @@ -73,9 +74,8 @@ pub struct Command {
#[arg(long = "debug.tip")]
tip: Option<H256>,

/// Disable the discovery service.
#[arg(short, long)]
disable_discovery: bool,
#[clap(flatten)]
network: NetworkOpts,
}

impl Command {
Expand All @@ -86,7 +86,14 @@ impl Command {
// Does not do anything on windows.
raise_fd_limit();

let config: Config = confy::load_path(&self.config).unwrap_or_default();
let mut config: Config = confy::load_path(&self.config).unwrap_or_default();
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);
});
}

info!("reth {} starting", crate_version!());

info!("Opening database at {}", &self.db);
Expand All @@ -104,7 +111,7 @@ 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.disable_discovery)
.network_config(db.clone(), chain_id, genesis_hash, self.network.disable_discovery)
.start_network()
.await?;

Expand Down
18 changes: 1 addition & 17 deletions bin/reth/src/stage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use crate::{
chainspec::{chain_spec_value_parser, ChainSpecification},
init::{init_db, init_genesis},
},
NetworkOpts,
};
use reth_consensus::BeaconConsensus;
use reth_downloaders::bodies::concurrent::ConcurrentDownloader;
use reth_executor::Config as ExecutorConfig;
use reth_primitives::NodeRecord;
use reth_stages::{
metrics::HeaderMetrics,
stages::{bodies::BodyStage, execution::ExecutionStage, sender_recovery::SenderRecoveryStage},
Expand Down Expand Up @@ -101,22 +101,6 @@ enum StageEnum {
Execution,
}

#[derive(Debug, Parser)]
struct NetworkOpts {
/// Disable the discovery service.
#[arg(short, long)]
disable_discovery: bool,

/// Target trusted peer enodes
/// --trusted-peers enode://abcd@192.168.0.1:30303
#[arg(long)]
trusted_peers: Vec<NodeRecord>,

/// Connect only to trusted peers
#[arg(long)]
trusted_only: bool,
}

impl Command {
/// Execute `stage` command
pub async fn execute(&self) -> eyre::Result<()> {
Expand Down

0 comments on commit fe5e3bd

Please sign in to comment.