diff --git a/bin/reth/src/cli/mod.rs b/bin/reth/src/cli/mod.rs index 665dbcba2..f06cb7169 100644 --- a/bin/reth/src/cli/mod.rs +++ b/bin/reth/src/cli/mod.rs @@ -133,7 +133,7 @@ impl, Ext: clap::Args + fmt::Debug> Cl /// ```` pub fn run(mut self, launcher: L) -> eyre::Result<()> where - L: FnOnce(WithLaunchContext>>, Ext) -> Fut, + L: FnOnce(WithLaunchContext, C::ChainSpec>>, Ext) -> Fut, Fut: Future>, { // add network name to logs dir diff --git a/crates/chainspec/src/api.rs b/crates/chainspec/src/api.rs index c9d8cc98a..7f0b09330 100644 --- a/crates/chainspec/src/api.rs +++ b/crates/chainspec/src/api.rs @@ -1,6 +1,7 @@ -use crate::ChainSpec; +use crate::{ChainSpec, DepositContract}; use alloy_chains::Chain; use alloy_eips::eip1559::BaseFeeParams; +use alloy_primitives::B256; use core::fmt::Debug; /// Trait representing type configuring a chain spec. @@ -14,6 +15,15 @@ pub trait EthChainSpec: Send + Sync + Unpin + Debug + 'static { /// Get the [`BaseFeeParams`] for the chain at the given timestamp. fn base_fee_params_at_timestamp(&self, timestamp: u64) -> BaseFeeParams; + + /// Returns the deposit contract data for the chain, if it's present + fn deposit_contract(&self) -> Option<&DepositContract>; + + /// The genesis hash. + fn genesis_hash(&self) -> B256; + + /// The delete limit for pruner, per run. + fn prune_delete_limit(&self) -> usize; } impl EthChainSpec for ChainSpec { @@ -24,4 +34,16 @@ impl EthChainSpec for ChainSpec { fn base_fee_params_at_timestamp(&self, timestamp: u64) -> BaseFeeParams { self.base_fee_params_at_timestamp(timestamp) } + + fn deposit_contract(&self) -> Option<&DepositContract> { + self.deposit_contract.as_ref() + } + + fn genesis_hash(&self) -> B256 { + self.genesis_hash() + } + + fn prune_delete_limit(&self) -> usize { + self.prune_delete_limit + } } diff --git a/crates/cli/commands/src/node.rs b/crates/cli/commands/src/node.rs index f92a0cdba..35bf73c2a 100644 --- a/crates/cli/commands/src/node.rs +++ b/crates/cli/commands/src/node.rs @@ -135,7 +135,7 @@ impl, Ext: clap::Args + fmt::Debug> No /// closure. pub async fn execute(self, ctx: CliContext, launcher: L) -> eyre::Result<()> where - L: FnOnce(WithLaunchContext>>, Ext) -> Fut, + L: FnOnce(WithLaunchContext, C::ChainSpec>>, Ext) -> Fut, Fut: Future>, { tracing::info!(target: "reth::cli", version = ?version::SHORT_VERSION, "Starting reth"); diff --git a/crates/ethereum/node/src/node.rs b/crates/ethereum/node/src/node.rs index 050f9b9bc..c7b8aee73 100644 --- a/crates/ethereum/node/src/node.rs +++ b/crates/ethereum/node/src/node.rs @@ -281,7 +281,7 @@ pub struct EthereumNetworkBuilder { impl NetworkBuilder for EthereumNetworkBuilder where - Node: FullNodeTypes, + Node: FullNodeTypes>, Pool: TransactionPool + Unpin + 'static, { async fn build_network( diff --git a/crates/exex/exex/src/context.rs b/crates/exex/exex/src/context.rs index ec3c88014..bdb2d4c27 100644 --- a/crates/exex/exex/src/context.rs +++ b/crates/exex/exex/src/context.rs @@ -1,6 +1,6 @@ use std::fmt::Debug; -use reth_node_api::{FullNodeComponents, NodeTypesWithEngine}; +use reth_node_api::{FullNodeComponents, NodeTypes, NodeTypesWithEngine}; use reth_node_core::node_config::NodeConfig; use reth_primitives::Head; use reth_tasks::TaskExecutor; @@ -13,7 +13,7 @@ pub struct ExExContext { /// The current head of the blockchain at launch. pub head: Head, /// The config of the node - pub config: NodeConfig, + pub config: NodeConfig<::ChainSpec>, /// The loaded node config pub reth_config: reth_config::Config, /// Channel used to send [`ExExEvent`]s to the rest of the node. diff --git a/crates/node/builder/src/builder/mod.rs b/crates/node/builder/src/builder/mod.rs index 472bc425a..4255e7fdf 100644 --- a/crates/node/builder/src/builder/mod.rs +++ b/crates/node/builder/src/builder/mod.rs @@ -11,7 +11,7 @@ pub use states::*; use std::sync::Arc; use futures::Future; -use reth_chainspec::ChainSpec; +use reth_chainspec::{ChainSpec, EthChainSpec}; use reth_cli_util::get_secret_key; use reth_db_api::{ database::Database, @@ -154,28 +154,30 @@ pub type RethFullAdapter = FullNodeTypesAdapter< /// configured by the builder itself during launch. This might change in the future. /// /// [builder]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html -pub struct NodeBuilder { +pub struct NodeBuilder { /// All settings for how the node should be configured. - config: NodeConfig, + config: NodeConfig, /// The configured database for the node. database: DB, } -impl NodeBuilder<()> { +impl NodeBuilder<(), ChainSpec> { /// Create a new [`NodeBuilder`]. - pub const fn new(config: NodeConfig) -> Self { + pub const fn new(config: NodeConfig) -> Self { Self { config, database: () } } } -impl NodeBuilder { +impl NodeBuilder { /// Returns a reference to the node builder's config. - pub const fn config(&self) -> &NodeConfig { + pub const fn config(&self) -> &NodeConfig { &self.config } +} +impl NodeBuilder { /// Configures the underlying database that the node will use. - pub fn with_database(self, database: D) -> NodeBuilder { + pub fn with_database(self, database: D) -> NodeBuilder { NodeBuilder { config: self.config, database } } @@ -191,8 +193,9 @@ impl NodeBuilder { pub fn testing_node( mut self, task_executor: TaskExecutor, - ) -> WithLaunchContext>>> - { + ) -> WithLaunchContext< + NodeBuilder>, ChainSpec>, + > { let path = reth_node_core::dirs::MaybePlatformPath::::from( reth_db::test_utils::tempdir_path(), ); @@ -202,7 +205,7 @@ impl NodeBuilder { }); let data_dir = - path.unwrap_or_chain_default(self.config.chain.chain, self.config.datadir.clone()); + path.unwrap_or_chain_default(self.config.chain.chain(), self.config.datadir.clone()); let db = reth_db::test_utils::create_test_rw_db_with_path(data_dir.db()); @@ -210,7 +213,7 @@ impl NodeBuilder { } } -impl NodeBuilder +impl NodeBuilder where DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static, { @@ -263,15 +266,17 @@ impl WithLaunchContext { } } -impl WithLaunchContext> +impl WithLaunchContext> { + /// Returns a reference to the node builder's config. + pub const fn config(&self) -> &NodeConfig { + self.builder.config() + } +} + +impl WithLaunchContext> where DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static, { - /// Returns a reference to the node builder's config. - pub const fn config(&self) -> &NodeConfig { - self.builder.config() - } - /// Configures the types of the node. pub fn with_types(self) -> WithLaunchContext>> where @@ -395,7 +400,7 @@ where AO: NodeAddOns, EthApi: FullEthApiServer + AddDevSigners>, { /// Returns a reference to the node builder's config. - pub const fn config(&self) -> &NodeConfig { + pub const fn config(&self) -> &NodeConfig<::ChainSpec> { &self.builder.config } @@ -520,7 +525,7 @@ pub struct BuilderContext { /// The executor of the node. pub(crate) executor: TaskExecutor, /// Config container - pub(crate) config_container: WithConfigs, + pub(crate) config_container: WithConfigs<::ChainSpec>, } impl BuilderContext { @@ -529,7 +534,7 @@ impl BuilderContext { head: Head, provider: Node::Provider, executor: TaskExecutor, - config_container: WithConfigs, + config_container: WithConfigs<::ChainSpec>, ) -> Self { Self { head, provider, executor, config_container } } @@ -545,7 +550,7 @@ impl BuilderContext { } /// Returns the config of the node. - pub const fn config(&self) -> &NodeConfig { + pub const fn config(&self) -> &NodeConfig<::ChainSpec> { &self.config_container.config } @@ -586,13 +591,6 @@ impl BuilderContext { self.config().builder.clone() } - /// Creates the [`NetworkBuilder`] for the node. - pub async fn network_builder(&self) -> eyre::Result> { - let network_config = self.network_config()?; - let builder = NetworkManager::builder(network_config).await?; - Ok(builder) - } - /// Convenience function to start the network. /// /// Spawns the configured network and associated tasks and returns the [`NetworkHandle`] @@ -634,6 +632,31 @@ impl BuilderContext { handle } + /// Get the network secret from the given data dir + fn network_secret(&self, data_dir: &ChainPath) -> eyre::Result { + let network_secret_path = + self.config().network.p2p_secret_key.clone().unwrap_or_else(|| data_dir.p2p_secret()); + let secret_key = get_secret_key(&network_secret_path)?; + Ok(secret_key) + } + + /// Builds the [`NetworkConfig`]. + pub fn build_network_config( + &self, + network_builder: NetworkConfigBuilder, + ) -> NetworkConfig { + network_builder.build(self.provider.clone()) + } +} + +impl>> BuilderContext { + /// Creates the [`NetworkBuilder`] for the node. + pub async fn network_builder(&self) -> eyre::Result> { + let network_config = self.network_config()?; + let builder = NetworkManager::builder(network_config).await?; + Ok(builder) + } + /// Returns the default network config for the node. pub fn network_config(&self) -> eyre::Result> { let network_builder = self.network_config_builder(); @@ -658,22 +681,6 @@ impl BuilderContext { Ok(builder) } - - /// Get the network secret from the given data dir - fn network_secret(&self, data_dir: &ChainPath) -> eyre::Result { - let network_secret_path = - self.config().network.p2p_secret_key.clone().unwrap_or_else(|| data_dir.p2p_secret()); - let secret_key = get_secret_key(&network_secret_path)?; - Ok(secret_key) - } - - /// Builds the [`NetworkConfig`]. - pub fn build_network_config( - &self, - network_builder: NetworkConfigBuilder, - ) -> NetworkConfig { - network_builder.build(self.provider.clone()) - } } impl std::fmt::Debug for BuilderContext { diff --git a/crates/node/builder/src/builder/states.rs b/crates/node/builder/src/builder/states.rs index b5c99d082..e1cee831b 100644 --- a/crates/node/builder/src/builder/states.rs +++ b/crates/node/builder/src/builder/states.rs @@ -9,7 +9,7 @@ use std::{fmt, future::Future, marker::PhantomData}; use reth_exex::ExExContext; use reth_node_api::{ - FullNodeComponents, FullNodeTypes, NodeAddOns, NodeTypesWithDB, NodeTypesWithEngine, + FullNodeComponents, FullNodeTypes, NodeAddOns, NodeTypes, NodeTypesWithDB, NodeTypesWithEngine, }; use reth_node_core::{ node_config::NodeConfig, @@ -29,14 +29,17 @@ use crate::{ /// A node builder that also has the configured types. pub struct NodeBuilderWithTypes { /// All settings for how the node should be configured. - config: NodeConfig, + config: NodeConfig<::ChainSpec>, /// The configured database for the node. adapter: NodeTypesAdapter, } impl NodeBuilderWithTypes { /// Creates a new instance of the node builder with the given configuration and types. - pub const fn new(config: NodeConfig, database: ::DB) -> Self { + pub const fn new( + config: NodeConfig<::ChainSpec>, + database: ::DB, + ) -> Self { Self { config, adapter: NodeTypesAdapter::new(database) } } @@ -149,7 +152,7 @@ pub struct NodeBuilderWithComponents< AO: NodeAddOns>, > { /// All settings for how the node should be configured. - pub config: NodeConfig, + pub config: NodeConfig<::ChainSpec>, /// Adapter for the underlying node types and database pub adapter: NodeTypesAdapter, /// container for type specific components diff --git a/crates/node/builder/src/launch/common.rs b/crates/node/builder/src/launch/common.rs index b729d80d4..f9974711b 100644 --- a/crates/node/builder/src/launch/common.rs +++ b/crates/node/builder/src/launch/common.rs @@ -10,7 +10,7 @@ use reth_beacon_consensus::EthBeaconConsensus; use reth_blockchain_tree::{ BlockchainTree, BlockchainTreeConfig, ShareableBlockchainTree, TreeExternals, }; -use reth_chainspec::{Chain, ChainSpec}; +use reth_chainspec::{Chain, ChainSpec, EthChainSpec, EthereumHardforks}; use reth_config::{config::EtlConfig, PruneConfig}; use reth_consensus::Consensus; use reth_db_api::database::Database; @@ -110,10 +110,10 @@ impl LaunchContext { /// `config`. /// /// Attaches both the `NodeConfig` and the loaded `reth.toml` config to the launch context. - pub fn with_loaded_toml_config( + pub fn with_loaded_toml_config( self, - config: NodeConfig, - ) -> eyre::Result> { + config: NodeConfig, + ) -> eyre::Result>> { let toml_config = self.load_toml_config(&config)?; Ok(self.with(WithConfigs { config, toml_config })) } @@ -122,7 +122,10 @@ impl LaunchContext { /// `config`. /// /// This is async because the trusted peers may have to be resolved. - pub fn load_toml_config(&self, config: &NodeConfig) -> eyre::Result { + pub fn load_toml_config( + &self, + config: &NodeConfig, + ) -> eyre::Result { let config_path = config.config.clone().unwrap_or_else(|| self.data_dir.config()); let mut toml_config = reth_config::Config::from_path(&config_path) @@ -139,9 +142,9 @@ impl LaunchContext { } /// Save prune config to the toml file if node is a full node. - fn save_pruning_config_if_full_node( + fn save_pruning_config_if_full_node( reth_config: &mut reth_config::Config, - config: &NodeConfig, + config: &NodeConfig, config_path: impl AsRef, ) -> eyre::Result<()> { if reth_config.prune.is_none() { @@ -242,7 +245,7 @@ impl LaunchContextWith { } } -impl LaunchContextWith { +impl LaunchContextWith> { /// Resolves the trusted peers and adds them to the toml config. pub async fn with_resolved_peers(mut self) -> eyre::Result { if !self.attachment.config.network.trusted_peers.is_empty() { @@ -279,7 +282,7 @@ impl LaunchContextWith> { &mut self.attachment.right } } -impl LaunchContextWith> { +impl LaunchContextWith, R>> { /// Adjust certain settings in the config to make sure they are set correctly /// /// This includes: @@ -306,17 +309,17 @@ impl LaunchContextWith> { } /// Returns the container for all config types - pub const fn configs(&self) -> &WithConfigs { + pub const fn configs(&self) -> &WithConfigs { self.attachment.left() } /// Returns the attached [`NodeConfig`]. - pub const fn node_config(&self) -> &NodeConfig { + pub const fn node_config(&self) -> &NodeConfig { &self.left().config } /// Returns the attached [`NodeConfig`]. - pub fn node_config_mut(&mut self) -> &mut NodeConfig { + pub fn node_config_mut(&mut self) -> &mut NodeConfig { &mut self.left_mut().config } @@ -342,7 +345,7 @@ impl LaunchContextWith> { /// Returns the chain identifier of the node. pub fn chain_id(&self) -> Chain { - self.node_config().chain.chain + self.node_config().chain.chain() } /// Returns true if the node is configured as --dev @@ -371,7 +374,7 @@ impl LaunchContextWith> { /// Returns an initialized [`PrunerBuilder`] based on the configured [`PruneConfig`] pub fn pruner_builder(&self) -> PrunerBuilder { PrunerBuilder::new(self.prune_config().unwrap_or_default()) - .delete_limit(self.chain_spec().prune_delete_limit) + .delete_limit(self.chain_spec().prune_delete_limit()) .timeout(PrunerBuilder::DEFAULT_TIMEOUT) } @@ -394,9 +397,10 @@ impl LaunchContextWith> { } } -impl LaunchContextWith> +impl LaunchContextWith, DB>> where DB: Database + Clone + 'static, + ChainSpec: EthChainSpec + EthereumHardforks, { /// Returns the [`ProviderFactory`] for the attached storage after executing a consistent check /// between the database and static files. **It may execute a pipeline unwind if it fails this @@ -466,7 +470,7 @@ where /// Creates a new [`ProviderFactory`] and attaches it to the launch context. pub async fn with_provider_factory>( self, - ) -> eyre::Result>>> { + ) -> eyre::Result, ProviderFactory>>> { let factory = self.create_provider_factory().await?; let ctx = LaunchContextWith { inner: self.inner, @@ -477,7 +481,7 @@ where } } -impl LaunchContextWith>> +impl LaunchContextWith, ProviderFactory>> where T: NodeTypesWithDB, { @@ -548,7 +552,7 @@ where /// prometheus. pub fn with_metrics_task( self, - ) -> LaunchContextWith>> { + ) -> LaunchContextWith, WithMeteredProvider>> { let (metrics_sender, metrics_receiver) = unbounded_channel(); let with_metrics = @@ -565,7 +569,7 @@ where } } -impl LaunchContextWith>> +impl LaunchContextWith, WithMeteredProvider>> where N: NodeTypesWithDB, { @@ -580,12 +584,13 @@ where } /// Creates a `BlockchainProvider` and attaches it to the launch context. + #[allow(clippy::complexity)] pub fn with_blockchain_db( self, create_blockchain_provider: F, tree_config: BlockchainTreeConfig, canon_state_notification_sender: CanonStateNotificationSender, - ) -> eyre::Result>>> + ) -> eyre::Result, WithMeteredProviders>>> where T: FullNodeTypes, F: FnOnce(ProviderFactory) -> eyre::Result, @@ -611,7 +616,10 @@ where } } -impl LaunchContextWith>> +impl + LaunchContextWith< + Attached::ChainSpec>, WithMeteredProviders>, + > where T: FullNodeTypes, Provider: WithTree>, { @@ -661,7 +669,11 @@ where on_component_initialized: Box< dyn OnComponentInitializedHook>, >, - ) -> eyre::Result>>> + ) -> eyre::Result< + LaunchContextWith< + Attached::ChainSpec>, WithComponents>, + >, + > where CB: NodeComponentsBuilder, { @@ -729,7 +741,10 @@ where } } -impl LaunchContextWith>> +impl + LaunchContextWith< + Attached::ChainSpec>, WithComponents>, + > where T: FullNodeTypes>, CB: NodeComponentsBuilder, @@ -855,7 +870,10 @@ where } } -impl LaunchContextWith>> +impl + LaunchContextWith< + Attached::ChainSpec>, WithComponents>, + > where T: FullNodeTypes< Provider: WithTree + StateProviderFactory + ChainSpecProvider, @@ -977,9 +995,9 @@ impl Attached { /// Helper container type to bundle the initial [`NodeConfig`] and the loaded settings from the /// reth.toml config #[derive(Debug, Clone)] -pub struct WithConfigs { +pub struct WithConfigs { /// The configured, usually derived from the CLI. - pub config: NodeConfig, + pub config: NodeConfig, /// The loaded reth.toml config. pub toml_config: reth_config::Config, } diff --git a/crates/node/builder/src/launch/engine.rs b/crates/node/builder/src/launch/engine.rs index 474635569..8b31b605e 100644 --- a/crates/node/builder/src/launch/engine.rs +++ b/crates/node/builder/src/launch/engine.rs @@ -42,6 +42,7 @@ use tokio::sync::{mpsc::unbounded_channel, oneshot}; use tokio_stream::wrappers::UnboundedReceiverStream; use crate::{ + common::{Attached, LaunchContextWith, WithConfigs}, hooks::NodeHooks, rpc::{launch_rpc_servers, EthApiBuilderProvider}, setup::build_networked_pipeline, @@ -132,7 +133,7 @@ where debug!(target: "reth::cli", chain=%this.chain_id(), genesis=?this.genesis_hash(), "Initializing genesis"); }) .with_genesis()? - .inspect(|this| { + .inspect(|this: &LaunchContextWith, _>>| { info!(target: "reth::cli", "\n{}", this.chain_spec().display_hardforks()); }) .with_metrics_task() diff --git a/crates/node/builder/src/launch/exex.rs b/crates/node/builder/src/launch/exex.rs index c3f842e5d..8624e3795 100644 --- a/crates/node/builder/src/launch/exex.rs +++ b/crates/node/builder/src/launch/exex.rs @@ -4,7 +4,7 @@ use std::{fmt, fmt::Debug}; use futures::future; use reth_exex::{ExExContext, ExExHandle, ExExManager, ExExManagerHandle}; -use reth_node_api::FullNodeComponents; +use reth_node_api::{FullNodeComponents, NodeTypes}; use reth_primitives::Head; use reth_provider::CanonStateSubscriptions; use reth_tracing::tracing::{debug, info}; @@ -17,7 +17,7 @@ pub struct ExExLauncher { head: Head, extensions: Vec<(String, Box>)>, components: Node, - config_container: WithConfigs, + config_container: WithConfigs<::ChainSpec>, } impl ExExLauncher { @@ -26,7 +26,7 @@ impl ExExLauncher { head: Head, components: Node, extensions: Vec<(String, Box>)>, - config_container: WithConfigs, + config_container: WithConfigs<::ChainSpec>, ) -> Self { Self { head, extensions, components, config_container } } diff --git a/crates/node/builder/src/launch/mod.rs b/crates/node/builder/src/launch/mod.rs index 2e0b9bec4..d8ebbfc03 100644 --- a/crates/node/builder/src/launch/mod.rs +++ b/crates/node/builder/src/launch/mod.rs @@ -6,6 +6,7 @@ mod exex; pub(crate) mod engine; pub use common::LaunchContext; +use common::{Attached, LaunchContextWith, WithConfigs}; pub use exex::ExExLauncher; use std::{future::Future, sync::Arc}; @@ -170,7 +171,7 @@ where debug!(target: "reth::cli", chain=%this.chain_id(), genesis=?this.genesis_hash(), "Initializing genesis"); }) .with_genesis()? - .inspect(|this| { + .inspect(|this: &LaunchContextWith, _>>| { info!(target: "reth::cli", "\n{}", this.chain_spec().display_hardforks()); }) .with_metrics_task() diff --git a/crates/node/builder/src/node.rs b/crates/node/builder/src/node.rs index 912046643..5d047f94c 100644 --- a/crates/node/builder/src/node.rs +++ b/crates/node/builder/src/node.rs @@ -110,7 +110,7 @@ pub struct FullNode> { /// The configured rpc namespaces pub rpc_registry: RpcRegistry, /// The initial node config. - pub config: NodeConfig, + pub config: NodeConfig<::ChainSpec>, /// The data dir of the node. pub data_dir: ChainPath, } diff --git a/crates/node/builder/src/rpc.rs b/crates/node/builder/src/rpc.rs index 64ce0b8ff..6b5818ff0 100644 --- a/crates/node/builder/src/rpc.rs +++ b/crates/node/builder/src/rpc.rs @@ -7,7 +7,9 @@ use std::{ use futures::TryFutureExt; use reth_chainspec::ChainSpec; -use reth_node_api::{BuilderProvider, FullNodeComponents, NodeTypesWithDB, NodeTypesWithEngine}; +use reth_node_api::{ + BuilderProvider, FullNodeComponents, NodeTypes, NodeTypesWithDB, NodeTypesWithEngine, +}; use reth_node_core::{ node_config::NodeConfig, rpc::{ @@ -237,7 +239,7 @@ pub struct RpcContext<'a, Node: FullNodeComponents, EthApi: EthApiTypes> { pub(crate) node: Node, /// Gives access to the node configuration. - pub(crate) config: &'a NodeConfig, + pub(crate) config: &'a NodeConfig<::ChainSpec>, /// A Helper type the holds instances of the configured modules. /// @@ -260,7 +262,7 @@ where EthApi: EthApiTypes, { /// Returns the config of the node. - pub const fn config(&self) -> &NodeConfig { + pub const fn config(&self) -> &NodeConfig<::ChainSpec> { self.config } @@ -296,7 +298,7 @@ where pub async fn launch_rpc_servers( node: Node, engine_api: Engine, - config: &NodeConfig, + config: &NodeConfig, jwt_secret: JwtSecret, add_ons: RpcAddOns, ) -> eyre::Result<(RethRpcServerHandles, RpcRegistry)> diff --git a/crates/node/core/src/args/pruning.rs b/crates/node/core/src/args/pruning.rs index ac4ea8f73..2bee5ec16 100644 --- a/crates/node/core/src/args/pruning.rs +++ b/crates/node/core/src/args/pruning.rs @@ -3,7 +3,7 @@ use crate::args::error::ReceiptsLogError; use alloy_primitives::{Address, BlockNumber}; use clap::Args; -use reth_chainspec::ChainSpec; +use reth_chainspec::EthChainSpec; use reth_config::config::PruneConfig; use reth_prune_types::{PruneMode, PruneModes, ReceiptsLogPruneConfig, MINIMUM_PRUNING_DISTANCE}; use std::collections::BTreeMap; @@ -92,7 +92,7 @@ pub struct PruningArgs { impl PruningArgs { /// Returns pruning configuration. - pub fn prune_config(&self, chain_spec: &ChainSpec) -> Option { + pub fn prune_config(&self, chain_spec: &impl EthChainSpec) -> Option { // Initialise with a default prune configuration. let mut config = PruneConfig::default(); @@ -106,16 +106,14 @@ impl PruningArgs { // prune all receipts if chain doesn't have deposit contract specified in chain // spec receipts: chain_spec - .deposit_contract - .as_ref() + .deposit_contract() .map(|contract| PruneMode::Before(contract.block)) .or(Some(PruneMode::Distance(MINIMUM_PRUNING_DISTANCE))), account_history: Some(PruneMode::Distance(MINIMUM_PRUNING_DISTANCE)), storage_history: Some(PruneMode::Distance(MINIMUM_PRUNING_DISTANCE)), receipts_log_filter: ReceiptsLogPruneConfig( chain_spec - .deposit_contract - .as_ref() + .deposit_contract() .map(|contract| (contract.address, PruneMode::Before(contract.block))) .into_iter() .collect(), diff --git a/crates/node/core/src/node_config.rs b/crates/node/core/src/node_config.rs index d4cdd2f88..de6929824 100644 --- a/crates/node/core/src/node_config.rs +++ b/crates/node/core/src/node_config.rs @@ -9,7 +9,7 @@ use crate::{ utils::get_single_header, }; use eyre::eyre; -use reth_chainspec::{ChainSpec, MAINNET}; +use reth_chainspec::{ChainSpec, EthChainSpec, MAINNET}; use reth_config::config::PruneConfig; use reth_network_p2p::headers::client::HeadersClient; use serde::{de::DeserializeOwned, Serialize}; @@ -70,8 +70,8 @@ use tracing::*; /// let builder = builder.with_rpc(rpc); /// } /// ``` -#[derive(Debug, Clone)] -pub struct NodeConfig { +#[derive(Debug)] +pub struct NodeConfig { /// All data directory related arguments pub datadir: DatadirArgs, @@ -129,14 +129,16 @@ pub struct NodeConfig { pub pruning: PruningArgs, } -impl NodeConfig { +impl NodeConfig { /// Creates a testing [`NodeConfig`], causing the database to be launched ephemerally. pub fn test() -> Self { Self::default() // set all ports to zero by default for test instances .with_unused_ports() } +} +impl NodeConfig { /// Sets --dev mode for the node. /// /// In addition to setting the `--dev` flag, this also: @@ -235,7 +237,10 @@ impl NodeConfig { } /// Returns pruning configuration. - pub fn prune_config(&self) -> Option { + pub fn prune_config(&self) -> Option + where + ChainSpec: EthChainSpec, + { self.pruning.prune_config(&self.chain) } @@ -365,8 +370,11 @@ impl NodeConfig { } /// Resolve the final datadir path. - pub fn datadir(&self) -> ChainPath { - self.datadir.clone().resolve_datadir(self.chain.chain) + pub fn datadir(&self) -> ChainPath + where + ChainSpec: EthChainSpec, + { + self.datadir.clone().resolve_datadir(self.chain.chain()) } /// Load an application configuration from a specified path. @@ -397,7 +405,7 @@ impl NodeConfig { } } -impl Default for NodeConfig { +impl Default for NodeConfig { fn default() -> Self { Self { config: None, @@ -416,3 +424,23 @@ impl Default for NodeConfig { } } } + +impl Clone for NodeConfig { + fn clone(&self) -> Self { + Self { + chain: self.chain.clone(), + config: self.config.clone(), + metrics: self.metrics, + instance: self.instance, + network: self.network.clone(), + rpc: self.rpc.clone(), + txpool: self.txpool.clone(), + builder: self.builder.clone(), + debug: self.debug.clone(), + db: self.db, + dev: self.dev, + pruning: self.pruning.clone(), + datadir: self.datadir.clone(), + } + } +} diff --git a/crates/optimism/cli/src/lib.rs b/crates/optimism/cli/src/lib.rs index e2d06e00a..67a48bae0 100644 --- a/crates/optimism/cli/src/lib.rs +++ b/crates/optimism/cli/src/lib.rs @@ -123,7 +123,7 @@ where /// [`NodeCommand`](reth_cli_commands::node::NodeCommand). pub fn run(mut self, launcher: L) -> eyre::Result<()> where - L: FnOnce(WithLaunchContext>>, Ext) -> Fut, + L: FnOnce(WithLaunchContext, ChainSpec>>, Ext) -> Fut, Fut: Future>, { // add network name to logs dir