diff --git a/Cargo.lock b/Cargo.lock index 74d5068eee..b9051766f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9172,6 +9172,7 @@ dependencies = [ "eyre", "futures", "op-alloy-consensus", + "op-alloy-network", "op-alloy-rpc-types-engine", "op-revm", "reth-chainspec", diff --git a/crates/optimism/node/Cargo.toml b/crates/optimism/node/Cargo.toml index d7f82bedb2..718fc5358e 100644 --- a/crates/optimism/node/Cargo.toml +++ b/crates/optimism/node/Cargo.toml @@ -50,6 +50,7 @@ op-revm.workspace = true # ethereum alloy-primitives.workspace = true op-alloy-consensus.workspace = true +op-alloy-network.workspace = true op-alloy-rpc-types-engine.workspace = true alloy-rpc-types-engine.workspace = true alloy-rpc-types-eth.workspace = true diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index b95a463220..60316e3061 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -49,7 +49,7 @@ use reth_optimism_txpool::{ }; use reth_provider::{providers::ProviderFactoryBuilder, CanonStateSubscriptions, EthStorage}; use reth_rpc_api::DebugApiServer; -use reth_rpc_eth_api::ext::L2EthApiExtServer; +use reth_rpc_eth_api::{ext::L2EthApiExtServer, FullEthApiServer}; use reth_rpc_eth_types::error::FromEvmError; use reth_rpc_server_types::RethRpcModule; use reth_tracing::tracing::{debug, info}; @@ -254,28 +254,28 @@ pub struct OpAddOns< enable_tx_conditional: bool, } -impl Default for OpAddOns +impl Default for OpAddOns> where - N: FullNodeComponents>, - OpEthApiBuilder: EthApiBuilder, + N: FullNodeComponents, + OpEthApiBuilder: EthApiBuilder, { fn default() -> Self { Self::builder().build() } } -impl OpAddOns +impl OpAddOns> where - N: FullNodeComponents>, - OpEthApiBuilder: EthApiBuilder, + N: FullNodeComponents, + OpEthApiBuilder: EthApiBuilder, { /// Build a [`OpAddOns`] using [`OpAddOnsBuilder`]. - pub fn builder() -> OpAddOnsBuilder { + pub fn builder() -> OpAddOnsBuilder { OpAddOnsBuilder::default() } } -impl NodeAddOns for OpAddOns +impl NodeAddOns for OpAddOns> where N: FullNodeComponents< Types: NodeTypes< @@ -289,8 +289,10 @@ where OpEthApiError: FromEvmError, ::Transaction: OpPooledTx, EvmFactoryFor: EvmFactory>, + OpEthApi: FullEthApiServer, + NetworkT: op_alloy_network::Network + Unpin, { - type Handle = RpcHandle>; + type Handle = RpcHandle>; async fn launch_add_ons( self, @@ -360,7 +362,7 @@ where } } -impl RethRpcAddOns for OpAddOns +impl RethRpcAddOns for OpAddOns> where N: FullNodeComponents< Types: NodeTypes< @@ -374,15 +376,17 @@ where OpEthApiError: FromEvmError, <::Pool as TransactionPool>::Transaction: OpPooledTx, EvmFactoryFor: EvmFactory>, + OpEthApi: FullEthApiServer, + NetworkT: op_alloy_network::Network + Unpin, { - type EthApi = OpEthApi; + type EthApi = OpEthApi; fn hooks_mut(&mut self) -> &mut reth_node_builder::rpc::RpcHooks { self.rpc_add_ons.hooks_mut() } } -impl EngineValidatorAddOn for OpAddOns +impl EngineValidatorAddOn for OpAddOns> where N: FullNodeComponents< Types: NodeTypes< @@ -391,7 +395,7 @@ where Payload = OpEngineTypes, >, >, - OpEthApiBuilder: EthApiBuilder, + OpEthApiBuilder: EthApiBuilder, { type Validator = OpEngineValidator; @@ -401,9 +405,9 @@ where } /// A regular optimism evm and executor builder. -#[derive(Debug, Default, Clone)] +#[derive(Debug, Clone)] #[non_exhaustive] -pub struct OpAddOnsBuilder { +pub struct OpAddOnsBuilder { /// Sequencer client, configured to forward submitted transactions to sequencer of given OP /// network. sequencer_url: Option, @@ -411,9 +415,22 @@ pub struct OpAddOnsBuilder { da_config: Option, /// Enable transaction conditionals. enable_tx_conditional: bool, + /// Marker for network types. + _nt: PhantomData, } -impl OpAddOnsBuilder { +impl Default for OpAddOnsBuilder { + fn default() -> Self { + Self { + sequencer_url: None, + da_config: None, + enable_tx_conditional: false, + _nt: PhantomData, + } + } +} + +impl OpAddOnsBuilder { /// With a [`SequencerClient`]. pub fn with_sequencer(mut self, sequencer_client: Option) -> Self { self.sequencer_url = sequencer_client; @@ -433,14 +450,14 @@ impl OpAddOnsBuilder { } } -impl OpAddOnsBuilder { +impl OpAddOnsBuilder { /// Builds an instance of [`OpAddOns`]. - pub fn build(self) -> OpAddOns + pub fn build(self) -> OpAddOns> where - N: FullNodeComponents>, - OpEthApiBuilder: EthApiBuilder, + N: FullNodeComponents, + OpEthApiBuilder: EthApiBuilder, { - let Self { sequencer_url, da_config, enable_tx_conditional } = self; + let Self { sequencer_url, da_config, enable_tx_conditional, .. } = self; OpAddOns { rpc_add_ons: RpcAddOns::new( diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs index f2f636cb42..fb462c99ee 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -99,7 +99,7 @@ where } /// Build a [`OpEthApi`] using [`OpEthApiBuilder`]. - pub const fn builder() -> OpEthApiBuilder { + pub const fn builder() -> OpEthApiBuilder { OpEthApiBuilder::new() } } @@ -119,9 +119,10 @@ where } } -impl RpcNodeCore for OpEthApi +impl RpcNodeCore for OpEthApi where N: OpNodeCore, + NetworkT: op_alloy_network::Network, { type Primitives = N::Primitives; type Provider = N::Provider; @@ -156,9 +157,10 @@ where } } -impl RpcNodeCoreExt for OpEthApi +impl RpcNodeCoreExt for OpEthApi where N: OpNodeCore, + NetworkT: op_alloy_network::Network, { #[inline] fn cache(&self) -> &EthStateCache, ProviderReceipt> { @@ -166,7 +168,7 @@ where } } -impl EthApiSpec for OpEthApi +impl EthApiSpec for OpEthApi where N: OpNodeCore< Provider: ChainSpecProvider @@ -174,6 +176,7 @@ where + StageCheckpointReader, Network: NetworkInfo, >, + NetworkT: op_alloy_network::Network, { type Transaction = ProviderTx; @@ -188,10 +191,11 @@ where } } -impl SpawnBlocking for OpEthApi +impl SpawnBlocking for OpEthApi where Self: Send + Sync + Clone + 'static, N: OpNodeCore, + NetworkT: op_alloy_network::Network, { #[inline] fn io_task_spawner(&self) -> impl TaskSpawner { @@ -209,7 +213,7 @@ where } } -impl LoadFee for OpEthApi +impl LoadFee for OpEthApi where Self: LoadBlock, N: OpNodeCore< @@ -229,15 +233,17 @@ where } } -impl LoadState for OpEthApi where +impl LoadState for OpEthApi +where N: OpNodeCore< Provider: StateProviderFactory + ChainSpecProvider, Pool: TransactionPool, - > + >, + NetworkT: op_alloy_network::Network, { } -impl EthState for OpEthApi +impl EthState for OpEthApi where Self: LoadState + SpawnBlocking, N: OpNodeCore, @@ -248,14 +254,14 @@ where } } -impl EthFees for OpEthApi +impl EthFees for OpEthApi where Self: LoadFee, N: OpNodeCore, { } -impl Trace for OpEthApi +impl Trace for OpEthApi where Self: RpcNodeCore + LoadState< @@ -271,7 +277,7 @@ where { } -impl AddDevSigners for OpEthApi +impl AddDevSigners for OpEthApi where N: OpNodeCore, { @@ -280,7 +286,7 @@ where } } -impl fmt::Debug for OpEthApi { +impl fmt::Debug for OpEthApi { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("OpEthApi").finish_non_exhaustive() } @@ -308,17 +314,25 @@ impl OpEthApiInner { } /// Builds [`OpEthApi`] for Optimism. -#[derive(Debug, Default)] -pub struct OpEthApiBuilder { +#[derive(Debug)] +pub struct OpEthApiBuilder { /// Sequencer client, configured to forward submitted transactions to sequencer of given OP /// network. sequencer_url: Option, + /// Marker for network types. + _nt: PhantomData, } -impl OpEthApiBuilder { +impl Default for OpEthApiBuilder { + fn default() -> Self { + Self { sequencer_url: None, _nt: PhantomData } + } +} + +impl OpEthApiBuilder { /// Creates a [`OpEthApiBuilder`] instance from core components. pub const fn new() -> Self { - Self { sequencer_url: None } + Self { sequencer_url: None, _nt: PhantomData } } /// With a [`SequencerClient`]. @@ -328,15 +342,16 @@ impl OpEthApiBuilder { } } -impl EthApiBuilder for OpEthApiBuilder +impl EthApiBuilder for OpEthApiBuilder where N: FullNodeComponents, - OpEthApi: FullEthApiServer, + OpEthApi: FullEthApiServer, + NetworkT: op_alloy_network::Network + Unpin, { - type EthApi = OpEthApi; + type EthApi = OpEthApi; async fn build_eth_api(self, ctx: EthApiCtx<'_, N>) -> eyre::Result { - let Self { sequencer_url } = self; + let Self { sequencer_url, .. } = self; let eth_api = reth_rpc::EthApiBuilder::new( ctx.components.provider().clone(), ctx.components.pool().clone(),