Skip to content

Commit

Permalink
refactor: reverse order iterator for transaction queue (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayeletstarkware authored Jul 7, 2024
1 parent 006d0c3 commit a2b8df2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions crates/mempool/src/mempool_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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]
Expand All @@ -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])
}
4 changes: 3 additions & 1 deletion crates/mempool/src/transaction_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = &TransactionReference> {
self.queue.iter().map(|tx| &tx.0)
self.queue.iter().rev().map(|tx| &tx.0)
}

pub fn _get_nonce(&self, address: &ContractAddress) -> Option<&Nonce> {
Expand Down

0 comments on commit a2b8df2

Please sign in to comment.