mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: make NodeConfig generic over ChainSpec (#11039)
This commit is contained in:
@ -133,7 +133,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>, Ext: clap::Args + fmt::Debug> Cl
|
||||
/// ````
|
||||
pub fn run<L, Fut>(mut self, launcher: L) -> eyre::Result<()>
|
||||
where
|
||||
L: FnOnce(WithLaunchContext<NodeBuilder<Arc<DatabaseEnv>>>, Ext) -> Fut,
|
||||
L: FnOnce(WithLaunchContext<NodeBuilder<Arc<DatabaseEnv>, C::ChainSpec>>, Ext) -> Fut,
|
||||
Fut: Future<Output = eyre::Result<()>>,
|
||||
{
|
||||
// add network name to logs dir
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>, Ext: clap::Args + fmt::Debug> No
|
||||
/// closure.
|
||||
pub async fn execute<L, Fut>(self, ctx: CliContext, launcher: L) -> eyre::Result<()>
|
||||
where
|
||||
L: FnOnce(WithLaunchContext<NodeBuilder<Arc<DatabaseEnv>>>, Ext) -> Fut,
|
||||
L: FnOnce(WithLaunchContext<NodeBuilder<Arc<DatabaseEnv>, C::ChainSpec>>, Ext) -> Fut,
|
||||
Fut: Future<Output = eyre::Result<()>>,
|
||||
{
|
||||
tracing::info!(target: "reth::cli", version = ?version::SHORT_VERSION, "Starting reth");
|
||||
|
||||
@ -281,7 +281,7 @@ pub struct EthereumNetworkBuilder {
|
||||
|
||||
impl<Node, Pool> NetworkBuilder<Node, Pool> for EthereumNetworkBuilder
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
Node: FullNodeTypes<Types: NodeTypes<ChainSpec = ChainSpec>>,
|
||||
Pool: TransactionPool + Unpin + 'static,
|
||||
{
|
||||
async fn build_network(
|
||||
|
||||
@ -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<Node: FullNodeComponents> {
|
||||
/// The current head of the blockchain at launch.
|
||||
pub head: Head,
|
||||
/// The config of the node
|
||||
pub config: NodeConfig,
|
||||
pub config: NodeConfig<<Node::Types as NodeTypes>::ChainSpec>,
|
||||
/// The loaded node config
|
||||
pub reth_config: reth_config::Config,
|
||||
/// Channel used to send [`ExExEvent`]s to the rest of the node.
|
||||
|
||||
@ -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<DB, Types> = 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<DB> {
|
||||
pub struct NodeBuilder<DB, ChainSpec> {
|
||||
/// All settings for how the node should be configured.
|
||||
config: NodeConfig,
|
||||
config: NodeConfig<ChainSpec>,
|
||||
/// The configured database for the node.
|
||||
database: DB,
|
||||
}
|
||||
|
||||
impl NodeBuilder<()> {
|
||||
impl<ChainSpec> NodeBuilder<(), ChainSpec> {
|
||||
/// Create a new [`NodeBuilder`].
|
||||
pub const fn new(config: NodeConfig) -> Self {
|
||||
pub const fn new(config: NodeConfig<ChainSpec>) -> Self {
|
||||
Self { config, database: () }
|
||||
}
|
||||
}
|
||||
|
||||
impl<DB> NodeBuilder<DB> {
|
||||
impl<DB, ChainSpec> NodeBuilder<DB, ChainSpec> {
|
||||
/// Returns a reference to the node builder's config.
|
||||
pub const fn config(&self) -> &NodeConfig {
|
||||
pub const fn config(&self) -> &NodeConfig<ChainSpec> {
|
||||
&self.config
|
||||
}
|
||||
}
|
||||
|
||||
impl<DB, ChainSpec: EthChainSpec> NodeBuilder<DB, ChainSpec> {
|
||||
/// Configures the underlying database that the node will use.
|
||||
pub fn with_database<D>(self, database: D) -> NodeBuilder<D> {
|
||||
pub fn with_database<D>(self, database: D) -> NodeBuilder<D, ChainSpec> {
|
||||
NodeBuilder { config: self.config, database }
|
||||
}
|
||||
|
||||
@ -191,8 +193,9 @@ impl<DB> NodeBuilder<DB> {
|
||||
pub fn testing_node(
|
||||
mut self,
|
||||
task_executor: TaskExecutor,
|
||||
) -> WithLaunchContext<NodeBuilder<Arc<reth_db::test_utils::TempDatabase<reth_db::DatabaseEnv>>>>
|
||||
{
|
||||
) -> WithLaunchContext<
|
||||
NodeBuilder<Arc<reth_db::test_utils::TempDatabase<reth_db::DatabaseEnv>>, ChainSpec>,
|
||||
> {
|
||||
let path = reth_node_core::dirs::MaybePlatformPath::<DataDirPath>::from(
|
||||
reth_db::test_utils::tempdir_path(),
|
||||
);
|
||||
@ -202,7 +205,7 @@ impl<DB> NodeBuilder<DB> {
|
||||
});
|
||||
|
||||
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<DB> NodeBuilder<DB> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<DB> NodeBuilder<DB>
|
||||
impl<DB> NodeBuilder<DB, ChainSpec>
|
||||
where
|
||||
DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static,
|
||||
{
|
||||
@ -263,15 +266,17 @@ impl<Builder> WithLaunchContext<Builder> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<DB> WithLaunchContext<NodeBuilder<DB>>
|
||||
impl<DB, ChainSpec> WithLaunchContext<NodeBuilder<DB, ChainSpec>> {
|
||||
/// Returns a reference to the node builder's config.
|
||||
pub const fn config(&self) -> &NodeConfig<ChainSpec> {
|
||||
self.builder.config()
|
||||
}
|
||||
}
|
||||
|
||||
impl<DB> WithLaunchContext<NodeBuilder<DB, ChainSpec>>
|
||||
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<T>(self) -> WithLaunchContext<NodeBuilderWithTypes<RethFullAdapter<DB, T>>>
|
||||
where
|
||||
@ -395,7 +400,7 @@ where
|
||||
AO: NodeAddOns<NodeAdapter<T, CB::Components>, EthApi: FullEthApiServer + AddDevSigners>,
|
||||
{
|
||||
/// Returns a reference to the node builder's config.
|
||||
pub const fn config(&self) -> &NodeConfig {
|
||||
pub const fn config(&self) -> &NodeConfig<<T::Types as NodeTypes>::ChainSpec> {
|
||||
&self.builder.config
|
||||
}
|
||||
|
||||
@ -520,7 +525,7 @@ pub struct BuilderContext<Node: FullNodeTypes> {
|
||||
/// The executor of the node.
|
||||
pub(crate) executor: TaskExecutor,
|
||||
/// Config container
|
||||
pub(crate) config_container: WithConfigs,
|
||||
pub(crate) config_container: WithConfigs<<Node::Types as NodeTypes>::ChainSpec>,
|
||||
}
|
||||
|
||||
impl<Node: FullNodeTypes> BuilderContext<Node> {
|
||||
@ -529,7 +534,7 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
|
||||
head: Head,
|
||||
provider: Node::Provider,
|
||||
executor: TaskExecutor,
|
||||
config_container: WithConfigs,
|
||||
config_container: WithConfigs<<Node::Types as NodeTypes>::ChainSpec>,
|
||||
) -> Self {
|
||||
Self { head, provider, executor, config_container }
|
||||
}
|
||||
@ -545,7 +550,7 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
|
||||
}
|
||||
|
||||
/// Returns the config of the node.
|
||||
pub const fn config(&self) -> &NodeConfig {
|
||||
pub const fn config(&self) -> &NodeConfig<<Node::Types as NodeTypes>::ChainSpec> {
|
||||
&self.config_container.config
|
||||
}
|
||||
|
||||
@ -586,13 +591,6 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
|
||||
self.config().builder.clone()
|
||||
}
|
||||
|
||||
/// Creates the [`NetworkBuilder`] for the node.
|
||||
pub async fn network_builder(&self) -> eyre::Result<NetworkBuilder<(), ()>> {
|
||||
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<Node: FullNodeTypes> BuilderContext<Node> {
|
||||
handle
|
||||
}
|
||||
|
||||
/// Get the network secret from the given data dir
|
||||
fn network_secret(&self, data_dir: &ChainPath<DataDirPath>) -> eyre::Result<SecretKey> {
|
||||
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<Node::Provider> {
|
||||
network_builder.build(self.provider.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node: FullNodeTypes<Types: NodeTypes<ChainSpec = ChainSpec>>> BuilderContext<Node> {
|
||||
/// Creates the [`NetworkBuilder`] for the node.
|
||||
pub async fn network_builder(&self) -> eyre::Result<NetworkBuilder<(), ()>> {
|
||||
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<NetworkConfig<Node::Provider>> {
|
||||
let network_builder = self.network_config_builder();
|
||||
@ -658,22 +681,6 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
|
||||
|
||||
Ok(builder)
|
||||
}
|
||||
|
||||
/// Get the network secret from the given data dir
|
||||
fn network_secret(&self, data_dir: &ChainPath<DataDirPath>) -> eyre::Result<SecretKey> {
|
||||
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<Node::Provider> {
|
||||
network_builder.build(self.provider.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node: FullNodeTypes> std::fmt::Debug for BuilderContext<Node> {
|
||||
|
||||
@ -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<T: FullNodeTypes> {
|
||||
/// All settings for how the node should be configured.
|
||||
config: NodeConfig,
|
||||
config: NodeConfig<<T::Types as NodeTypes>::ChainSpec>,
|
||||
/// The configured database for the node.
|
||||
adapter: NodeTypesAdapter<T>,
|
||||
}
|
||||
|
||||
impl<T: FullNodeTypes> NodeBuilderWithTypes<T> {
|
||||
/// Creates a new instance of the node builder with the given configuration and types.
|
||||
pub const fn new(config: NodeConfig, database: <T::Types as NodeTypesWithDB>::DB) -> Self {
|
||||
pub const fn new(
|
||||
config: NodeConfig<<T::Types as NodeTypes>::ChainSpec>,
|
||||
database: <T::Types as NodeTypesWithDB>::DB,
|
||||
) -> Self {
|
||||
Self { config, adapter: NodeTypesAdapter::new(database) }
|
||||
}
|
||||
|
||||
@ -149,7 +152,7 @@ pub struct NodeBuilderWithComponents<
|
||||
AO: NodeAddOns<NodeAdapter<T, CB::Components>>,
|
||||
> {
|
||||
/// All settings for how the node should be configured.
|
||||
pub config: NodeConfig,
|
||||
pub config: NodeConfig<<T::Types as NodeTypes>::ChainSpec>,
|
||||
/// Adapter for the underlying node types and database
|
||||
pub adapter: NodeTypesAdapter<T>,
|
||||
/// container for type specific components
|
||||
|
||||
@ -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<ChainSpec: EthChainSpec>(
|
||||
self,
|
||||
config: NodeConfig,
|
||||
) -> eyre::Result<LaunchContextWith<WithConfigs>> {
|
||||
config: NodeConfig<ChainSpec>,
|
||||
) -> eyre::Result<LaunchContextWith<WithConfigs<ChainSpec>>> {
|
||||
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<reth_config::Config> {
|
||||
pub fn load_toml_config<ChainSpec: EthChainSpec>(
|
||||
&self,
|
||||
config: &NodeConfig<ChainSpec>,
|
||||
) -> eyre::Result<reth_config::Config> {
|
||||
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<ChainSpec: EthChainSpec>(
|
||||
reth_config: &mut reth_config::Config,
|
||||
config: &NodeConfig,
|
||||
config: &NodeConfig<ChainSpec>,
|
||||
config_path: impl AsRef<std::path::Path>,
|
||||
) -> eyre::Result<()> {
|
||||
if reth_config.prune.is_none() {
|
||||
@ -242,7 +245,7 @@ impl<T> LaunchContextWith<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl LaunchContextWith<WithConfigs> {
|
||||
impl<ChainSpec> LaunchContextWith<WithConfigs<ChainSpec>> {
|
||||
/// Resolves the trusted peers and adds them to the toml config.
|
||||
pub async fn with_resolved_peers(mut self) -> eyre::Result<Self> {
|
||||
if !self.attachment.config.network.trusted_peers.is_empty() {
|
||||
@ -279,7 +282,7 @@ impl<L, R> LaunchContextWith<Attached<L, R>> {
|
||||
&mut self.attachment.right
|
||||
}
|
||||
}
|
||||
impl<R> LaunchContextWith<Attached<WithConfigs, R>> {
|
||||
impl<R, ChainSpec: EthChainSpec> LaunchContextWith<Attached<WithConfigs<ChainSpec>, R>> {
|
||||
/// Adjust certain settings in the config to make sure they are set correctly
|
||||
///
|
||||
/// This includes:
|
||||
@ -306,17 +309,17 @@ impl<R> LaunchContextWith<Attached<WithConfigs, R>> {
|
||||
}
|
||||
|
||||
/// Returns the container for all config types
|
||||
pub const fn configs(&self) -> &WithConfigs {
|
||||
pub const fn configs(&self) -> &WithConfigs<ChainSpec> {
|
||||
self.attachment.left()
|
||||
}
|
||||
|
||||
/// Returns the attached [`NodeConfig`].
|
||||
pub const fn node_config(&self) -> &NodeConfig {
|
||||
pub const fn node_config(&self) -> &NodeConfig<ChainSpec> {
|
||||
&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<ChainSpec> {
|
||||
&mut self.left_mut().config
|
||||
}
|
||||
|
||||
@ -342,7 +345,7 @@ impl<R> LaunchContextWith<Attached<WithConfigs, R>> {
|
||||
|
||||
/// 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<R> LaunchContextWith<Attached<WithConfigs, R>> {
|
||||
/// 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<R> LaunchContextWith<Attached<WithConfigs, R>> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<DB> LaunchContextWith<Attached<WithConfigs, DB>>
|
||||
impl<DB, ChainSpec> LaunchContextWith<Attached<WithConfigs<ChainSpec>, 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<N: NodeTypesWithDB<DB = DB, ChainSpec = ChainSpec>>(
|
||||
self,
|
||||
) -> eyre::Result<LaunchContextWith<Attached<WithConfigs, ProviderFactory<N>>>> {
|
||||
) -> eyre::Result<LaunchContextWith<Attached<WithConfigs<ChainSpec>, ProviderFactory<N>>>> {
|
||||
let factory = self.create_provider_factory().await?;
|
||||
let ctx = LaunchContextWith {
|
||||
inner: self.inner,
|
||||
@ -477,7 +481,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> LaunchContextWith<Attached<WithConfigs, ProviderFactory<T>>>
|
||||
impl<T> LaunchContextWith<Attached<WithConfigs<T::ChainSpec>, ProviderFactory<T>>>
|
||||
where
|
||||
T: NodeTypesWithDB<ChainSpec = ChainSpec>,
|
||||
{
|
||||
@ -548,7 +552,7 @@ where
|
||||
/// prometheus.
|
||||
pub fn with_metrics_task(
|
||||
self,
|
||||
) -> LaunchContextWith<Attached<WithConfigs, WithMeteredProvider<T>>> {
|
||||
) -> LaunchContextWith<Attached<WithConfigs<T::ChainSpec>, WithMeteredProvider<T>>> {
|
||||
let (metrics_sender, metrics_receiver) = unbounded_channel();
|
||||
|
||||
let with_metrics =
|
||||
@ -565,7 +569,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> LaunchContextWith<Attached<WithConfigs, WithMeteredProvider<N>>>
|
||||
impl<N> LaunchContextWith<Attached<WithConfigs<N::ChainSpec>, WithMeteredProvider<N>>>
|
||||
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<T, F>(
|
||||
self,
|
||||
create_blockchain_provider: F,
|
||||
tree_config: BlockchainTreeConfig,
|
||||
canon_state_notification_sender: CanonStateNotificationSender,
|
||||
) -> eyre::Result<LaunchContextWith<Attached<WithConfigs, WithMeteredProviders<T>>>>
|
||||
) -> eyre::Result<LaunchContextWith<Attached<WithConfigs<N::ChainSpec>, WithMeteredProviders<T>>>>
|
||||
where
|
||||
T: FullNodeTypes<Types = N>,
|
||||
F: FnOnce(ProviderFactory<N>) -> eyre::Result<T::Provider>,
|
||||
@ -611,7 +616,10 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> LaunchContextWith<Attached<WithConfigs, WithMeteredProviders<T>>>
|
||||
impl<T>
|
||||
LaunchContextWith<
|
||||
Attached<WithConfigs<<T::Types as NodeTypes>::ChainSpec>, WithMeteredProviders<T>>,
|
||||
>
|
||||
where
|
||||
T: FullNodeTypes<Types: NodeTypesWithDB<ChainSpec = ChainSpec>, Provider: WithTree>,
|
||||
{
|
||||
@ -661,7 +669,11 @@ where
|
||||
on_component_initialized: Box<
|
||||
dyn OnComponentInitializedHook<NodeAdapter<T, CB::Components>>,
|
||||
>,
|
||||
) -> eyre::Result<LaunchContextWith<Attached<WithConfigs, WithComponents<T, CB>>>>
|
||||
) -> eyre::Result<
|
||||
LaunchContextWith<
|
||||
Attached<WithConfigs<<T::Types as NodeTypes>::ChainSpec>, WithComponents<T, CB>>,
|
||||
>,
|
||||
>
|
||||
where
|
||||
CB: NodeComponentsBuilder<T>,
|
||||
{
|
||||
@ -729,7 +741,10 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, CB> LaunchContextWith<Attached<WithConfigs, WithComponents<T, CB>>>
|
||||
impl<T, CB>
|
||||
LaunchContextWith<
|
||||
Attached<WithConfigs<<T::Types as NodeTypes>::ChainSpec>, WithComponents<T, CB>>,
|
||||
>
|
||||
where
|
||||
T: FullNodeTypes<Provider: WithTree, Types: NodeTypes<ChainSpec = ChainSpec>>,
|
||||
CB: NodeComponentsBuilder<T>,
|
||||
@ -855,7 +870,10 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, CB> LaunchContextWith<Attached<WithConfigs, WithComponents<T, CB>>>
|
||||
impl<T, CB>
|
||||
LaunchContextWith<
|
||||
Attached<WithConfigs<<T::Types as NodeTypes>::ChainSpec>, WithComponents<T, CB>>,
|
||||
>
|
||||
where
|
||||
T: FullNodeTypes<
|
||||
Provider: WithTree + StateProviderFactory + ChainSpecProvider<ChainSpec = ChainSpec>,
|
||||
@ -977,9 +995,9 @@ impl<L, R> Attached<L, R> {
|
||||
/// 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<ChainSpec> {
|
||||
/// The configured, usually derived from the CLI.
|
||||
pub config: NodeConfig,
|
||||
pub config: NodeConfig<ChainSpec>,
|
||||
/// The loaded reth.toml config.
|
||||
pub toml_config: reth_config::Config,
|
||||
}
|
||||
|
||||
@ -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<Attached<WithConfigs<ChainSpec>, _>>| {
|
||||
info!(target: "reth::cli", "\n{}", this.chain_spec().display_hardforks());
|
||||
})
|
||||
.with_metrics_task()
|
||||
|
||||
@ -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<Node: FullNodeComponents> {
|
||||
head: Head,
|
||||
extensions: Vec<(String, Box<dyn BoxedLaunchExEx<Node>>)>,
|
||||
components: Node,
|
||||
config_container: WithConfigs,
|
||||
config_container: WithConfigs<<Node::Types as NodeTypes>::ChainSpec>,
|
||||
}
|
||||
|
||||
impl<Node: FullNodeComponents + Clone> ExExLauncher<Node> {
|
||||
@ -26,7 +26,7 @@ impl<Node: FullNodeComponents + Clone> ExExLauncher<Node> {
|
||||
head: Head,
|
||||
components: Node,
|
||||
extensions: Vec<(String, Box<dyn BoxedLaunchExEx<Node>>)>,
|
||||
config_container: WithConfigs,
|
||||
config_container: WithConfigs<<Node::Types as NodeTypes>::ChainSpec>,
|
||||
) -> Self {
|
||||
Self { head, extensions, components, config_container }
|
||||
}
|
||||
|
||||
@ -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<Attached<WithConfigs<ChainSpec>, _>>| {
|
||||
info!(target: "reth::cli", "\n{}", this.chain_spec().display_hardforks());
|
||||
})
|
||||
.with_metrics_task()
|
||||
|
||||
@ -110,7 +110,7 @@ pub struct FullNode<Node: FullNodeComponents, AddOns: NodeAddOns<Node>> {
|
||||
/// The configured rpc namespaces
|
||||
pub rpc_registry: RpcRegistry<Node, AddOns::EthApi>,
|
||||
/// The initial node config.
|
||||
pub config: NodeConfig,
|
||||
pub config: NodeConfig<<Node::Types as NodeTypes>::ChainSpec>,
|
||||
/// The data dir of the node.
|
||||
pub data_dir: ChainPath<DataDirPath>,
|
||||
}
|
||||
|
||||
@ -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<<Node::Types as NodeTypes>::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<<Node::Types as NodeTypes>::ChainSpec> {
|
||||
self.config
|
||||
}
|
||||
|
||||
@ -296,7 +298,7 @@ where
|
||||
pub async fn launch_rpc_servers<Node, Engine, EthApi>(
|
||||
node: Node,
|
||||
engine_api: Engine,
|
||||
config: &NodeConfig,
|
||||
config: &NodeConfig<ChainSpec>,
|
||||
jwt_secret: JwtSecret,
|
||||
add_ons: RpcAddOns<Node, EthApi>,
|
||||
) -> eyre::Result<(RethRpcServerHandles, RpcRegistry<Node, EthApi>)>
|
||||
|
||||
@ -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<PruneConfig> {
|
||||
pub fn prune_config(&self, chain_spec: &impl EthChainSpec) -> Option<PruneConfig> {
|
||||
// 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(),
|
||||
|
||||
@ -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<ChainSpec> {
|
||||
/// All data directory related arguments
|
||||
pub datadir: DatadirArgs,
|
||||
|
||||
@ -129,14 +129,16 @@ pub struct NodeConfig {
|
||||
pub pruning: PruningArgs,
|
||||
}
|
||||
|
||||
impl NodeConfig {
|
||||
impl NodeConfig<ChainSpec> {
|
||||
/// 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<ChainSpec> NodeConfig<ChainSpec> {
|
||||
/// 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<PruneConfig> {
|
||||
pub fn prune_config(&self) -> Option<PruneConfig>
|
||||
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<DataDirPath> {
|
||||
self.datadir.clone().resolve_datadir(self.chain.chain)
|
||||
pub fn datadir(&self) -> ChainPath<DataDirPath>
|
||||
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<ChainSpec> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
config: None,
|
||||
@ -416,3 +424,23 @@ impl Default for NodeConfig {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<ChainSpec> Clone for NodeConfig<ChainSpec> {
|
||||
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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ where
|
||||
/// [`NodeCommand`](reth_cli_commands::node::NodeCommand).
|
||||
pub fn run<L, Fut>(mut self, launcher: L) -> eyre::Result<()>
|
||||
where
|
||||
L: FnOnce(WithLaunchContext<NodeBuilder<Arc<DatabaseEnv>>>, Ext) -> Fut,
|
||||
L: FnOnce(WithLaunchContext<NodeBuilder<Arc<DatabaseEnv>, ChainSpec>>, Ext) -> Fut,
|
||||
Fut: Future<Output = eyre::Result<()>>,
|
||||
{
|
||||
// add network name to logs dir
|
||||
|
||||
Reference in New Issue
Block a user