From 04203ffb7de7d3fbd5bca076793736e87c8c99c5 Mon Sep 17 00:00:00 2001 From: Ayelet Zilber Date: Thu, 4 Jul 2024 14:12:14 +0300 Subject: [PATCH] refactor: reverse order iterator for transaction queue --- crates/mempool/src/mempool_test.rs | 6 +++--- crates/mempool/src/transaction_queue.rs | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/mempool/src/mempool_test.rs b/crates/mempool/src/mempool_test.rs index 5c761e0ec..9d7ab0526 100644 --- a/crates/mempool/src/mempool_test.rs +++ b/crates/mempool/src/mempool_test.rs @@ -109,7 +109,7 @@ fn test_add_tx(mut mempool: Mempool) { add_tx(&mut mempool, &input_tip_80_address_2); let expected_txs = - &[input_tip_50_address_0.tx, input_tip_80_address_2.tx, input_tip_100_address_1.tx]; + &[input_tip_100_address_1.tx, input_tip_80_address_2.tx, input_tip_50_address_0.tx]; check_mempool_txs_eq(&mempool, expected_txs) } @@ -152,7 +152,7 @@ fn test_add_tx_with_identical_tip_succeeds(mut mempool: Mempool) { // TODO: currently hash comparison tie-breaks the two. Once more robust tie-breaks are added // replace this assertion with a dedicated test. - check_mempool_txs_eq(&mempool, &[input2.tx, input1.tx]); + check_mempool_txs_eq(&mempool, &[input1.tx, input2.tx]); } #[rstest] @@ -165,5 +165,5 @@ fn test_tip_priority_over_tx_hash(mut mempool: Mempool) { add_tx(&mut mempool, &input_big_tip_small_hash); add_tx(&mut mempool, &input_small_tip_big_hash); - check_mempool_txs_eq(&mempool, &[input_small_tip_big_hash.tx, input_big_tip_small_hash.tx]) + check_mempool_txs_eq(&mempool, &[input_big_tip_small_hash.tx, input_small_tip_big_hash.tx]) } diff --git a/crates/mempool/src/transaction_queue.rs b/crates/mempool/src/transaction_queue.rs index 1edf0ee41..9dc070f2a 100644 --- a/crates/mempool/src/transaction_queue.rs +++ b/crates/mempool/src/transaction_queue.rs @@ -39,8 +39,10 @@ impl TransactionQueue { txs.into_iter().map(|tx| tx.tx_hash).collect() } + /// Returns an iterator of the current eligible transactions for sequencing, ordered by their + /// priority. pub fn iter(&self) -> impl Iterator { - self.queue.iter().map(|tx| &tx.0) + self.queue.iter().rev().map(|tx| &tx.0) } pub fn _get_nonce(&self, address: &ContractAddress) -> Option<&Nonce> {