mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-19 03:04:27 -05:00
refactor(pool): add IntoIter: Send bounds to avoid unnecessary Vec collect (#22001)
Co-authored-by: klkvr <klkvr@users.noreply.github.com> Co-authored-by: Amp <amp@ampcode.com> Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com> Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de> Co-authored-by: Emma Jamieson-Hoare <ejamieson19@gmail.com> Co-authored-by: Emma Jamieson-Hoare <emmajam@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
b3fe168548
commit
a87510069d
5
.changelog/old-dogs-shake.md
Normal file
5
.changelog/old-dogs-shake.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
reth-transaction-pool: minor
|
||||
---
|
||||
|
||||
Added `IntoIter: Send` bounds to `validate_transactions` and `validate_transactions_with_origin` in the `TransactionValidator` trait, avoiding unnecessary `Vec` collects. Simplified default `validate_transactions_with_origin` to delegate to `validate_transactions`.
|
||||
@@ -853,7 +853,8 @@ where
|
||||
|
||||
async fn validate_transactions(
|
||||
&self,
|
||||
transactions: impl IntoIterator<Item = (TransactionOrigin, Self::Transaction)> + Send,
|
||||
transactions: impl IntoIterator<Item = (TransactionOrigin, Self::Transaction), IntoIter: Send>
|
||||
+ Send,
|
||||
) -> Vec<TransactionValidationOutcome<Self::Transaction>> {
|
||||
self.validate_batch(transactions)
|
||||
}
|
||||
@@ -861,7 +862,7 @@ where
|
||||
async fn validate_transactions_with_origin(
|
||||
&self,
|
||||
origin: TransactionOrigin,
|
||||
transactions: impl IntoIterator<Item = Self::Transaction> + Send,
|
||||
transactions: impl IntoIterator<Item = Self::Transaction, IntoIter: Send> + Send,
|
||||
) -> Vec<TransactionValidationOutcome<Self::Transaction>> {
|
||||
self.validate_batch_with_origin(origin, transactions)
|
||||
}
|
||||
|
||||
@@ -212,7 +212,8 @@ pub trait TransactionValidator: Debug + Send + Sync {
|
||||
/// See also [`Self::validate_transaction`].
|
||||
fn validate_transactions(
|
||||
&self,
|
||||
transactions: impl IntoIterator<Item = (TransactionOrigin, Self::Transaction)> + Send,
|
||||
transactions: impl IntoIterator<Item = (TransactionOrigin, Self::Transaction), IntoIter: Send>
|
||||
+ Send,
|
||||
) -> impl Future<Output = Vec<TransactionValidationOutcome<Self::Transaction>>> + Send {
|
||||
futures_util::future::join_all(
|
||||
transactions.into_iter().map(|(origin, tx)| self.validate_transaction(origin, tx)),
|
||||
@@ -227,10 +228,9 @@ pub trait TransactionValidator: Debug + Send + Sync {
|
||||
fn validate_transactions_with_origin(
|
||||
&self,
|
||||
origin: TransactionOrigin,
|
||||
transactions: impl IntoIterator<Item = Self::Transaction> + Send,
|
||||
transactions: impl IntoIterator<Item = Self::Transaction, IntoIter: Send> + Send,
|
||||
) -> 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)
|
||||
self.validate_transactions(transactions.into_iter().map(move |tx| (origin, tx)))
|
||||
}
|
||||
|
||||
/// Invoked when the head block changes.
|
||||
@@ -260,7 +260,8 @@ where
|
||||
|
||||
async fn validate_transactions(
|
||||
&self,
|
||||
transactions: impl IntoIterator<Item = (TransactionOrigin, Self::Transaction)> + Send,
|
||||
transactions: impl IntoIterator<Item = (TransactionOrigin, Self::Transaction), IntoIter: Send>
|
||||
+ Send,
|
||||
) -> Vec<TransactionValidationOutcome<Self::Transaction>> {
|
||||
match self {
|
||||
Self::Left(v) => v.validate_transactions(transactions).await,
|
||||
@@ -268,17 +269,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
async fn validate_transactions_with_origin(
|
||||
&self,
|
||||
origin: TransactionOrigin,
|
||||
transactions: impl IntoIterator<Item = Self::Transaction> + Send,
|
||||
) -> 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(&self, new_tip_block: &SealedBlock<Self::Block>) {
|
||||
match self {
|
||||
Self::Left(v) => v.on_new_head_block(new_tip_block),
|
||||
|
||||
@@ -254,7 +254,8 @@ where
|
||||
|
||||
async fn validate_transactions(
|
||||
&self,
|
||||
transactions: impl IntoIterator<Item = (TransactionOrigin, Self::Transaction)> + Send,
|
||||
transactions: impl IntoIterator<Item = (TransactionOrigin, Self::Transaction), IntoIter: Send>
|
||||
+ Send,
|
||||
) -> Vec<TransactionValidationOutcome<Self::Transaction>> {
|
||||
let transactions: Vec<_> = transactions.into_iter().collect();
|
||||
let hashes: Vec<_> = transactions.iter().map(|(_, tx)| *tx.hash()).collect();
|
||||
@@ -296,15 +297,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
async fn validate_transactions_with_origin(
|
||||
&self,
|
||||
origin: TransactionOrigin,
|
||||
transactions: impl IntoIterator<Item = Self::Transaction> + Send,
|
||||
) -> Vec<TransactionValidationOutcome<Self::Transaction>> {
|
||||
let transactions: Vec<_> = transactions.into_iter().map(|tx| (origin, tx)).collect();
|
||||
self.validate_transactions(transactions).await
|
||||
}
|
||||
|
||||
fn on_new_head_block(&self, new_tip_block: &SealedBlock<Self::Block>) {
|
||||
self.validator.on_new_head_block(new_tip_block)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user