mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-29 00:58:11 -05:00
chore: limited node command cleanup (#5539)
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
//! Support for integrating customizations into the CLI.
|
||||
|
||||
use crate::cli::{
|
||||
components::{RethNodeComponents, RethRpcComponents},
|
||||
config::{PayloadBuilderConfig, RethRpcConfig},
|
||||
components::{RethNodeComponents, RethRpcComponents, RethRpcServerHandles},
|
||||
config::{PayloadBuilderConfig, RethNetworkConfig, RethRpcConfig},
|
||||
};
|
||||
use clap::Args;
|
||||
use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig};
|
||||
@@ -10,8 +10,6 @@ use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
|
||||
use reth_tasks::TaskSpawner;
|
||||
use std::{fmt, marker::PhantomData};
|
||||
|
||||
use crate::cli::{components::RethRpcServerHandles, config::RethNetworkConfig};
|
||||
|
||||
/// A trait that allows for extending parts of the CLI with additional functionality.
|
||||
///
|
||||
/// This is intended as a way to allow to _extend_ the node command. For example, to register
|
||||
|
||||
@@ -13,7 +13,7 @@ use crate::{
|
||||
config::RethRpcConfig,
|
||||
ext::{RethCliExt, RethNodeCommandConfig},
|
||||
},
|
||||
dirs::{DataDirPath, MaybePlatformPath},
|
||||
dirs::{ChainPath, DataDirPath, MaybePlatformPath},
|
||||
init::init_genesis,
|
||||
node::cl_events::ConsensusLayerHealthEvents,
|
||||
prometheus_exporter,
|
||||
@@ -241,18 +241,14 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
|
||||
// Does not do anything on windows.
|
||||
raise_fd_limit();
|
||||
|
||||
// add network name to data dir
|
||||
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
|
||||
let config_path = self.config.clone().unwrap_or(data_dir.config_path());
|
||||
|
||||
let mut config: Config = self.load_config(config_path.clone())?;
|
||||
|
||||
// always store reth.toml in the data dir, not the chain specific data dir
|
||||
info!(target: "reth::cli", path = ?config_path, "Configuration loaded");
|
||||
// get config
|
||||
let config = self.load_config()?;
|
||||
|
||||
let prometheus_handle = self.install_prometheus_recorder()?;
|
||||
|
||||
let data_dir = self.data_dir();
|
||||
let db_path = data_dir.db_path();
|
||||
|
||||
info!(target: "reth::cli", path = ?db_path, "Opening database");
|
||||
let db = Arc::new(init_db(&db_path, self.db.log_level)?.with_metrics());
|
||||
info!(target: "reth::cli", "Database opened");
|
||||
@@ -273,14 +269,12 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
|
||||
|
||||
debug!(target: "reth::cli", chain=%self.chain.chain, genesis=?self.chain.genesis_hash(), "Initializing genesis");
|
||||
|
||||
let genesis_hash = init_genesis(db.clone(), self.chain.clone())?;
|
||||
let genesis_hash = init_genesis(Arc::clone(&db), self.chain.clone())?;
|
||||
|
||||
info!(target: "reth::cli", "{}", DisplayHardforks::new(self.chain.hardforks()));
|
||||
|
||||
let consensus = self.consensus();
|
||||
|
||||
self.init_trusted_nodes(&mut config);
|
||||
|
||||
debug!(target: "reth::cli", "Spawning stages metrics listener task");
|
||||
let (sync_metrics_tx, sync_metrics_rx) = unbounded_channel();
|
||||
let sync_metrics_listener = reth_stages::MetricsListener::new(sync_metrics_rx);
|
||||
@@ -647,10 +641,35 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
|
||||
Ok(pipeline)
|
||||
}
|
||||
|
||||
/// Returns the chain specific path to the data dir.
|
||||
fn data_dir(&self) -> ChainPath<DataDirPath> {
|
||||
self.datadir.unwrap_or_chain_default(self.chain.chain)
|
||||
}
|
||||
|
||||
/// Returns the path to the config file.
|
||||
fn config_path(&self) -> PathBuf {
|
||||
self.config.clone().unwrap_or_else(|| self.data_dir().config_path())
|
||||
}
|
||||
|
||||
/// Loads the reth config with the given datadir root
|
||||
fn load_config(&self, config_path: PathBuf) -> eyre::Result<Config> {
|
||||
confy::load_path::<Config>(config_path.clone())
|
||||
.wrap_err_with(|| format!("Could not load config file {:?}", config_path))
|
||||
fn load_config(&self) -> eyre::Result<Config> {
|
||||
let config_path = self.config_path();
|
||||
let mut config = confy::load_path::<Config>(&config_path)
|
||||
.wrap_err_with(|| format!("Could not load config file {:?}", config_path))?;
|
||||
|
||||
info!(target: "reth::cli", path = ?config_path, "Configuration loaded");
|
||||
|
||||
// Update the config with the command line arguments
|
||||
config.peers.connect_trusted_nodes_only = self.network.trusted_only;
|
||||
|
||||
if !self.network.trusted_peers.is_empty() {
|
||||
info!(target: "reth::cli", "Adding trusted nodes");
|
||||
self.network.trusted_peers.iter().for_each(|peer| {
|
||||
config.peers.trusted_nodes.insert(*peer);
|
||||
});
|
||||
}
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
/// Loads the trusted setup params from a given file path or falls back to
|
||||
@@ -665,17 +684,6 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
|
||||
}
|
||||
}
|
||||
|
||||
fn init_trusted_nodes(&self, config: &mut Config) {
|
||||
config.peers.connect_trusted_nodes_only = self.network.trusted_only;
|
||||
|
||||
if !self.network.trusted_peers.is_empty() {
|
||||
info!(target: "reth::cli", "Adding trusted nodes");
|
||||
self.network.trusted_peers.iter().for_each(|peer| {
|
||||
config.peers.trusted_nodes.insert(*peer);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn install_prometheus_recorder(&self) -> eyre::Result<PrometheusHandle> {
|
||||
prometheus_exporter::install_recorder()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user