diff --git a/crates/exex/exex/src/dyn_context.rs b/crates/exex/exex/src/dyn_context.rs index 226f3a3feb9a..b48a6ebc951f 100644 --- a/crates/exex/exex/src/dyn_context.rs +++ b/crates/exex/exex/src/dyn_context.rs @@ -1,7 +1,7 @@ //! Mirrored version of [`ExExContext`](`crate::ExExContext`) //! without generic abstraction over [Node](`reth_node_api::FullNodeComponents`) -use std::{fmt::Debug, sync::Arc}; +use std::fmt::Debug; use reth_chainspec::{EthChainSpec, Head}; use reth_node_api::FullNodeComponents; @@ -55,24 +55,8 @@ where Node::Executor: Debug, { fn from(ctx: ExExContext) -> Self { - // convert `NodeConfig` with generic over chainspec into `NodeConfig` - let chain: Arc> = - Arc::new(Box::new(ctx.config.chain) as Box); - let config = NodeConfig { - chain, - datadir: ctx.config.datadir, - config: ctx.config.config, - metrics: ctx.config.metrics, - instance: ctx.config.instance, - network: ctx.config.network, - rpc: ctx.config.rpc, - txpool: ctx.config.txpool, - builder: ctx.config.builder, - debug: ctx.config.debug, - db: ctx.config.db, - dev: ctx.config.dev, - pruning: ctx.config.pruning, - }; + let config = + ctx.config.map_chainspec(|chainspec| Box::new(chainspec) as Box); let notifications = Box::new(ctx.notifications) as Box; Self { diff --git a/crates/node/core/src/node_config.rs b/crates/node/core/src/node_config.rs index a8799d80df1c..80fb5152e7bb 100644 --- a/crates/node/core/src/node_config.rs +++ b/crates/node/core/src/node_config.rs @@ -422,6 +422,29 @@ impl NodeConfig { Err(e) => Err(eyre!("Failed to load configuration: {e}")), } } + + /// Modifies the [`ChainSpec`] generic of the config using the provided closure. + pub fn map_chainspec(self, f: F) -> NodeConfig + where + F: FnOnce(Arc) -> C, + { + let chain = Arc::new(f(self.chain)); + NodeConfig { + chain, + datadir: self.datadir, + config: self.config, + metrics: self.metrics, + instance: self.instance, + network: self.network, + rpc: self.rpc, + txpool: self.txpool, + builder: self.builder, + debug: self.debug, + db: self.db, + dev: self.dev, + pruning: self.pruning, + } + } } impl Default for NodeConfig {