feat: added TransactionValidator::validate_transactions_with_origin (#16238)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
This commit is contained in:
Developer Uche
2025-05-16 12:53:48 +01:00
committed by GitHub
parent 585a1cca9d
commit 401b88c86b
3 changed files with 83 additions and 0 deletions

View File

@@ -231,6 +231,22 @@ where
.await
}
/// Validates all given transactions with the specified origin parameter.
///
/// 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(
&self,
@@ -331,6 +347,14 @@ where
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
B: Block,

View File

@@ -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>
@@ -128,6 +141,14 @@ where
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
B: Block,
@@ -604,6 +625,19 @@ where
.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
if self.chain_spec().is_cancun_active_at_timestamp(new_tip_block.timestamp()) {

View File

@@ -206,6 +206,20 @@ pub trait TransactionValidator: Debug + Send + Sync {
}
}
/// Validates a batch of transactions with that given 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.
///
/// This can be used to update fork specific values (timestamp).
@@ -244,6 +258,17 @@ where
}
}
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
Bl: Block,