diff --git a/crates/transaction-pool/src/lib.rs b/crates/transaction-pool/src/lib.rs index 284a3ee70f..5b356d5830 100644 --- a/crates/transaction-pool/src/lib.rs +++ b/crates/transaction-pool/src/lib.rs @@ -225,7 +225,11 @@ where self.pool.add_transaction_listener() } - fn pooled_transactions(&self) -> Vec { + fn pooled_transaction_hashes(&self) -> Vec { + self.pool.pooled_transactions_hashes() + } + + fn pooled_transactions(&self) -> Vec>> { self.pool.pooled_transactions() } diff --git a/crates/transaction-pool/src/pool/mod.rs b/crates/transaction-pool/src/pool/mod.rs index 8ebdacb6a7..001a9bc034 100644 --- a/crates/transaction-pool/src/pool/mod.rs +++ b/crates/transaction-pool/src/pool/mod.rs @@ -172,11 +172,17 @@ where } /// Returns hashes of _all_ transactions in the pool. - pub(crate) fn pooled_transactions(&self) -> Vec { + pub(crate) fn pooled_transactions_hashes(&self) -> Vec { let pool = self.pool.read(); pool.all().hashes_iter().collect() } + /// Returns _all_ transactions in the pool. + pub(crate) fn pooled_transactions(&self) -> Vec>> { + let pool = self.pool.read(); + pool.all().transactions_iter().collect() + } + /// Updates the entire pool after a new block was executed. pub(crate) fn on_new_block(&self, block: OnNewBlockEvent) { let outcome = self.pool.write().on_new_block(block); diff --git a/crates/transaction-pool/src/pool/txpool.rs b/crates/transaction-pool/src/pool/txpool.rs index 2ec46d394e..983a9d48ac 100644 --- a/crates/transaction-pool/src/pool/txpool.rs +++ b/crates/transaction-pool/src/pool/txpool.rs @@ -512,6 +512,13 @@ impl AllTransactions { self.by_hash.keys().copied() } + /// Returns an iterator over all _unique_ hashes in the pool + pub(crate) fn transactions_iter( + &self, + ) -> impl Iterator>> + '_ { + self.by_hash.values().cloned() + } + /// Returns if the transaction for the given hash is already included in this pool pub(crate) fn contains(&self, tx_hash: &TxHash) -> bool { self.by_hash.contains_key(tx_hash) diff --git a/crates/transaction-pool/src/traits.rs b/crates/transaction-pool/src/traits.rs index 7a736ce2f0..d9b9461b0b 100644 --- a/crates/transaction-pool/src/traits.rs +++ b/crates/transaction-pool/src/traits.rs @@ -70,12 +70,19 @@ pub trait TransactionPool: Send + Sync + Clone { /// Returns a new stream that yields new valid transactions added to the pool. fn transactions_listener(&self) -> Receiver>; - /// Returns hashes of all transactions in the pool. + /// Returns the _hashes_ of all transactions in the pool. /// /// Note: This returns a `Vec` but should guarantee that all hashes are unique. /// /// Consumer: P2P - fn pooled_transactions(&self) -> Vec; + fn pooled_transaction_hashes(&self) -> Vec; + + /// Returns the _full_ transaction objects all transactions in the pool. + /// + /// Note: This returns a `Vec` but should guarantee that all transactions are unique. + /// + /// Consumer: P2P + fn pooled_transactions(&self) -> Vec>>; /// Returns an iterator that yields transactions that are ready for block production. ///