Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: reverse order iterator for transaction queue #364

Merged
merged 1 commit into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading