Skip to content
Merged
24 changes: 24 additions & 0 deletions crates/optimism/txpool/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,22 @@ where
)
.await
}

/// Validates all given transactions.
///
/// Returns all outcomes for the given transactions in the same order.
///
/// See also [`Self::validate_one`]
pub async fn validate_all_with_origin(
&self,
origin: TransactionOrigin,
transactions: Vec<Tx>,
) -> Vec<TransactionValidationOutcome<Tx>> {
futures_util::future::join_all(
transactions.into_iter().map(|tx| self.validate_one(origin, tx)),
)
.await
}

/// Performs the necessary opstack specific checks based on top of the regular eth outcome.
fn apply_op_checks(
Expand Down Expand Up @@ -330,6 +346,14 @@ where
) -> Vec<TransactionValidationOutcome<Self::Transaction>> {
self.validate_all(transactions).await
}

async fn validate_transactions_with_origin(
&self,
origin: TransactionOrigin,
transactions: Vec<Self::Transaction>,
) -> Vec<TransactionValidationOutcome<Self::Transaction>> {
self.validate_all_with_origin(origin, transactions).await
}

fn on_new_head_block<B>(&self, new_tip_block: &SealedBlock<B>)
where
Expand Down
34 changes: 34 additions & 0 deletions crates/transaction-pool/src/validate/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ where
) -> Vec<TransactionValidationOutcome<Tx>> {
self.inner.validate_batch(transactions)
}

/// Validates all given transactions with origin.
///
/// Returns all outcomes for the given transactions in the same order.
///
/// See also [`Self::validate_one`]
pub fn validate_all_with_origin(
&self,
origin: TransactionOrigin,
transactions: Vec<Tx>,
) -> Vec<TransactionValidationOutcome<Tx>> {
self.inner.validate_batch_with_origin(origin, transactions)
}
}

impl<Client, Tx> TransactionValidator for EthTransactionValidator<Client, Tx>
Expand All @@ -127,6 +140,14 @@ where
) -> Vec<TransactionValidationOutcome<Self::Transaction>> {
self.validate_all(transactions)
}

async fn validate_transactions_with_origin(
&self,
origin: TransactionOrigin,
transactions: Vec<Self::Transaction>,
) -> Vec<TransactionValidationOutcome<Self::Transaction>> {
self.validate_all_with_origin(origin, transactions)
}

fn on_new_head_block<B>(&self, new_tip_block: &SealedBlock<B>)
where
Expand Down Expand Up @@ -603,6 +624,19 @@ where
.map(|(origin, tx)| self.validate_one_with_provider(origin, tx, &mut provider))
.collect()
}

/// Validates all given transactions with origin.
fn validate_batch_with_origin(
&self,
origin: TransactionOrigin,
transactions: Vec<Tx>,
) -> Vec<TransactionValidationOutcome<Tx>> {
let mut provider = None;
transactions
.into_iter()
.map(|tx| self.validate_one_with_provider(origin, tx, &mut provider))
.collect()
}

fn on_new_head_block<T: BlockHeader>(&self, new_tip_block: &T) {
// update all forks
Expand Down
27 changes: 27 additions & 0 deletions crates/transaction-pool/src/validate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,22 @@ pub trait TransactionValidator: Debug + Send + Sync {
.await
}
}

/// Validates a batch of transactions against an origin.
///
/// Must return all outcomes for the given transactions in the same order.
///
/// See also [`Self::validate_transaction`].
fn validate_transactions_with_origin(
&self,
origin: TransactionOrigin,
transactions: Vec<Self::Transaction>,
) -> impl Future<Output = Vec<TransactionValidationOutcome<Self::Transaction>>> + Send {
let futures = transactions
.into_iter()
.map(|tx| self.validate_transaction(origin, tx));
futures_util::future::join_all(futures)
}

/// Invoked when the head block changes.
///
Expand Down Expand Up @@ -243,6 +259,17 @@ where
Self::Right(v) => v.validate_transactions(transactions).await,
}
}

async fn validate_transactions_with_origin(
&self,
origin: TransactionOrigin,
transactions: Vec<Self::Transaction>,
) -> Vec<TransactionValidationOutcome<Self::Transaction>> {
match self {
Self::Left(v) => v.validate_transactions_with_origin(origin, transactions).await,
Self::Right(v) => v.validate_transactions_with_origin(origin, transactions).await,
}
}

fn on_new_head_block<Bl>(&self, new_tip_block: &SealedBlock<Bl>)
where
Expand Down
Loading