From a87510069ded5b6c69ff0ffe626d0a69fa02f510 Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Mon, 9 Feb 2026 13:45:56 -0800 Subject: [PATCH] refactor(pool): add IntoIter: Send bounds to avoid unnecessary Vec collect (#22001) Co-authored-by: klkvr Co-authored-by: Amp Co-authored-by: Arsenii Kulikov Co-authored-by: Matthias Seitz Co-authored-by: Emma Jamieson-Hoare Co-authored-by: Emma Jamieson-Hoare --- .changelog/old-dogs-shake.md | 5 +++++ crates/transaction-pool/src/validate/eth.rs | 5 +++-- crates/transaction-pool/src/validate/mod.rs | 22 ++++++-------------- crates/transaction-pool/src/validate/task.rs | 12 ++--------- 4 files changed, 16 insertions(+), 28 deletions(-) create mode 100644 .changelog/old-dogs-shake.md diff --git a/.changelog/old-dogs-shake.md b/.changelog/old-dogs-shake.md new file mode 100644 index 0000000000..2c5da9f7b2 --- /dev/null +++ b/.changelog/old-dogs-shake.md @@ -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`. diff --git a/crates/transaction-pool/src/validate/eth.rs b/crates/transaction-pool/src/validate/eth.rs index 69cd89c414..058823f503 100644 --- a/crates/transaction-pool/src/validate/eth.rs +++ b/crates/transaction-pool/src/validate/eth.rs @@ -853,7 +853,8 @@ where async fn validate_transactions( &self, - transactions: impl IntoIterator + Send, + transactions: impl IntoIterator + + Send, ) -> Vec> { self.validate_batch(transactions) } @@ -861,7 +862,7 @@ where async fn validate_transactions_with_origin( &self, origin: TransactionOrigin, - transactions: impl IntoIterator + Send, + transactions: impl IntoIterator + Send, ) -> Vec> { self.validate_batch_with_origin(origin, transactions) } diff --git a/crates/transaction-pool/src/validate/mod.rs b/crates/transaction-pool/src/validate/mod.rs index 1ae8dfacfa..17f4677c8a 100644 --- a/crates/transaction-pool/src/validate/mod.rs +++ b/crates/transaction-pool/src/validate/mod.rs @@ -212,7 +212,8 @@ pub trait TransactionValidator: Debug + Send + Sync { /// See also [`Self::validate_transaction`]. fn validate_transactions( &self, - transactions: impl IntoIterator + Send, + transactions: impl IntoIterator + + Send, ) -> impl Future>> + 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 + Send, + transactions: impl IntoIterator + Send, ) -> impl Future>> + 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 + Send, + transactions: impl IntoIterator + + Send, ) -> Vec> { 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 + Send, - ) -> Vec> { - 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) { match self { Self::Left(v) => v.on_new_head_block(new_tip_block), diff --git a/crates/transaction-pool/src/validate/task.rs b/crates/transaction-pool/src/validate/task.rs index eb07de96da..bf1798c5c0 100644 --- a/crates/transaction-pool/src/validate/task.rs +++ b/crates/transaction-pool/src/validate/task.rs @@ -254,7 +254,8 @@ where async fn validate_transactions( &self, - transactions: impl IntoIterator + Send, + transactions: impl IntoIterator + + Send, ) -> Vec> { 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 + Send, - ) -> Vec> { - 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.validator.on_new_head_block(new_tip_block) }