From 9de9b7cb32abf299967a12c8718cc55b4a319fa5 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 24 Jul 2024 17:34:04 +0200 Subject: [PATCH] chore: relax some builder api trait bounds (#9770) --- crates/node/builder/src/builder/mod.rs | 73 ++++++++++++++------------ 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/crates/node/builder/src/builder/mod.rs b/crates/node/builder/src/builder/mod.rs index ce371f2218..cf6f9867ac 100644 --- a/crates/node/builder/src/builder/mod.rs +++ b/crates/node/builder/src/builder/mod.rs @@ -269,6 +269,20 @@ where WithLaunchContext { builder: self.builder.with_types(), task_executor: self.task_executor } } + /// Configures the types of the node and the provider type that will be used by the node. + pub fn with_types_and_provider( + self, + ) -> WithLaunchContext>> + where + T: NodeTypes, + P: FullProvider, + { + WithLaunchContext { + builder: self.builder.with_types_and_provider(), + task_executor: self.task_executor, + } + } + /// Preconfigures the node with a specific node implementation. /// /// This is a convenience method that sets the node's types and components in one call. @@ -319,18 +333,14 @@ where } } -impl WithLaunchContext>> -where - DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static, - T: NodeTypes, -{ +impl WithLaunchContext> { /// Advances the state of the node builder to the next state where all components are configured pub fn with_components( self, components_builder: CB, - ) -> WithLaunchContext, CB, ()>> + ) -> WithLaunchContext> where - CB: NodeComponentsBuilder>, + CB: NodeComponentsBuilder, { WithLaunchContext { builder: self.builder.with_components(components_builder), @@ -339,20 +349,16 @@ where } } -impl WithLaunchContext, CB, ()>> +impl WithLaunchContext> where - DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static, - T: NodeTypes, - CB: NodeComponentsBuilder>, + T: FullNodeTypes, + CB: NodeComponentsBuilder, { /// Advances the state of the node builder to the next state where all customizable /// [`NodeAddOns`] types are configured. - pub fn with_add_ons( - self, - ) -> WithLaunchContext, CB, AO>> + pub fn with_add_ons(self) -> WithLaunchContext> where - CB: NodeComponentsBuilder>, - AO: NodeAddOns, CB::Components>>, + AO: NodeAddOns>, { WithLaunchContext { builder: self.builder.with_add_ons::(), @@ -361,20 +367,17 @@ where } } -impl WithLaunchContext, CB, AO>> +impl WithLaunchContext> where - DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static, - T: NodeTypes, - CB: NodeComponentsBuilder>, - AO: NodeAddOns, CB::Components>>, + T: FullNodeTypes, + CB: NodeComponentsBuilder, + AO: NodeAddOns>, AO::EthApi: FullEthApiServer + AddDevSigners, { /// Sets the hook that is run once the node's components are initialized. pub fn on_component_initialized(self, hook: F) -> Self where - F: FnOnce(NodeAdapter, CB::Components>) -> eyre::Result<()> - + Send - + 'static, + F: FnOnce(NodeAdapter) -> eyre::Result<()> + Send + 'static, { Self { builder: self.builder.on_component_initialized(hook), @@ -385,9 +388,7 @@ where /// Sets the hook that is run once the node has started. pub fn on_node_started(self, hook: F) -> Self where - F: FnOnce( - FullNode, CB::Components>, AO>, - ) -> eyre::Result<()> + F: FnOnce(FullNode, AO>) -> eyre::Result<()> + Send + 'static, { @@ -398,7 +399,7 @@ where pub fn on_rpc_started(self, hook: F) -> Self where F: FnOnce( - RpcContext<'_, NodeAdapter, CB::Components>, AO::EthApi>, + RpcContext<'_, NodeAdapter, AO::EthApi>, RethRpcServerHandles, ) -> eyre::Result<()> + Send @@ -410,9 +411,7 @@ where /// Sets the hook that is run to configure the rpc modules. pub fn extend_rpc_modules(self, hook: F) -> Self where - F: FnOnce( - RpcContext<'_, NodeAdapter, CB::Components>, AO::EthApi>, - ) -> eyre::Result<()> + F: FnOnce(RpcContext<'_, NodeAdapter, AO::EthApi>) -> eyre::Result<()> + Send + 'static, { @@ -426,9 +425,7 @@ where /// The `ExEx` ID must be unique. pub fn install_exex(self, exex_id: impl Into, exex: F) -> Self where - F: FnOnce(ExExContext, CB::Components>>) -> R - + Send - + 'static, + F: FnOnce(ExExContext>) -> R + Send + 'static, R: Future> + Send, E: Future> + Send, { @@ -438,6 +435,14 @@ where } } + /// Launches the node with the given closure. + pub fn launch_with_fn(self, launcher: L) -> R + where + L: FnOnce(Self) -> R, + { + launcher(self) + } + /// Check that the builder can be launched /// /// This is useful when writing tests to ensure that the builder is configured correctly.