mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
feat(node): allow config'ing trusted nodes from cli (#728)
This commit is contained in:
committed by
GitHub
parent
e4bd5b4fe9
commit
fe5e3bd0c8
@ -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,
|
||||
}
|
||||
|
||||
@ -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;
|
||||
@ -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 {
|
||||
@ -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);
|
||||
@ -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?;
|
||||
|
||||
|
||||
@ -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},
|
||||
@ -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<()> {
|
||||
|
||||
Reference in New Issue
Block a user