diff --git a/crates/transaction-pool/src/lib.rs b/crates/transaction-pool/src/lib.rs index 1bf0a3ed95..c27cbd0519 100644 --- a/crates/transaction-pool/src/lib.rs +++ b/crates/transaction-pool/src/lib.rs @@ -235,9 +235,9 @@ where fn remove_invalid( &self, - _tx_hashes: &[TxHash], + hashes: impl IntoIterator, ) -> Vec>> { - todo!() + self.pool.remove_invalid(hashes) } fn retain_unknown(&self, hashes: &mut Vec) { diff --git a/crates/transaction-pool/src/pool/mod.rs b/crates/transaction-pool/src/pool/mod.rs index 06283fdec9..cd35fa8ea1 100644 --- a/crates/transaction-pool/src/pool/mod.rs +++ b/crates/transaction-pool/src/pool/mod.rs @@ -334,6 +334,20 @@ where self.pool.read().best_transactions() } + /// Removes and returns all matching transactions from the pool. + pub(crate) fn remove_invalid( + &self, + hashes: impl IntoIterator, + ) -> Vec>> { + let removed = self.pool.write().remove_invalid(hashes); + + let mut listener = self.event_listener.write(); + + removed.iter().for_each(|tx| listener.discarded(tx.hash())); + + removed + } + /// Removes all transactions that are missing in the pool. pub(crate) fn retain_unknown(&self, hashes: &mut Vec) { let pool = self.pool.read(); diff --git a/crates/transaction-pool/src/pool/txpool.rs b/crates/transaction-pool/src/pool/txpool.rs index 14d98e33cb..72d001c179 100644 --- a/crates/transaction-pool/src/pool/txpool.rs +++ b/crates/transaction-pool/src/pool/txpool.rs @@ -276,6 +276,14 @@ impl TxPool { } } + /// Removes and returns all matching transactions from the pool. + pub(crate) fn remove_invalid( + &mut self, + hashes: impl IntoIterator, + ) -> Vec>> { + hashes.into_iter().filter_map(|hash| self.remove_transaction_by_hash(&hash)).collect() + } + /// Remove the transaction from the entire pool. /// /// This includes the total set of transaction and the subpool it currently resides in. @@ -289,7 +297,7 @@ impl TxPool { /// Remove the transaction from the entire pool via its hash. /// - /// This includes the total set of transaction and the subpool it currently resides in. + /// This includes the total set of transactions and the subpool it currently resides in. fn remove_transaction_by_hash( &mut self, tx_hash: &H256, diff --git a/crates/transaction-pool/src/traits.rs b/crates/transaction-pool/src/traits.rs index 78f96f6298..0fa14fe7bf 100644 --- a/crates/transaction-pool/src/traits.rs +++ b/crates/transaction-pool/src/traits.rs @@ -83,7 +83,7 @@ pub trait TransactionPool: Send + Sync + 'static { /// Consumer: Block production fn remove_invalid( &self, - tx_hashes: &[TxHash], + hashes: impl IntoIterator, ) -> Vec>>; /// Retains only those hashes that are unknown to the pool.