feat(op, cli): add cli option to enable tx conditional (#14421)

This commit is contained in:
Federico Gimenez
2025-02-12 14:15:27 +01:00
committed by GitHub
parent 82903d9fe4
commit 71b9f1225a
6 changed files with 109 additions and 22 deletions

View File

@ -1,4 +1,5 @@
use super::{OpEthApiInner, OpNodeCore};
//! Eth API extension.
use crate::{error::TxConditionalErr, OpEthApiError, SequencerClient};
use alloy_consensus::BlockHeader;
use alloy_eips::BlockNumberOrTag;
@ -15,42 +16,73 @@ use std::sync::Arc;
/// Maximum execution const for conditional transactions.
const MAX_CONDITIONAL_EXECUTION_COST: u64 = 5000;
#[derive(Debug)]
struct OpEthExtApiInner<Pool, Provider> {
/// The transaction pool of the node.
pool: Pool,
/// The provider type used to interact with the node.
provider: Provider,
}
impl<Pool, Provider> OpEthExtApiInner<Pool, Provider> {
fn new(pool: Pool, provider: Provider) -> Self {
Self { pool, provider }
}
#[inline]
fn pool(&self) -> &Pool {
&self.pool
}
#[inline]
fn provider(&self) -> &Provider {
&self.provider
}
}
/// OP-Reth `Eth` API extensions implementation.
///
/// Separate from [`super::OpEthApi`] to allow to enable it conditionally,
#[derive(Clone)]
#[derive(Clone, Debug)]
#[allow(dead_code)]
pub(crate) struct OpEthApiExt<N: OpNodeCore> {
/// Gateway to node's core components.
inner: Arc<OpEthApiInner<N>>,
pub struct OpEthExtApi<Pool, Provider> {
/// Sequencer client, configured to forward submitted transactions to sequencer of given OP
/// network.
sequencer_client: Option<SequencerClient>,
inner: Arc<OpEthExtApiInner<Pool, Provider>>,
}
impl<N> OpEthApiExt<N>
impl<Pool, Provider> OpEthExtApi<Pool, Provider>
where
N: OpNodeCore<Provider: BlockReaderIdExt + Clone + 'static>,
Provider: BlockReaderIdExt + Clone + 'static,
{
/// Creates a new [`OpEthExtApi`].
pub fn new(sequencer_client: Option<SequencerClient>, pool: Pool, provider: Provider) -> Self {
let inner = Arc::new(OpEthExtApiInner::new(pool, provider));
Self { sequencer_client, inner }
}
/// Returns the configured sequencer client, if any.
pub(crate) fn sequencer_client(&self) -> Option<&SequencerClient> {
self.inner.sequencer_client()
fn sequencer_client(&self) -> Option<&SequencerClient> {
self.sequencer_client.as_ref()
}
#[inline]
fn pool(&self) -> &N::Pool {
self.inner.eth_api.pool()
fn pool(&self) -> &Pool {
self.inner.pool()
}
#[inline]
fn provider(&self) -> &N::Provider {
self.inner.eth_api.provider()
fn provider(&self) -> &Provider {
self.inner.provider()
}
}
#[async_trait::async_trait]
impl<N> L2EthApiExtServer for OpEthApiExt<N>
impl<Pool, Provider> L2EthApiExtServer for OpEthExtApi<Pool, Provider>
where
N: OpNodeCore + 'static,
N::Provider: BlockReaderIdExt + StateProviderFactory,
N::Pool: TransactionPool<Transaction: MaybeConditionalTransaction>,
Provider: BlockReaderIdExt + StateProviderFactory + Clone + 'static,
Pool: TransactionPool<Transaction: MaybeConditionalTransaction> + 'static,
{
async fn send_raw_transaction_conditional(
&self,
@ -67,7 +99,7 @@ where
OpEthApiError::Eth(reth_rpc_eth_types::EthApiError::FailedToDecodeSignedTransaction)
})?;
let mut tx = <N::Pool as TransactionPool>::Transaction::from_pooled(recovered_tx);
let mut tx = <Pool as TransactionPool>::Transaction::from_pooled(recovered_tx);
// get current header
let header_not_found = || {

View File

@ -1,11 +1,11 @@
//! OP-Reth `eth_` endpoint implementation.
pub mod ext;
pub mod receipt;
pub mod transaction;
mod block;
mod call;
mod ext;
mod pending_block;
pub use receipt::{OpReceiptBuilder, OpReceiptFieldsBuilder};