mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Simplify node components (#4922)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
args::GasPriceOracleArgs,
|
args::GasPriceOracleArgs,
|
||||||
cli::{config::RethRpcConfig, ext::RethNodeCommandConfig},
|
cli::{components::RethRpcComponents, config::RethRpcConfig, ext::RethNodeCommandConfig},
|
||||||
};
|
};
|
||||||
use clap::{
|
use clap::{
|
||||||
builder::{PossibleValue, RangedU64ValueParser, TypedValueParser},
|
builder::{PossibleValue, RangedU64ValueParser, TypedValueParser},
|
||||||
@ -193,19 +193,19 @@ impl RpcServerArgs {
|
|||||||
let module_config = self.transport_rpc_module_config();
|
let module_config = self.transport_rpc_module_config();
|
||||||
debug!(target: "reth::cli", http=?module_config.http(), ws=?module_config.ws(), "Using RPC module config");
|
debug!(target: "reth::cli", http=?module_config.http(), ws=?module_config.ws(), "Using RPC module config");
|
||||||
|
|
||||||
let (mut rpc_modules, auth_module, mut registry) = RpcModuleBuilder::default()
|
let (mut modules, auth_module, mut registry) = RpcModuleBuilder::default()
|
||||||
.with_provider(components.provider())
|
.with_provider(components.provider())
|
||||||
.with_pool(components.pool())
|
.with_pool(components.pool())
|
||||||
.with_network(components.network())
|
.with_network(components.network())
|
||||||
.with_events(components.events())
|
.with_events(components.events())
|
||||||
.with_executor(components.task_executor())
|
.with_executor(components.task_executor())
|
||||||
.build_with_auth_server(module_config, engine_api);
|
.build_with_auth_server(module_config, engine_api);
|
||||||
|
let node_modules = RethRpcComponents { registry: &mut registry, modules: &mut modules };
|
||||||
// apply configured customization
|
// apply configured customization
|
||||||
conf.extend_rpc_modules(self, components, &mut registry, &mut rpc_modules)?;
|
conf.extend_rpc_modules(self, components, node_modules)?;
|
||||||
|
|
||||||
let server_config = self.rpc_server_config();
|
let server_config = self.rpc_server_config();
|
||||||
let launch_rpc = rpc_modules.start_server(server_config).map_ok(|handle| {
|
let launch_rpc = modules.start_server(server_config).map_ok(|handle| {
|
||||||
if let Some(url) = handle.ipc_endpoint() {
|
if let Some(url) = handle.ipc_endpoint() {
|
||||||
info!(target: "reth::cli", url=%url, "RPC IPC server started");
|
info!(target: "reth::cli", url=%url, "RPC IPC server started");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ use reth_provider::{
|
|||||||
AccountReader, BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider, ChangeSetReader,
|
AccountReader, BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider, ChangeSetReader,
|
||||||
EvmEnvProvider, StateProviderFactory,
|
EvmEnvProvider, StateProviderFactory,
|
||||||
};
|
};
|
||||||
|
use reth_rpc_builder::{RethModuleRegistry, TransportRpcModules};
|
||||||
use reth_tasks::TaskSpawner;
|
use reth_tasks::TaskSpawner;
|
||||||
use reth_transaction_pool::TransactionPool;
|
use reth_transaction_pool::TransactionPool;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -71,6 +72,31 @@ pub trait RethNodeComponents {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Helper container to encapsulate [RethModuleRegistry] and [TransportRpcModules].
|
||||||
|
///
|
||||||
|
/// This can be used to access installed modules, or create commonly used handlers like
|
||||||
|
/// [reth_rpc::EthApi], and ultimately merge additional rpc handler into the configured transport
|
||||||
|
/// modules [TransportRpcModules].
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
|
pub struct RethRpcComponents<'a, Reth: RethNodeComponents> {
|
||||||
|
/// A Helper type the holds instances of the configured modules.
|
||||||
|
///
|
||||||
|
/// This provides easy access to rpc handlers, such as [RethModuleRegistry::eth_api].
|
||||||
|
pub registry: &'a mut RethModuleRegistry<
|
||||||
|
Reth::Provider,
|
||||||
|
Reth::Pool,
|
||||||
|
Reth::Network,
|
||||||
|
Reth::Tasks,
|
||||||
|
Reth::Events,
|
||||||
|
>,
|
||||||
|
/// Holds installed modules per transport type.
|
||||||
|
///
|
||||||
|
/// This can be used to merge additional modules into the configured transports (http, ipc,
|
||||||
|
/// ws). See [TransportRpcModules::merge_configured]
|
||||||
|
pub modules: &'a mut TransportRpcModules,
|
||||||
|
}
|
||||||
|
|
||||||
/// A Generic implementation of the RethNodeComponents trait.
|
/// A Generic implementation of the RethNodeComponents trait.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
|
|||||||
@ -1,13 +1,12 @@
|
|||||||
//! Support for integrating customizations into the CLI.
|
//! Support for integrating customizations into the CLI.
|
||||||
|
|
||||||
use crate::cli::{
|
use crate::cli::{
|
||||||
components::RethNodeComponents,
|
components::{RethNodeComponents, RethRpcComponents},
|
||||||
config::{PayloadBuilderConfig, RethRpcConfig},
|
config::{PayloadBuilderConfig, RethRpcConfig},
|
||||||
};
|
};
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig};
|
use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig};
|
||||||
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
|
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
|
||||||
use reth_rpc_builder::{RethModuleRegistry, TransportRpcModules};
|
|
||||||
use reth_tasks::TaskSpawner;
|
use reth_tasks::TaskSpawner;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
@ -49,21 +48,13 @@ pub trait RethNodeCommandConfig: fmt::Debug {
|
|||||||
|
|
||||||
/// Allows for registering additional RPC modules for the transports.
|
/// Allows for registering additional RPC modules for the transports.
|
||||||
///
|
///
|
||||||
/// This is expected to call the merge functions of [TransportRpcModules], for example
|
/// This is expected to call the merge functions of [reth_rpc_builder::TransportRpcModules], for
|
||||||
/// [TransportRpcModules::merge_configured]
|
/// example [reth_rpc_builder::TransportRpcModules::merge_configured]
|
||||||
#[allow(clippy::type_complexity)]
|
|
||||||
fn extend_rpc_modules<Conf, Reth>(
|
fn extend_rpc_modules<Conf, Reth>(
|
||||||
&mut self,
|
&mut self,
|
||||||
config: &Conf,
|
config: &Conf,
|
||||||
components: &Reth,
|
components: &Reth,
|
||||||
registry: &mut RethModuleRegistry<
|
rpc_components: RethRpcComponents<'_, Reth>,
|
||||||
Reth::Provider,
|
|
||||||
Reth::Pool,
|
|
||||||
Reth::Network,
|
|
||||||
Reth::Tasks,
|
|
||||||
Reth::Events,
|
|
||||||
>,
|
|
||||||
modules: &mut TransportRpcModules,
|
|
||||||
) -> eyre::Result<()>
|
) -> eyre::Result<()>
|
||||||
where
|
where
|
||||||
Conf: RethRpcConfig,
|
Conf: RethRpcConfig,
|
||||||
@ -71,8 +62,7 @@ pub trait RethNodeCommandConfig: fmt::Debug {
|
|||||||
{
|
{
|
||||||
let _ = config;
|
let _ = config;
|
||||||
let _ = components;
|
let _ = components;
|
||||||
let _ = registry;
|
let _ = rpc_components;
|
||||||
let _ = modules;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,21 +186,14 @@ impl<T: RethNodeCommandConfig> RethNodeCommandConfig for NoArgs<T> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
config: &Conf,
|
config: &Conf,
|
||||||
components: &Reth,
|
components: &Reth,
|
||||||
registry: &mut RethModuleRegistry<
|
rpc_components: RethRpcComponents<'_, Reth>,
|
||||||
Reth::Provider,
|
|
||||||
Reth::Pool,
|
|
||||||
Reth::Network,
|
|
||||||
Reth::Tasks,
|
|
||||||
Reth::Events,
|
|
||||||
>,
|
|
||||||
modules: &mut TransportRpcModules,
|
|
||||||
) -> eyre::Result<()>
|
) -> eyre::Result<()>
|
||||||
where
|
where
|
||||||
Conf: RethRpcConfig,
|
Conf: RethRpcConfig,
|
||||||
Reth: RethNodeComponents,
|
Reth: RethNodeComponents,
|
||||||
{
|
{
|
||||||
if let Some(conf) = self.inner_mut() {
|
if let Some(conf) = self.inner_mut() {
|
||||||
conf.extend_rpc_modules(config, components, registry, modules)
|
conf.extend_rpc_modules(config, components, rpc_components)
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,14 +13,11 @@
|
|||||||
//! ```
|
//! ```
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
|
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
|
||||||
use reth::{
|
use reth::cli::{
|
||||||
cli::{
|
components::{RethNodeComponents, RethRpcComponents},
|
||||||
components::RethNodeComponents,
|
config::RethRpcConfig,
|
||||||
config::RethRpcConfig,
|
ext::{RethCliExt, RethNodeCommandConfig},
|
||||||
ext::{RethCliExt, RethNodeCommandConfig},
|
Cli,
|
||||||
Cli,
|
|
||||||
},
|
|
||||||
rpc::builder::{RethModuleRegistry, TransportRpcModules},
|
|
||||||
};
|
};
|
||||||
use reth_transaction_pool::TransactionPool;
|
use reth_transaction_pool::TransactionPool;
|
||||||
|
|
||||||
@ -50,14 +47,7 @@ impl RethNodeCommandConfig for RethCliTxpoolExt {
|
|||||||
&mut self,
|
&mut self,
|
||||||
_config: &Conf,
|
_config: &Conf,
|
||||||
_components: &Reth,
|
_components: &Reth,
|
||||||
registry: &mut RethModuleRegistry<
|
rpc_components: RethRpcComponents<'_, Reth>,
|
||||||
Reth::Provider,
|
|
||||||
Reth::Pool,
|
|
||||||
Reth::Network,
|
|
||||||
Reth::Tasks,
|
|
||||||
Reth::Events,
|
|
||||||
>,
|
|
||||||
modules: &mut TransportRpcModules,
|
|
||||||
) -> eyre::Result<()>
|
) -> eyre::Result<()>
|
||||||
where
|
where
|
||||||
Conf: RethRpcConfig,
|
Conf: RethRpcConfig,
|
||||||
@ -68,11 +58,11 @@ impl RethNodeCommandConfig for RethCliTxpoolExt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// here we get the configured pool type from the CLI.
|
// here we get the configured pool type from the CLI.
|
||||||
let pool = registry.pool().clone();
|
let pool = rpc_components.registry.pool().clone();
|
||||||
let ext = TxpoolExt { pool };
|
let ext = TxpoolExt { pool };
|
||||||
|
|
||||||
// now we merge our extension namespace into all configured transports
|
// now we merge our extension namespace into all configured transports
|
||||||
modules.merge_configured(ext.into_rpc())?;
|
rpc_components.modules.merge_configured(ext.into_rpc())?;
|
||||||
|
|
||||||
println!("txpool extension enabled");
|
println!("txpool extension enabled");
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user