Skip to content

Commit 401b88c

Browse files
developeruchemattssegraphite-app[bot]
authored
feat: added TransactionValidator::validate_transactions_with_origin (#16238)
Co-authored-by: Matthias Seitz <[email protected]> Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
1 parent 585a1cc commit 401b88c

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

crates/optimism/txpool/src/validator.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,22 @@ where
231231
.await
232232
}
233233

234+
/// Validates all given transactions with the specified origin parameter.
235+
///
236+
/// Returns all outcomes for the given transactions in the same order.
237+
///
238+
/// See also [`Self::validate_one`]
239+
pub async fn validate_all_with_origin(
240+
&self,
241+
origin: TransactionOrigin,
242+
transactions: Vec<Tx>,
243+
) -> Vec<TransactionValidationOutcome<Tx>> {
244+
futures_util::future::join_all(
245+
transactions.into_iter().map(|tx| self.validate_one(origin, tx)),
246+
)
247+
.await
248+
}
249+
234250
/// Performs the necessary opstack specific checks based on top of the regular eth outcome.
235251
fn apply_op_checks(
236252
&self,
@@ -331,6 +347,14 @@ where
331347
self.validate_all(transactions).await
332348
}
333349

350+
async fn validate_transactions_with_origin(
351+
&self,
352+
origin: TransactionOrigin,
353+
transactions: Vec<Self::Transaction>,
354+
) -> Vec<TransactionValidationOutcome<Self::Transaction>> {
355+
self.validate_all_with_origin(origin, transactions).await
356+
}
357+
334358
fn on_new_head_block<B>(&self, new_tip_block: &SealedBlock<B>)
335359
where
336360
B: Block,

crates/transaction-pool/src/validate/eth.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ where
104104
) -> Vec<TransactionValidationOutcome<Tx>> {
105105
self.inner.validate_batch(transactions)
106106
}
107+
108+
/// Validates all given transactions with origin.
109+
///
110+
/// Returns all outcomes for the given transactions in the same order.
111+
///
112+
/// See also [`Self::validate_one`]
113+
pub fn validate_all_with_origin(
114+
&self,
115+
origin: TransactionOrigin,
116+
transactions: Vec<Tx>,
117+
) -> Vec<TransactionValidationOutcome<Tx>> {
118+
self.inner.validate_batch_with_origin(origin, transactions)
119+
}
107120
}
108121

109122
impl<Client, Tx> TransactionValidator for EthTransactionValidator<Client, Tx>
@@ -128,6 +141,14 @@ where
128141
self.validate_all(transactions)
129142
}
130143

144+
async fn validate_transactions_with_origin(
145+
&self,
146+
origin: TransactionOrigin,
147+
transactions: Vec<Self::Transaction>,
148+
) -> Vec<TransactionValidationOutcome<Self::Transaction>> {
149+
self.validate_all_with_origin(origin, transactions)
150+
}
151+
131152
fn on_new_head_block<B>(&self, new_tip_block: &SealedBlock<B>)
132153
where
133154
B: Block,
@@ -604,6 +625,19 @@ where
604625
.collect()
605626
}
606627

628+
/// Validates all given transactions with origin.
629+
fn validate_batch_with_origin(
630+
&self,
631+
origin: TransactionOrigin,
632+
transactions: Vec<Tx>,
633+
) -> Vec<TransactionValidationOutcome<Tx>> {
634+
let mut provider = None;
635+
transactions
636+
.into_iter()
637+
.map(|tx| self.validate_one_with_provider(origin, tx, &mut provider))
638+
.collect()
639+
}
640+
607641
fn on_new_head_block<T: BlockHeader>(&self, new_tip_block: &T) {
608642
// update all forks
609643
if self.chain_spec().is_cancun_active_at_timestamp(new_tip_block.timestamp()) {

crates/transaction-pool/src/validate/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,20 @@ pub trait TransactionValidator: Debug + Send + Sync {
206206
}
207207
}
208208

209+
/// Validates a batch of transactions with that given origin.
210+
///
211+
/// Must return all outcomes for the given transactions in the same order.
212+
///
213+
/// See also [`Self::validate_transaction`].
214+
fn validate_transactions_with_origin(
215+
&self,
216+
origin: TransactionOrigin,
217+
transactions: Vec<Self::Transaction>,
218+
) -> impl Future<Output = Vec<TransactionValidationOutcome<Self::Transaction>>> + Send {
219+
let futures = transactions.into_iter().map(|tx| self.validate_transaction(origin, tx));
220+
futures_util::future::join_all(futures)
221+
}
222+
209223
/// Invoked when the head block changes.
210224
///
211225
/// This can be used to update fork specific values (timestamp).
@@ -244,6 +258,17 @@ where
244258
}
245259
}
246260

261+
async fn validate_transactions_with_origin(
262+
&self,
263+
origin: TransactionOrigin,
264+
transactions: Vec<Self::Transaction>,
265+
) -> Vec<TransactionValidationOutcome<Self::Transaction>> {
266+
match self {
267+
Self::Left(v) => v.validate_transactions_with_origin(origin, transactions).await,
268+
Self::Right(v) => v.validate_transactions_with_origin(origin, transactions).await,
269+
}
270+
}
271+
247272
fn on_new_head_block<Bl>(&self, new_tip_block: &SealedBlock<Bl>)
248273
where
249274
Bl: Block,

0 commit comments

Comments
 (0)