diff --git a/crates/node/builder/src/builder/states.rs b/crates/node/builder/src/builder/states.rs index 975590c5fe..b77588df49 100644 --- a/crates/node/builder/src/builder/states.rs +++ b/crates/node/builder/src/builder/states.rs @@ -157,7 +157,7 @@ impl> NodeBuilderWithComponents(mut self, hook: F) -> Self where - F: Fn(NodeAdapter) -> eyre::Result<()> + Send + 'static, + F: FnOnce(NodeAdapter) -> eyre::Result<()> + Send + 'static, { self.add_ons.hooks.set_on_component_initialized(hook); self @@ -166,7 +166,7 @@ impl> NodeBuilderWithComponents(mut self, hook: F) -> Self where - F: Fn(FullNode>) -> eyre::Result<()> + Send + 'static, + F: FnOnce(FullNode>) -> eyre::Result<()> + Send + 'static, { self.add_ons.hooks.set_on_node_started(hook); self @@ -175,7 +175,7 @@ impl> NodeBuilderWithComponents(mut self, hook: F) -> Self where - F: Fn( + F: FnOnce( RpcContext<'_, NodeAdapter>, RethRpcServerHandles, ) -> eyre::Result<()> @@ -189,7 +189,9 @@ impl> NodeBuilderWithComponents(mut self, hook: F) -> Self where - F: Fn(RpcContext<'_, NodeAdapter>) -> eyre::Result<()> + Send + 'static, + F: FnOnce(RpcContext<'_, NodeAdapter>) -> eyre::Result<()> + + Send + + 'static, { self.add_ons.rpc.set_extend_rpc_modules(hook); self @@ -202,7 +204,7 @@ impl> NodeBuilderWithComponents(mut self, exex_id: impl Into, exex: F) -> Self where - F: Fn(ExExContext>) -> R + Send + 'static, + F: FnOnce(ExExContext>) -> R + Send + 'static, R: Future> + Send, E: Future> + Send, { diff --git a/crates/node/builder/src/hooks.rs b/crates/node/builder/src/hooks.rs index 9d2127f5a5..468c84e851 100644 --- a/crates/node/builder/src/hooks.rs +++ b/crates/node/builder/src/hooks.rs @@ -77,15 +77,15 @@ pub trait OnComponentInitializedHook: Send { /// Consumes the event hook and runs it. /// /// If this returns an error, the node launch will be aborted. - fn on_event(&self, node: Node) -> eyre::Result<()>; + fn on_event(self: Box, node: Node) -> eyre::Result<()>; } impl OnComponentInitializedHook for F where - F: Fn(Node) -> eyre::Result<()> + Send, + F: FnOnce(Node) -> eyre::Result<()> + Send, { - fn on_event(&self, node: Node) -> eyre::Result<()> { - self(node) + fn on_event(self: Box, node: Node) -> eyre::Result<()> { + (*self)(node) } } @@ -94,27 +94,27 @@ pub trait OnNodeStartedHook: Send { /// Consumes the event hook and runs it. /// /// If this returns an error, the node launch will be aborted. - fn on_event(&self, node: FullNode) -> eyre::Result<()>; + fn on_event(self: Box, node: FullNode) -> eyre::Result<()>; } impl OnNodeStartedHook for F where Node: FullNodeComponents, - F: Fn(FullNode) -> eyre::Result<()> + Send, + F: FnOnce(FullNode) -> eyre::Result<()> + Send, { - fn on_event(&self, node: FullNode) -> eyre::Result<()> { - self(node) + fn on_event(self: Box, node: FullNode) -> eyre::Result<()> { + (*self)(node) } } impl OnComponentInitializedHook for () { - fn on_event(&self, _node: Node) -> eyre::Result<()> { + fn on_event(self: Box, _node: Node) -> eyre::Result<()> { Ok(()) } } impl OnNodeStartedHook for () { - fn on_event(&self, _node: FullNode) -> eyre::Result<()> { + fn on_event(self: Box, _node: FullNode) -> eyre::Result<()> { Ok(()) } } diff --git a/crates/node/builder/src/launch/mod.rs b/crates/node/builder/src/launch/mod.rs index 39c549e06e..4f1f00e4e5 100644 --- a/crates/node/builder/src/launch/mod.rs +++ b/crates/node/builder/src/launch/mod.rs @@ -232,8 +232,7 @@ where async move { while let Ok(notification) = canon_state_notifications.recv().await { handle.send_async(notification.into()).await.expect( - "blockchain tree notification could not be sent to exex -manager", + "blockchain tree notification could not be sent to exex manager", ); } }, diff --git a/crates/node/builder/src/rpc.rs b/crates/node/builder/src/rpc.rs index 3efeba7f5f..a65dcfce5f 100644 --- a/crates/node/builder/src/rpc.rs +++ b/crates/node/builder/src/rpc.rs @@ -98,7 +98,7 @@ impl fmt::Debug for RpcHooks { pub trait OnRpcStarted: Send { /// The hook that is called once the rpc server is started. fn on_rpc_started( - &self, + self: Box, ctx: RpcContext<'_, Node>, handles: RethRpcServerHandles, ) -> eyre::Result<()>; @@ -106,20 +106,24 @@ pub trait OnRpcStarted: Send { impl OnRpcStarted for F where - F: Fn(RpcContext<'_, Node>, RethRpcServerHandles) -> eyre::Result<()> + Send, + F: FnOnce(RpcContext<'_, Node>, RethRpcServerHandles) -> eyre::Result<()> + Send, Node: FullNodeComponents, { fn on_rpc_started( - &self, + self: Box, ctx: RpcContext<'_, Node>, handles: RethRpcServerHandles, ) -> eyre::Result<()> { - self(ctx, handles) + (*self)(ctx, handles) } } impl OnRpcStarted for () { - fn on_rpc_started(&self, _: RpcContext<'_, Node>, _: RethRpcServerHandles) -> eyre::Result<()> { + fn on_rpc_started( + self: Box, + _: RpcContext<'_, Node>, + _: RethRpcServerHandles, + ) -> eyre::Result<()> { Ok(()) } } @@ -127,21 +131,21 @@ impl OnRpcStarted for () { /// Event hook that is called when the rpc server is started. pub trait ExtendRpcModules: Send { /// The hook that is called once the rpc server is started. - fn extend_rpc_modules(&self, ctx: RpcContext<'_, Node>) -> eyre::Result<()>; + fn extend_rpc_modules(self: Box, ctx: RpcContext<'_, Node>) -> eyre::Result<()>; } impl ExtendRpcModules for F where - F: Fn(RpcContext<'_, Node>) -> eyre::Result<()> + Send, + F: FnOnce(RpcContext<'_, Node>) -> eyre::Result<()> + Send, Node: FullNodeComponents, { - fn extend_rpc_modules(&self, ctx: RpcContext<'_, Node>) -> eyre::Result<()> { - self(ctx) + fn extend_rpc_modules(self: Box, ctx: RpcContext<'_, Node>) -> eyre::Result<()> { + (*self)(ctx) } } impl ExtendRpcModules for () { - fn extend_rpc_modules(&self, _: RpcContext<'_, Node>) -> eyre::Result<()> { + fn extend_rpc_modules(self: Box, _: RpcContext<'_, Node>) -> eyre::Result<()> { Ok(()) } }