Skip to content

Commit

Permalink
chore: some touchups
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Oct 5, 2023
1 parent 04a7242 commit e96e068
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
3 changes: 1 addition & 2 deletions bin/reth/src/args/rpc_server_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ impl RpcServerArgs {
.with_events(components.events())
.with_executor(components.task_executor())
.build_with_auth_server(module_config, engine_api);
let node_modules =
&mut RethRpcComponents::<Reth> { registry: &mut registry, modules: &mut modules };
let node_modules = RethRpcComponents { registry: &mut registry, modules: &mut modules };
// apply configured customization
conf.extend_rpc_modules(self, components, node_modules)?;

Expand Down
13 changes: 11 additions & 2 deletions bin/reth/src/cli/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,17 @@ pub trait RethNodeComponents {
}
}

/// Helper function to encapsulate [RethModuleRegistry] and [TransportRpcModules]
/// generic over [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,
Expand All @@ -85,6 +91,9 @@ pub struct RethRpcComponents<'a, Reth: RethNodeComponents> {
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,
}

Expand Down
7 changes: 3 additions & 4 deletions bin/reth/src/cli/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ pub trait RethNodeCommandConfig: fmt::Debug {
///
/// This is expected to call the merge functions of [reth_rpc_builder::TransportRpcModules], for
/// example [reth_rpc_builder::TransportRpcModules::merge_configured]
#[allow(clippy::type_complexity)]
fn extend_rpc_modules<Conf, Reth>(
&mut self,
config: &Conf,
components: &Reth,
rpc_components: &mut RethRpcComponents<'_, Reth>,
rpc_components: RethRpcComponents<'_, Reth>,
) -> eyre::Result<()>
where
Conf: RethRpcConfig,
Expand Down Expand Up @@ -187,14 +186,14 @@ impl<T: RethNodeCommandConfig> RethNodeCommandConfig for NoArgs<T> {
&mut self,
config: &Conf,
components: &Reth,
node_components: &mut RethRpcComponents<'_, Reth>,
rpc_components: RethRpcComponents<'_, Reth>,
) -> eyre::Result<()>
where
Conf: RethRpcConfig,
Reth: RethNodeComponents,
{
if let Some(conf) = self.inner_mut() {
conf.extend_rpc_modules(config, components, node_components)
conf.extend_rpc_modules(config, components, rpc_components)
} else {
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions examples/additional-rpc-namespace-in-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl RethNodeCommandConfig for RethCliTxpoolExt {
&mut self,
_config: &Conf,
_components: &Reth,
node_components: &mut RethRpcComponents<'_, Reth>,
rpc_components: RethRpcComponents<'_, Reth>,
) -> eyre::Result<()>
where
Conf: RethRpcConfig,
Expand All @@ -58,11 +58,11 @@ impl RethNodeCommandConfig for RethCliTxpoolExt {
}

// here we get the configured pool type from the CLI.
let pool = node_components.registry.pool().clone();
let pool = rpc_components.registry.pool().clone();
let ext = TxpoolExt { pool };

// now we merge our extension namespace into all configured transports
node_components.modules.merge_configured(ext.into_rpc())?;
rpc_components.modules.merge_configured(ext.into_rpc())?;

println!("txpool extension enabled");
Ok(())
Expand Down

0 comments on commit e96e068

Please sign in to comment.