Skip to content

Commit

Permalink
feat: add validate transactions function (#5010)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Oct 13, 2023
1 parent 92ceb2f commit 411893e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
11 changes: 9 additions & 2 deletions crates/transaction-pool/src/validate/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ where
/// See also [Self::validate_one]
pub fn validate_all(
&self,
transaction: Vec<(TransactionOrigin, Tx)>,
transactions: Vec<(TransactionOrigin, Tx)>,
) -> Vec<TransactionValidationOutcome<Tx>> {
transaction.into_iter().map(|(origin, tx)| self.validate_one(origin, tx)).collect()
transactions.into_iter().map(|(origin, tx)| self.validate_one(origin, tx)).collect()
}
}

Expand All @@ -78,6 +78,13 @@ where
self.validate_one(origin, transaction)
}

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

fn on_new_head_block(&self, new_tip_block: &SealedBlock) {
self.inner.on_new_head_block(new_tip_block)
}
Expand Down
15 changes: 15 additions & 0 deletions crates/transaction-pool/src/validate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,21 @@ pub trait TransactionValidator: Send + Sync {
transaction: Self::Transaction,
) -> TransactionValidationOutcome<Self::Transaction>;

/// Validates a batch of transactions.
///
/// Must return all outcomes for the given transactions in the same order.
///
/// See also [Self::validate_transaction].
async fn validate_transactions(
&self,
transactions: Vec<(TransactionOrigin, Self::Transaction)>,
) -> Vec<TransactionValidationOutcome<Self::Transaction>> {
futures_util::future::join_all(
transactions.into_iter().map(|(origin, tx)| self.validate_transaction(origin, tx)),
)
.await
}

/// Invoked when the head block changes.
///
/// This can be used to update fork specific values (timestamp).
Expand Down

0 comments on commit 411893e

Please sign in to comment.