mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +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<()>
|
pub fn run<L, Fut>(mut self, launcher: L) -> eyre::Result<()>
|
||||||
where
|
where
|
||||||
L: FnOnce(WithLaunchContext<NodeBuilder<Arc<DatabaseEnv>>>, Ext) -> Fut,
|
L: FnOnce(WithLaunchContext<NodeBuilder<Arc<DatabaseEnv>, C::ChainSpec>>, Ext) -> Fut,
|
||||||
Fut: Future<Output = eyre::Result<()>>,
|
Fut: Future<Output = eyre::Result<()>>,
|
||||||
{
|
{
|
||||||
// add network name to logs dir
|
// add network name to logs dir
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
use crate::ChainSpec;
|
use crate::{ChainSpec, DepositContract};
|
||||||
use alloy_chains::Chain;
|
use alloy_chains::Chain;
|
||||||
use alloy_eips::eip1559::BaseFeeParams;
|
use alloy_eips::eip1559::BaseFeeParams;
|
||||||
|
use alloy_primitives::B256;
|
||||||
use core::fmt::Debug;
|
use core::fmt::Debug;
|
||||||
|
|
||||||
/// Trait representing type configuring a chain spec.
|
/// 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.
|
/// Get the [`BaseFeeParams`] for the chain at the given timestamp.
|
||||||
fn base_fee_params_at_timestamp(&self, timestamp: u64) -> BaseFeeParams;
|
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 {
|
impl EthChainSpec for ChainSpec {
|
||||||
@ -24,4 +34,16 @@ impl EthChainSpec for ChainSpec {
|
|||||||
fn base_fee_params_at_timestamp(&self, timestamp: u64) -> BaseFeeParams {
|
fn base_fee_params_at_timestamp(&self, timestamp: u64) -> BaseFeeParams {
|
||||||
self.base_fee_params_at_timestamp(timestamp)
|
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.
|
/// closure.
|
||||||
pub async fn execute<L, Fut>(self, ctx: CliContext, launcher: L) -> eyre::Result<()>
|
pub async fn execute<L, Fut>(self, ctx: CliContext, launcher: L) -> eyre::Result<()>
|
||||||
where
|
where
|
||||||
L: FnOnce(WithLaunchContext<NodeBuilder<Arc<DatabaseEnv>>>, Ext) -> Fut,
|
L: FnOnce(WithLaunchContext<NodeBuilder<Arc<DatabaseEnv>, C::ChainSpec>>, Ext) -> Fut,
|
||||||
Fut: Future<Output = eyre::Result<()>>,
|
Fut: Future<Output = eyre::Result<()>>,
|
||||||
{
|
{
|
||||||
tracing::info!(target: "reth::cli", version = ?version::SHORT_VERSION, "Starting reth");
|
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
|
impl<Node, Pool> NetworkBuilder<Node, Pool> for EthereumNetworkBuilder
|
||||||
where
|
where
|
||||||
Node: FullNodeTypes,
|
Node: FullNodeTypes<Types: NodeTypes<ChainSpec = ChainSpec>>,
|
||||||
Pool: TransactionPool + Unpin + 'static,
|
Pool: TransactionPool + Unpin + 'static,
|
||||||
{
|
{
|
||||||
async fn build_network(
|
async fn build_network(
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
use std::fmt::Debug;
|
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_node_core::node_config::NodeConfig;
|
||||||
use reth_primitives::Head;
|
use reth_primitives::Head;
|
||||||
use reth_tasks::TaskExecutor;
|
use reth_tasks::TaskExecutor;
|
||||||
@ -13,7 +13,7 @@ pub struct ExExContext<Node: FullNodeComponents> {
|
|||||||
/// The current head of the blockchain at launch.
|
/// The current head of the blockchain at launch.
|
||||||
pub head: Head,
|
pub head: Head,
|
||||||
/// The config of the node
|
/// The config of the node
|
||||||
pub config: NodeConfig,
|
pub config: NodeConfig<<Node::Types as NodeTypes>::ChainSpec>,
|
||||||
/// The loaded node config
|
/// The loaded node config
|
||||||
pub reth_config: reth_config::Config,
|
pub reth_config: reth_config::Config,
|
||||||
/// Channel used to send [`ExExEvent`]s to the rest of the node.
|
/// Channel used to send [`ExExEvent`]s to the rest of the node.
|
||||||
|
|||||||
@ -11,7 +11,7 @@ pub use states::*;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use reth_chainspec::ChainSpec;
|
use reth_chainspec::{ChainSpec, EthChainSpec};
|
||||||
use reth_cli_util::get_secret_key;
|
use reth_cli_util::get_secret_key;
|
||||||
use reth_db_api::{
|
use reth_db_api::{
|
||||||
database::Database,
|
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.
|
/// 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
|
/// [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.
|
/// All settings for how the node should be configured.
|
||||||
config: NodeConfig,
|
config: NodeConfig<ChainSpec>,
|
||||||
/// The configured database for the node.
|
/// The configured database for the node.
|
||||||
database: DB,
|
database: DB,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NodeBuilder<()> {
|
impl<ChainSpec> NodeBuilder<(), ChainSpec> {
|
||||||
/// Create a new [`NodeBuilder`].
|
/// Create a new [`NodeBuilder`].
|
||||||
pub const fn new(config: NodeConfig) -> Self {
|
pub const fn new(config: NodeConfig<ChainSpec>) -> Self {
|
||||||
Self { config, database: () }
|
Self { config, database: () }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<DB> NodeBuilder<DB> {
|
impl<DB, ChainSpec> NodeBuilder<DB, ChainSpec> {
|
||||||
/// Returns a reference to the node builder's config.
|
/// Returns a reference to the node builder's config.
|
||||||
pub const fn config(&self) -> &NodeConfig {
|
pub const fn config(&self) -> &NodeConfig<ChainSpec> {
|
||||||
&self.config
|
&self.config
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<DB, ChainSpec: EthChainSpec> NodeBuilder<DB, ChainSpec> {
|
||||||
/// Configures the underlying database that the node will use.
|
/// 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 }
|
NodeBuilder { config: self.config, database }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,8 +193,9 @@ impl<DB> NodeBuilder<DB> {
|
|||||||
pub fn testing_node(
|
pub fn testing_node(
|
||||||
mut self,
|
mut self,
|
||||||
task_executor: TaskExecutor,
|
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(
|
let path = reth_node_core::dirs::MaybePlatformPath::<DataDirPath>::from(
|
||||||
reth_db::test_utils::tempdir_path(),
|
reth_db::test_utils::tempdir_path(),
|
||||||
);
|
);
|
||||||
@ -202,7 +205,7 @@ impl<DB> NodeBuilder<DB> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let data_dir =
|
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());
|
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
|
where
|
||||||
DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static,
|
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
|
where
|
||||||
DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static,
|
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.
|
/// Configures the types of the node.
|
||||||
pub fn with_types<T>(self) -> WithLaunchContext<NodeBuilderWithTypes<RethFullAdapter<DB, T>>>
|
pub fn with_types<T>(self) -> WithLaunchContext<NodeBuilderWithTypes<RethFullAdapter<DB, T>>>
|
||||||
where
|
where
|
||||||
@ -395,7 +400,7 @@ where
|
|||||||
AO: NodeAddOns<NodeAdapter<T, CB::Components>, EthApi: FullEthApiServer + AddDevSigners>,
|
AO: NodeAddOns<NodeAdapter<T, CB::Components>, EthApi: FullEthApiServer + AddDevSigners>,
|
||||||
{
|
{
|
||||||
/// Returns a reference to the node builder's config.
|
/// 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
|
&self.builder.config
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -520,7 +525,7 @@ pub struct BuilderContext<Node: FullNodeTypes> {
|
|||||||
/// The executor of the node.
|
/// The executor of the node.
|
||||||
pub(crate) executor: TaskExecutor,
|
pub(crate) executor: TaskExecutor,
|
||||||
/// Config container
|
/// Config container
|
||||||
pub(crate) config_container: WithConfigs,
|
pub(crate) config_container: WithConfigs<<Node::Types as NodeTypes>::ChainSpec>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Node: FullNodeTypes> BuilderContext<Node> {
|
impl<Node: FullNodeTypes> BuilderContext<Node> {
|
||||||
@ -529,7 +534,7 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
|
|||||||
head: Head,
|
head: Head,
|
||||||
provider: Node::Provider,
|
provider: Node::Provider,
|
||||||
executor: TaskExecutor,
|
executor: TaskExecutor,
|
||||||
config_container: WithConfigs,
|
config_container: WithConfigs<<Node::Types as NodeTypes>::ChainSpec>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { head, provider, executor, config_container }
|
Self { head, provider, executor, config_container }
|
||||||
}
|
}
|
||||||
@ -545,7 +550,7 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the config of the 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
|
&self.config_container.config
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -586,13 +591,6 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
|
|||||||
self.config().builder.clone()
|
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.
|
/// Convenience function to start the network.
|
||||||
///
|
///
|
||||||
/// Spawns the configured network and associated tasks and returns the [`NetworkHandle`]
|
/// Spawns the configured network and associated tasks and returns the [`NetworkHandle`]
|
||||||
@ -634,6 +632,31 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
|
|||||||
handle
|
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.
|
/// Returns the default network config for the node.
|
||||||
pub fn network_config(&self) -> eyre::Result<NetworkConfig<Node::Provider>> {
|
pub fn network_config(&self) -> eyre::Result<NetworkConfig<Node::Provider>> {
|
||||||
let network_builder = self.network_config_builder();
|
let network_builder = self.network_config_builder();
|
||||||
@ -658,22 +681,6 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
|
|||||||
|
|
||||||
Ok(builder)
|
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> {
|
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_exex::ExExContext;
|
||||||
use reth_node_api::{
|
use reth_node_api::{
|
||||||
FullNodeComponents, FullNodeTypes, NodeAddOns, NodeTypesWithDB, NodeTypesWithEngine,
|
FullNodeComponents, FullNodeTypes, NodeAddOns, NodeTypes, NodeTypesWithDB, NodeTypesWithEngine,
|
||||||
};
|
};
|
||||||
use reth_node_core::{
|
use reth_node_core::{
|
||||||
node_config::NodeConfig,
|
node_config::NodeConfig,
|
||||||
@ -29,14 +29,17 @@ use crate::{
|
|||||||
/// A node builder that also has the configured types.
|
/// A node builder that also has the configured types.
|
||||||
pub struct NodeBuilderWithTypes<T: FullNodeTypes> {
|
pub struct NodeBuilderWithTypes<T: FullNodeTypes> {
|
||||||
/// All settings for how the node should be configured.
|
/// All settings for how the node should be configured.
|
||||||
config: NodeConfig,
|
config: NodeConfig<<T::Types as NodeTypes>::ChainSpec>,
|
||||||
/// The configured database for the node.
|
/// The configured database for the node.
|
||||||
adapter: NodeTypesAdapter<T>,
|
adapter: NodeTypesAdapter<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: FullNodeTypes> NodeBuilderWithTypes<T> {
|
impl<T: FullNodeTypes> NodeBuilderWithTypes<T> {
|
||||||
/// Creates a new instance of the node builder with the given configuration and types.
|
/// 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) }
|
Self { config, adapter: NodeTypesAdapter::new(database) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +152,7 @@ pub struct NodeBuilderWithComponents<
|
|||||||
AO: NodeAddOns<NodeAdapter<T, CB::Components>>,
|
AO: NodeAddOns<NodeAdapter<T, CB::Components>>,
|
||||||
> {
|
> {
|
||||||
/// All settings for how the node should be configured.
|
/// 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
|
/// Adapter for the underlying node types and database
|
||||||
pub adapter: NodeTypesAdapter<T>,
|
pub adapter: NodeTypesAdapter<T>,
|
||||||
/// container for type specific components
|
/// container for type specific components
|
||||||
|
|||||||
@ -10,7 +10,7 @@ use reth_beacon_consensus::EthBeaconConsensus;
|
|||||||
use reth_blockchain_tree::{
|
use reth_blockchain_tree::{
|
||||||
BlockchainTree, BlockchainTreeConfig, ShareableBlockchainTree, TreeExternals,
|
BlockchainTree, BlockchainTreeConfig, ShareableBlockchainTree, TreeExternals,
|
||||||
};
|
};
|
||||||
use reth_chainspec::{Chain, ChainSpec};
|
use reth_chainspec::{Chain, ChainSpec, EthChainSpec, EthereumHardforks};
|
||||||
use reth_config::{config::EtlConfig, PruneConfig};
|
use reth_config::{config::EtlConfig, PruneConfig};
|
||||||
use reth_consensus::Consensus;
|
use reth_consensus::Consensus;
|
||||||
use reth_db_api::database::Database;
|
use reth_db_api::database::Database;
|
||||||
@ -110,10 +110,10 @@ impl LaunchContext {
|
|||||||
/// `config`.
|
/// `config`.
|
||||||
///
|
///
|
||||||
/// Attaches both the `NodeConfig` and the loaded `reth.toml` config to the launch context.
|
/// 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,
|
self,
|
||||||
config: NodeConfig,
|
config: NodeConfig<ChainSpec>,
|
||||||
) -> eyre::Result<LaunchContextWith<WithConfigs>> {
|
) -> eyre::Result<LaunchContextWith<WithConfigs<ChainSpec>>> {
|
||||||
let toml_config = self.load_toml_config(&config)?;
|
let toml_config = self.load_toml_config(&config)?;
|
||||||
Ok(self.with(WithConfigs { config, toml_config }))
|
Ok(self.with(WithConfigs { config, toml_config }))
|
||||||
}
|
}
|
||||||
@ -122,7 +122,10 @@ impl LaunchContext {
|
|||||||
/// `config`.
|
/// `config`.
|
||||||
///
|
///
|
||||||
/// This is async because the trusted peers may have to be resolved.
|
/// 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 config_path = config.config.clone().unwrap_or_else(|| self.data_dir.config());
|
||||||
|
|
||||||
let mut toml_config = reth_config::Config::from_path(&config_path)
|
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.
|
/// 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,
|
reth_config: &mut reth_config::Config,
|
||||||
config: &NodeConfig,
|
config: &NodeConfig<ChainSpec>,
|
||||||
config_path: impl AsRef<std::path::Path>,
|
config_path: impl AsRef<std::path::Path>,
|
||||||
) -> eyre::Result<()> {
|
) -> eyre::Result<()> {
|
||||||
if reth_config.prune.is_none() {
|
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.
|
/// Resolves the trusted peers and adds them to the toml config.
|
||||||
pub async fn with_resolved_peers(mut self) -> eyre::Result<Self> {
|
pub async fn with_resolved_peers(mut self) -> eyre::Result<Self> {
|
||||||
if !self.attachment.config.network.trusted_peers.is_empty() {
|
if !self.attachment.config.network.trusted_peers.is_empty() {
|
||||||
@ -279,7 +282,7 @@ impl<L, R> LaunchContextWith<Attached<L, R>> {
|
|||||||
&mut self.attachment.right
|
&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
|
/// Adjust certain settings in the config to make sure they are set correctly
|
||||||
///
|
///
|
||||||
/// This includes:
|
/// This includes:
|
||||||
@ -306,17 +309,17 @@ impl<R> LaunchContextWith<Attached<WithConfigs, R>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the container for all config types
|
/// Returns the container for all config types
|
||||||
pub const fn configs(&self) -> &WithConfigs {
|
pub const fn configs(&self) -> &WithConfigs<ChainSpec> {
|
||||||
self.attachment.left()
|
self.attachment.left()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the attached [`NodeConfig`].
|
/// Returns the attached [`NodeConfig`].
|
||||||
pub const fn node_config(&self) -> &NodeConfig {
|
pub const fn node_config(&self) -> &NodeConfig<ChainSpec> {
|
||||||
&self.left().config
|
&self.left().config
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the attached [`NodeConfig`].
|
/// 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
|
&mut self.left_mut().config
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,7 +345,7 @@ impl<R> LaunchContextWith<Attached<WithConfigs, R>> {
|
|||||||
|
|
||||||
/// Returns the chain identifier of the node.
|
/// Returns the chain identifier of the node.
|
||||||
pub fn chain_id(&self) -> Chain {
|
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
|
/// 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`]
|
/// Returns an initialized [`PrunerBuilder`] based on the configured [`PruneConfig`]
|
||||||
pub fn pruner_builder(&self) -> PrunerBuilder {
|
pub fn pruner_builder(&self) -> PrunerBuilder {
|
||||||
PrunerBuilder::new(self.prune_config().unwrap_or_default())
|
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)
|
.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
|
where
|
||||||
DB: Database + Clone + 'static,
|
DB: Database + Clone + 'static,
|
||||||
|
ChainSpec: EthChainSpec + EthereumHardforks,
|
||||||
{
|
{
|
||||||
/// Returns the [`ProviderFactory`] for the attached storage after executing a consistent check
|
/// 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
|
/// 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.
|
/// Creates a new [`ProviderFactory`] and attaches it to the launch context.
|
||||||
pub async fn with_provider_factory<N: NodeTypesWithDB<DB = DB, ChainSpec = ChainSpec>>(
|
pub async fn with_provider_factory<N: NodeTypesWithDB<DB = DB, ChainSpec = ChainSpec>>(
|
||||||
self,
|
self,
|
||||||
) -> eyre::Result<LaunchContextWith<Attached<WithConfigs, ProviderFactory<N>>>> {
|
) -> eyre::Result<LaunchContextWith<Attached<WithConfigs<ChainSpec>, ProviderFactory<N>>>> {
|
||||||
let factory = self.create_provider_factory().await?;
|
let factory = self.create_provider_factory().await?;
|
||||||
let ctx = LaunchContextWith {
|
let ctx = LaunchContextWith {
|
||||||
inner: self.inner,
|
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
|
where
|
||||||
T: NodeTypesWithDB<ChainSpec = ChainSpec>,
|
T: NodeTypesWithDB<ChainSpec = ChainSpec>,
|
||||||
{
|
{
|
||||||
@ -548,7 +552,7 @@ where
|
|||||||
/// prometheus.
|
/// prometheus.
|
||||||
pub fn with_metrics_task(
|
pub fn with_metrics_task(
|
||||||
self,
|
self,
|
||||||
) -> LaunchContextWith<Attached<WithConfigs, WithMeteredProvider<T>>> {
|
) -> LaunchContextWith<Attached<WithConfigs<T::ChainSpec>, WithMeteredProvider<T>>> {
|
||||||
let (metrics_sender, metrics_receiver) = unbounded_channel();
|
let (metrics_sender, metrics_receiver) = unbounded_channel();
|
||||||
|
|
||||||
let with_metrics =
|
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
|
where
|
||||||
N: NodeTypesWithDB,
|
N: NodeTypesWithDB,
|
||||||
{
|
{
|
||||||
@ -580,12 +584,13 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a `BlockchainProvider` and attaches it to the launch context.
|
/// Creates a `BlockchainProvider` and attaches it to the launch context.
|
||||||
|
#[allow(clippy::complexity)]
|
||||||
pub fn with_blockchain_db<T, F>(
|
pub fn with_blockchain_db<T, F>(
|
||||||
self,
|
self,
|
||||||
create_blockchain_provider: F,
|
create_blockchain_provider: F,
|
||||||
tree_config: BlockchainTreeConfig,
|
tree_config: BlockchainTreeConfig,
|
||||||
canon_state_notification_sender: CanonStateNotificationSender,
|
canon_state_notification_sender: CanonStateNotificationSender,
|
||||||
) -> eyre::Result<LaunchContextWith<Attached<WithConfigs, WithMeteredProviders<T>>>>
|
) -> eyre::Result<LaunchContextWith<Attached<WithConfigs<N::ChainSpec>, WithMeteredProviders<T>>>>
|
||||||
where
|
where
|
||||||
T: FullNodeTypes<Types = N>,
|
T: FullNodeTypes<Types = N>,
|
||||||
F: FnOnce(ProviderFactory<N>) -> eyre::Result<T::Provider>,
|
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
|
where
|
||||||
T: FullNodeTypes<Types: NodeTypesWithDB<ChainSpec = ChainSpec>, Provider: WithTree>,
|
T: FullNodeTypes<Types: NodeTypesWithDB<ChainSpec = ChainSpec>, Provider: WithTree>,
|
||||||
{
|
{
|
||||||
@ -661,7 +669,11 @@ where
|
|||||||
on_component_initialized: Box<
|
on_component_initialized: Box<
|
||||||
dyn OnComponentInitializedHook<NodeAdapter<T, CB::Components>>,
|
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
|
where
|
||||||
CB: NodeComponentsBuilder<T>,
|
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
|
where
|
||||||
T: FullNodeTypes<Provider: WithTree, Types: NodeTypes<ChainSpec = ChainSpec>>,
|
T: FullNodeTypes<Provider: WithTree, Types: NodeTypes<ChainSpec = ChainSpec>>,
|
||||||
CB: NodeComponentsBuilder<T>,
|
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
|
where
|
||||||
T: FullNodeTypes<
|
T: FullNodeTypes<
|
||||||
Provider: WithTree + StateProviderFactory + ChainSpecProvider<ChainSpec = ChainSpec>,
|
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
|
/// Helper container type to bundle the initial [`NodeConfig`] and the loaded settings from the
|
||||||
/// reth.toml config
|
/// reth.toml config
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct WithConfigs {
|
pub struct WithConfigs<ChainSpec> {
|
||||||
/// The configured, usually derived from the CLI.
|
/// The configured, usually derived from the CLI.
|
||||||
pub config: NodeConfig,
|
pub config: NodeConfig<ChainSpec>,
|
||||||
/// The loaded reth.toml config.
|
/// The loaded reth.toml config.
|
||||||
pub toml_config: reth_config::Config,
|
pub toml_config: reth_config::Config,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,6 +42,7 @@ use tokio::sync::{mpsc::unbounded_channel, oneshot};
|
|||||||
use tokio_stream::wrappers::UnboundedReceiverStream;
|
use tokio_stream::wrappers::UnboundedReceiverStream;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
common::{Attached, LaunchContextWith, WithConfigs},
|
||||||
hooks::NodeHooks,
|
hooks::NodeHooks,
|
||||||
rpc::{launch_rpc_servers, EthApiBuilderProvider},
|
rpc::{launch_rpc_servers, EthApiBuilderProvider},
|
||||||
setup::build_networked_pipeline,
|
setup::build_networked_pipeline,
|
||||||
@ -132,7 +133,7 @@ where
|
|||||||
debug!(target: "reth::cli", chain=%this.chain_id(), genesis=?this.genesis_hash(), "Initializing genesis");
|
debug!(target: "reth::cli", chain=%this.chain_id(), genesis=?this.genesis_hash(), "Initializing genesis");
|
||||||
})
|
})
|
||||||
.with_genesis()?
|
.with_genesis()?
|
||||||
.inspect(|this| {
|
.inspect(|this: &LaunchContextWith<Attached<WithConfigs<ChainSpec>, _>>| {
|
||||||
info!(target: "reth::cli", "\n{}", this.chain_spec().display_hardforks());
|
info!(target: "reth::cli", "\n{}", this.chain_spec().display_hardforks());
|
||||||
})
|
})
|
||||||
.with_metrics_task()
|
.with_metrics_task()
|
||||||
|
|||||||
@ -4,7 +4,7 @@ use std::{fmt, fmt::Debug};
|
|||||||
|
|
||||||
use futures::future;
|
use futures::future;
|
||||||
use reth_exex::{ExExContext, ExExHandle, ExExManager, ExExManagerHandle};
|
use reth_exex::{ExExContext, ExExHandle, ExExManager, ExExManagerHandle};
|
||||||
use reth_node_api::FullNodeComponents;
|
use reth_node_api::{FullNodeComponents, NodeTypes};
|
||||||
use reth_primitives::Head;
|
use reth_primitives::Head;
|
||||||
use reth_provider::CanonStateSubscriptions;
|
use reth_provider::CanonStateSubscriptions;
|
||||||
use reth_tracing::tracing::{debug, info};
|
use reth_tracing::tracing::{debug, info};
|
||||||
@ -17,7 +17,7 @@ pub struct ExExLauncher<Node: FullNodeComponents> {
|
|||||||
head: Head,
|
head: Head,
|
||||||
extensions: Vec<(String, Box<dyn BoxedLaunchExEx<Node>>)>,
|
extensions: Vec<(String, Box<dyn BoxedLaunchExEx<Node>>)>,
|
||||||
components: Node,
|
components: Node,
|
||||||
config_container: WithConfigs,
|
config_container: WithConfigs<<Node::Types as NodeTypes>::ChainSpec>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Node: FullNodeComponents + Clone> ExExLauncher<Node> {
|
impl<Node: FullNodeComponents + Clone> ExExLauncher<Node> {
|
||||||
@ -26,7 +26,7 @@ impl<Node: FullNodeComponents + Clone> ExExLauncher<Node> {
|
|||||||
head: Head,
|
head: Head,
|
||||||
components: Node,
|
components: Node,
|
||||||
extensions: Vec<(String, Box<dyn BoxedLaunchExEx<Node>>)>,
|
extensions: Vec<(String, Box<dyn BoxedLaunchExEx<Node>>)>,
|
||||||
config_container: WithConfigs,
|
config_container: WithConfigs<<Node::Types as NodeTypes>::ChainSpec>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { head, extensions, components, config_container }
|
Self { head, extensions, components, config_container }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ mod exex;
|
|||||||
pub(crate) mod engine;
|
pub(crate) mod engine;
|
||||||
|
|
||||||
pub use common::LaunchContext;
|
pub use common::LaunchContext;
|
||||||
|
use common::{Attached, LaunchContextWith, WithConfigs};
|
||||||
pub use exex::ExExLauncher;
|
pub use exex::ExExLauncher;
|
||||||
|
|
||||||
use std::{future::Future, sync::Arc};
|
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");
|
debug!(target: "reth::cli", chain=%this.chain_id(), genesis=?this.genesis_hash(), "Initializing genesis");
|
||||||
})
|
})
|
||||||
.with_genesis()?
|
.with_genesis()?
|
||||||
.inspect(|this| {
|
.inspect(|this: &LaunchContextWith<Attached<WithConfigs<ChainSpec>, _>>| {
|
||||||
info!(target: "reth::cli", "\n{}", this.chain_spec().display_hardforks());
|
info!(target: "reth::cli", "\n{}", this.chain_spec().display_hardforks());
|
||||||
})
|
})
|
||||||
.with_metrics_task()
|
.with_metrics_task()
|
||||||
|
|||||||
@ -110,7 +110,7 @@ pub struct FullNode<Node: FullNodeComponents, AddOns: NodeAddOns<Node>> {
|
|||||||
/// The configured rpc namespaces
|
/// The configured rpc namespaces
|
||||||
pub rpc_registry: RpcRegistry<Node, AddOns::EthApi>,
|
pub rpc_registry: RpcRegistry<Node, AddOns::EthApi>,
|
||||||
/// The initial node config.
|
/// The initial node config.
|
||||||
pub config: NodeConfig,
|
pub config: NodeConfig<<Node::Types as NodeTypes>::ChainSpec>,
|
||||||
/// The data dir of the node.
|
/// The data dir of the node.
|
||||||
pub data_dir: ChainPath<DataDirPath>,
|
pub data_dir: ChainPath<DataDirPath>,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,9 @@ use std::{
|
|||||||
|
|
||||||
use futures::TryFutureExt;
|
use futures::TryFutureExt;
|
||||||
use reth_chainspec::ChainSpec;
|
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::{
|
use reth_node_core::{
|
||||||
node_config::NodeConfig,
|
node_config::NodeConfig,
|
||||||
rpc::{
|
rpc::{
|
||||||
@ -237,7 +239,7 @@ pub struct RpcContext<'a, Node: FullNodeComponents, EthApi: EthApiTypes> {
|
|||||||
pub(crate) node: Node,
|
pub(crate) node: Node,
|
||||||
|
|
||||||
/// Gives access to the node configuration.
|
/// 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.
|
/// A Helper type the holds instances of the configured modules.
|
||||||
///
|
///
|
||||||
@ -260,7 +262,7 @@ where
|
|||||||
EthApi: EthApiTypes,
|
EthApi: EthApiTypes,
|
||||||
{
|
{
|
||||||
/// Returns the config of the 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
|
self.config
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,7 +298,7 @@ where
|
|||||||
pub async fn launch_rpc_servers<Node, Engine, EthApi>(
|
pub async fn launch_rpc_servers<Node, Engine, EthApi>(
|
||||||
node: Node,
|
node: Node,
|
||||||
engine_api: Engine,
|
engine_api: Engine,
|
||||||
config: &NodeConfig,
|
config: &NodeConfig<ChainSpec>,
|
||||||
jwt_secret: JwtSecret,
|
jwt_secret: JwtSecret,
|
||||||
add_ons: RpcAddOns<Node, EthApi>,
|
add_ons: RpcAddOns<Node, EthApi>,
|
||||||
) -> eyre::Result<(RethRpcServerHandles, RpcRegistry<Node, EthApi>)>
|
) -> eyre::Result<(RethRpcServerHandles, RpcRegistry<Node, EthApi>)>
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
use crate::args::error::ReceiptsLogError;
|
use crate::args::error::ReceiptsLogError;
|
||||||
use alloy_primitives::{Address, BlockNumber};
|
use alloy_primitives::{Address, BlockNumber};
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
use reth_chainspec::ChainSpec;
|
use reth_chainspec::EthChainSpec;
|
||||||
use reth_config::config::PruneConfig;
|
use reth_config::config::PruneConfig;
|
||||||
use reth_prune_types::{PruneMode, PruneModes, ReceiptsLogPruneConfig, MINIMUM_PRUNING_DISTANCE};
|
use reth_prune_types::{PruneMode, PruneModes, ReceiptsLogPruneConfig, MINIMUM_PRUNING_DISTANCE};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
@ -92,7 +92,7 @@ pub struct PruningArgs {
|
|||||||
|
|
||||||
impl PruningArgs {
|
impl PruningArgs {
|
||||||
/// Returns pruning configuration.
|
/// 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.
|
// Initialise with a default prune configuration.
|
||||||
let mut config = PruneConfig::default();
|
let mut config = PruneConfig::default();
|
||||||
|
|
||||||
@ -106,16 +106,14 @@ impl PruningArgs {
|
|||||||
// prune all receipts if chain doesn't have deposit contract specified in chain
|
// prune all receipts if chain doesn't have deposit contract specified in chain
|
||||||
// spec
|
// spec
|
||||||
receipts: chain_spec
|
receipts: chain_spec
|
||||||
.deposit_contract
|
.deposit_contract()
|
||||||
.as_ref()
|
|
||||||
.map(|contract| PruneMode::Before(contract.block))
|
.map(|contract| PruneMode::Before(contract.block))
|
||||||
.or(Some(PruneMode::Distance(MINIMUM_PRUNING_DISTANCE))),
|
.or(Some(PruneMode::Distance(MINIMUM_PRUNING_DISTANCE))),
|
||||||
account_history: Some(PruneMode::Distance(MINIMUM_PRUNING_DISTANCE)),
|
account_history: Some(PruneMode::Distance(MINIMUM_PRUNING_DISTANCE)),
|
||||||
storage_history: Some(PruneMode::Distance(MINIMUM_PRUNING_DISTANCE)),
|
storage_history: Some(PruneMode::Distance(MINIMUM_PRUNING_DISTANCE)),
|
||||||
receipts_log_filter: ReceiptsLogPruneConfig(
|
receipts_log_filter: ReceiptsLogPruneConfig(
|
||||||
chain_spec
|
chain_spec
|
||||||
.deposit_contract
|
.deposit_contract()
|
||||||
.as_ref()
|
|
||||||
.map(|contract| (contract.address, PruneMode::Before(contract.block)))
|
.map(|contract| (contract.address, PruneMode::Before(contract.block)))
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect(),
|
.collect(),
|
||||||
|
|||||||
@ -9,7 +9,7 @@ use crate::{
|
|||||||
utils::get_single_header,
|
utils::get_single_header,
|
||||||
};
|
};
|
||||||
use eyre::eyre;
|
use eyre::eyre;
|
||||||
use reth_chainspec::{ChainSpec, MAINNET};
|
use reth_chainspec::{ChainSpec, EthChainSpec, MAINNET};
|
||||||
use reth_config::config::PruneConfig;
|
use reth_config::config::PruneConfig;
|
||||||
use reth_network_p2p::headers::client::HeadersClient;
|
use reth_network_p2p::headers::client::HeadersClient;
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
@ -70,8 +70,8 @@ use tracing::*;
|
|||||||
/// let builder = builder.with_rpc(rpc);
|
/// let builder = builder.with_rpc(rpc);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug)]
|
||||||
pub struct NodeConfig {
|
pub struct NodeConfig<ChainSpec> {
|
||||||
/// All data directory related arguments
|
/// All data directory related arguments
|
||||||
pub datadir: DatadirArgs,
|
pub datadir: DatadirArgs,
|
||||||
|
|
||||||
@ -129,14 +129,16 @@ pub struct NodeConfig {
|
|||||||
pub pruning: PruningArgs,
|
pub pruning: PruningArgs,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NodeConfig {
|
impl NodeConfig<ChainSpec> {
|
||||||
/// Creates a testing [`NodeConfig`], causing the database to be launched ephemerally.
|
/// Creates a testing [`NodeConfig`], causing the database to be launched ephemerally.
|
||||||
pub fn test() -> Self {
|
pub fn test() -> Self {
|
||||||
Self::default()
|
Self::default()
|
||||||
// set all ports to zero by default for test instances
|
// set all ports to zero by default for test instances
|
||||||
.with_unused_ports()
|
.with_unused_ports()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<ChainSpec> NodeConfig<ChainSpec> {
|
||||||
/// Sets --dev mode for the node.
|
/// Sets --dev mode for the node.
|
||||||
///
|
///
|
||||||
/// In addition to setting the `--dev` flag, this also:
|
/// In addition to setting the `--dev` flag, this also:
|
||||||
@ -235,7 +237,10 @@ impl NodeConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns pruning configuration.
|
/// 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)
|
self.pruning.prune_config(&self.chain)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,8 +370,11 @@ impl NodeConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Resolve the final datadir path.
|
/// Resolve the final datadir path.
|
||||||
pub fn datadir(&self) -> ChainPath<DataDirPath> {
|
pub fn datadir(&self) -> ChainPath<DataDirPath>
|
||||||
self.datadir.clone().resolve_datadir(self.chain.chain)
|
where
|
||||||
|
ChainSpec: EthChainSpec,
|
||||||
|
{
|
||||||
|
self.datadir.clone().resolve_datadir(self.chain.chain())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load an application configuration from a specified path.
|
/// 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 {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
config: None,
|
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).
|
/// [`NodeCommand`](reth_cli_commands::node::NodeCommand).
|
||||||
pub fn run<L, Fut>(mut self, launcher: L) -> eyre::Result<()>
|
pub fn run<L, Fut>(mut self, launcher: L) -> eyre::Result<()>
|
||||||
where
|
where
|
||||||
L: FnOnce(WithLaunchContext<NodeBuilder<Arc<DatabaseEnv>>>, Ext) -> Fut,
|
L: FnOnce(WithLaunchContext<NodeBuilder<Arc<DatabaseEnv>, ChainSpec>>, Ext) -> Fut,
|
||||||
Fut: Future<Output = eyre::Result<()>>,
|
Fut: Future<Output = eyre::Result<()>>,
|
||||||
{
|
{
|
||||||
// add network name to logs dir
|
// add network name to logs dir
|
||||||
|
|||||||
Reference in New Issue
Block a user