mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-15 09:25:33 -05:00
feat: relax OpEthApiBuilder type constraints (#16410)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -9172,6 +9172,7 @@ dependencies = [
|
||||
"eyre",
|
||||
"futures",
|
||||
"op-alloy-consensus",
|
||||
"op-alloy-network",
|
||||
"op-alloy-rpc-types-engine",
|
||||
"op-revm",
|
||||
"reth-chainspec",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<N> Default for OpAddOns<N, OpEthApiBuilder>
|
||||
impl<N, NetworkT> Default for OpAddOns<N, OpEthApiBuilder<NetworkT>>
|
||||
where
|
||||
N: FullNodeComponents<Types: NodeTypes<Primitives = OpPrimitives>>,
|
||||
OpEthApiBuilder: EthApiBuilder<N>,
|
||||
N: FullNodeComponents<Types: NodeTypes>,
|
||||
OpEthApiBuilder<NetworkT>: EthApiBuilder<N>,
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self::builder().build()
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> OpAddOns<N, OpEthApiBuilder>
|
||||
impl<N, NetworkT> OpAddOns<N, OpEthApiBuilder<NetworkT>>
|
||||
where
|
||||
N: FullNodeComponents<Types: NodeTypes<Primitives = OpPrimitives>>,
|
||||
OpEthApiBuilder: EthApiBuilder<N>,
|
||||
N: FullNodeComponents<Types: NodeTypes>,
|
||||
OpEthApiBuilder<NetworkT>: EthApiBuilder<N>,
|
||||
{
|
||||
/// Build a [`OpAddOns`] using [`OpAddOnsBuilder`].
|
||||
pub fn builder() -> OpAddOnsBuilder {
|
||||
pub fn builder() -> OpAddOnsBuilder<NetworkT> {
|
||||
OpAddOnsBuilder::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> NodeAddOns<N> for OpAddOns<N, OpEthApiBuilder>
|
||||
impl<N, NetworkT> NodeAddOns<N> for OpAddOns<N, OpEthApiBuilder<NetworkT>>
|
||||
where
|
||||
N: FullNodeComponents<
|
||||
Types: NodeTypes<
|
||||
@@ -289,8 +289,10 @@ where
|
||||
OpEthApiError: FromEvmError<N::Evm>,
|
||||
<N::Pool as TransactionPool>::Transaction: OpPooledTx,
|
||||
EvmFactoryFor<N::Evm>: EvmFactory<Tx = op_revm::OpTransaction<TxEnv>>,
|
||||
OpEthApi<N, NetworkT>: FullEthApiServer<Provider = N::Provider, Pool = N::Pool>,
|
||||
NetworkT: op_alloy_network::Network + Unpin,
|
||||
{
|
||||
type Handle = RpcHandle<N, OpEthApi<N>>;
|
||||
type Handle = RpcHandle<N, OpEthApi<N, NetworkT>>;
|
||||
|
||||
async fn launch_add_ons(
|
||||
self,
|
||||
@@ -360,7 +362,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> RethRpcAddOns<N> for OpAddOns<N, OpEthApiBuilder>
|
||||
impl<N, NetworkT> RethRpcAddOns<N> for OpAddOns<N, OpEthApiBuilder<NetworkT>>
|
||||
where
|
||||
N: FullNodeComponents<
|
||||
Types: NodeTypes<
|
||||
@@ -374,15 +376,17 @@ where
|
||||
OpEthApiError: FromEvmError<N::Evm>,
|
||||
<<N as FullNodeComponents>::Pool as TransactionPool>::Transaction: OpPooledTx,
|
||||
EvmFactoryFor<N::Evm>: EvmFactory<Tx = op_revm::OpTransaction<TxEnv>>,
|
||||
OpEthApi<N, NetworkT>: FullEthApiServer<Provider = N::Provider, Pool = N::Pool>,
|
||||
NetworkT: op_alloy_network::Network + Unpin,
|
||||
{
|
||||
type EthApi = OpEthApi<N>;
|
||||
type EthApi = OpEthApi<N, NetworkT>;
|
||||
|
||||
fn hooks_mut(&mut self) -> &mut reth_node_builder::rpc::RpcHooks<N, Self::EthApi> {
|
||||
self.rpc_add_ons.hooks_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> EngineValidatorAddOn<N> for OpAddOns<N, OpEthApiBuilder>
|
||||
impl<N, NetworkT> EngineValidatorAddOn<N> for OpAddOns<N, OpEthApiBuilder<NetworkT>>
|
||||
where
|
||||
N: FullNodeComponents<
|
||||
Types: NodeTypes<
|
||||
@@ -391,7 +395,7 @@ where
|
||||
Payload = OpEngineTypes,
|
||||
>,
|
||||
>,
|
||||
OpEthApiBuilder: EthApiBuilder<N>,
|
||||
OpEthApiBuilder<NetworkT>: EthApiBuilder<N>,
|
||||
{
|
||||
type Validator = OpEngineValidator<N::Provider>;
|
||||
|
||||
@@ -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<NetworkT> {
|
||||
/// Sequencer client, configured to forward submitted transactions to sequencer of given OP
|
||||
/// network.
|
||||
sequencer_url: Option<String>,
|
||||
@@ -411,9 +415,22 @@ pub struct OpAddOnsBuilder {
|
||||
da_config: Option<OpDAConfig>,
|
||||
/// Enable transaction conditionals.
|
||||
enable_tx_conditional: bool,
|
||||
/// Marker for network types.
|
||||
_nt: PhantomData<NetworkT>,
|
||||
}
|
||||
|
||||
impl OpAddOnsBuilder {
|
||||
impl<NetworkT> Default for OpAddOnsBuilder<NetworkT> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
sequencer_url: None,
|
||||
da_config: None,
|
||||
enable_tx_conditional: false,
|
||||
_nt: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<NetworkT> OpAddOnsBuilder<NetworkT> {
|
||||
/// With a [`SequencerClient`].
|
||||
pub fn with_sequencer(mut self, sequencer_client: Option<String>) -> Self {
|
||||
self.sequencer_url = sequencer_client;
|
||||
@@ -433,14 +450,14 @@ impl OpAddOnsBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
impl OpAddOnsBuilder {
|
||||
impl<NetworkT> OpAddOnsBuilder<NetworkT> {
|
||||
/// Builds an instance of [`OpAddOns`].
|
||||
pub fn build<N>(self) -> OpAddOns<N, OpEthApiBuilder>
|
||||
pub fn build<N>(self) -> OpAddOns<N, OpEthApiBuilder<NetworkT>>
|
||||
where
|
||||
N: FullNodeComponents<Types: NodeTypes<Primitives = OpPrimitives>>,
|
||||
OpEthApiBuilder: EthApiBuilder<N>,
|
||||
N: FullNodeComponents<Types: NodeTypes>,
|
||||
OpEthApiBuilder<NetworkT>: EthApiBuilder<N>,
|
||||
{
|
||||
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(
|
||||
|
||||
@@ -99,7 +99,7 @@ where
|
||||
}
|
||||
|
||||
/// Build a [`OpEthApi`] using [`OpEthApiBuilder`].
|
||||
pub const fn builder() -> OpEthApiBuilder {
|
||||
pub const fn builder() -> OpEthApiBuilder<NetworkT> {
|
||||
OpEthApiBuilder::new()
|
||||
}
|
||||
}
|
||||
@@ -119,9 +119,10 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> RpcNodeCore for OpEthApi<N>
|
||||
impl<N, NetworkT> RpcNodeCore for OpEthApi<N, NetworkT>
|
||||
where
|
||||
N: OpNodeCore,
|
||||
NetworkT: op_alloy_network::Network,
|
||||
{
|
||||
type Primitives = N::Primitives;
|
||||
type Provider = N::Provider;
|
||||
@@ -156,9 +157,10 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> RpcNodeCoreExt for OpEthApi<N>
|
||||
impl<N, NetworkT> RpcNodeCoreExt for OpEthApi<N, NetworkT>
|
||||
where
|
||||
N: OpNodeCore,
|
||||
NetworkT: op_alloy_network::Network,
|
||||
{
|
||||
#[inline]
|
||||
fn cache(&self) -> &EthStateCache<ProviderBlock<N::Provider>, ProviderReceipt<N::Provider>> {
|
||||
@@ -166,7 +168,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> EthApiSpec for OpEthApi<N>
|
||||
impl<N, NetworkT> EthApiSpec for OpEthApi<N, NetworkT>
|
||||
where
|
||||
N: OpNodeCore<
|
||||
Provider: ChainSpecProvider<ChainSpec: EthereumHardforks>
|
||||
@@ -174,6 +176,7 @@ where
|
||||
+ StageCheckpointReader,
|
||||
Network: NetworkInfo,
|
||||
>,
|
||||
NetworkT: op_alloy_network::Network,
|
||||
{
|
||||
type Transaction = ProviderTx<Self::Provider>;
|
||||
|
||||
@@ -188,10 +191,11 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> SpawnBlocking for OpEthApi<N>
|
||||
impl<N, NetworkT> SpawnBlocking for OpEthApi<N, NetworkT>
|
||||
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<N> LoadFee for OpEthApi<N>
|
||||
impl<N, NetworkT> LoadFee for OpEthApi<N, NetworkT>
|
||||
where
|
||||
Self: LoadBlock<Provider = N::Provider>,
|
||||
N: OpNodeCore<
|
||||
@@ -229,15 +233,17 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> LoadState for OpEthApi<N> where
|
||||
impl<N, NetworkT> LoadState for OpEthApi<N, NetworkT>
|
||||
where
|
||||
N: OpNodeCore<
|
||||
Provider: StateProviderFactory + ChainSpecProvider<ChainSpec: EthereumHardforks>,
|
||||
Pool: TransactionPool,
|
||||
>
|
||||
>,
|
||||
NetworkT: op_alloy_network::Network,
|
||||
{
|
||||
}
|
||||
|
||||
impl<N> EthState for OpEthApi<N>
|
||||
impl<N, NetworkT> EthState for OpEthApi<N, NetworkT>
|
||||
where
|
||||
Self: LoadState + SpawnBlocking,
|
||||
N: OpNodeCore,
|
||||
@@ -248,14 +254,14 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> EthFees for OpEthApi<N>
|
||||
impl<N, NetworkT> EthFees for OpEthApi<N, NetworkT>
|
||||
where
|
||||
Self: LoadFee,
|
||||
N: OpNodeCore,
|
||||
{
|
||||
}
|
||||
|
||||
impl<N> Trace for OpEthApi<N>
|
||||
impl<N, NetworkT> Trace for OpEthApi<N, NetworkT>
|
||||
where
|
||||
Self: RpcNodeCore<Provider: BlockReader>
|
||||
+ LoadState<
|
||||
@@ -271,7 +277,7 @@ where
|
||||
{
|
||||
}
|
||||
|
||||
impl<N> AddDevSigners for OpEthApi<N>
|
||||
impl<N, NetworkT> AddDevSigners for OpEthApi<N, NetworkT>
|
||||
where
|
||||
N: OpNodeCore,
|
||||
{
|
||||
@@ -280,7 +286,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: OpNodeCore> fmt::Debug for OpEthApi<N> {
|
||||
impl<N: OpNodeCore, NetworkT> fmt::Debug for OpEthApi<N, NetworkT> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("OpEthApi").finish_non_exhaustive()
|
||||
}
|
||||
@@ -308,17 +314,25 @@ impl<N: OpNodeCore> OpEthApiInner<N> {
|
||||
}
|
||||
|
||||
/// Builds [`OpEthApi`] for Optimism.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct OpEthApiBuilder {
|
||||
#[derive(Debug)]
|
||||
pub struct OpEthApiBuilder<NetworkT = Optimism> {
|
||||
/// Sequencer client, configured to forward submitted transactions to sequencer of given OP
|
||||
/// network.
|
||||
sequencer_url: Option<String>,
|
||||
/// Marker for network types.
|
||||
_nt: PhantomData<NetworkT>,
|
||||
}
|
||||
|
||||
impl OpEthApiBuilder {
|
||||
impl<NetworkT> Default for OpEthApiBuilder<NetworkT> {
|
||||
fn default() -> Self {
|
||||
Self { sequencer_url: None, _nt: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
impl<NetworkT> OpEthApiBuilder<NetworkT> {
|
||||
/// 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<N> EthApiBuilder<N> for OpEthApiBuilder
|
||||
impl<N, NetworkT> EthApiBuilder<N> for OpEthApiBuilder<NetworkT>
|
||||
where
|
||||
N: FullNodeComponents,
|
||||
OpEthApi<N>: FullEthApiServer<Provider = N::Provider, Pool = N::Pool>,
|
||||
OpEthApi<N, NetworkT>: FullEthApiServer<Provider = N::Provider, Pool = N::Pool>,
|
||||
NetworkT: op_alloy_network::Network + Unpin,
|
||||
{
|
||||
type EthApi = OpEthApi<N>;
|
||||
type EthApi = OpEthApi<N, NetworkT>;
|
||||
|
||||
async fn build_eth_api(self, ctx: EthApiCtx<'_, N>) -> eyre::Result<Self::EthApi> {
|
||||
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(),
|
||||
|
||||
Reference in New Issue
Block a user