Skip to content

Commit

Permalink
fix: make address prio queue inner private
Browse files Browse the repository at this point in the history
To protect invariant.
  • Loading branch information
Gilad Chase committed Jun 13, 2024
1 parent 50d38f0 commit 9f6467f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions crates/mempool/src/priority_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,23 @@ impl PartialOrd for PrioritizedTransaction {

// TODO: remove when is used.
#[allow(dead_code)]
// Assumption: there are no gaps, and the transactions are received in order.
pub struct AddressPriorityQueue(pub Vec<ThinTransaction>);
// Invariant: Transactions have strictly increasing nonces, without gaps.
// Assumption: Transactions are provided in the correct order.
#[derive(Default)]
pub struct AddressPriorityQueue(Vec<ThinTransaction>);

// TODO: remove when is used.
#[allow(dead_code)]
impl AddressPriorityQueue {
pub fn push(&mut self, tx: ThinTransaction) {
if let Some(last_tx) = self.0.last() {
assert_eq!(
tx.nonce,
last_tx.nonce.try_increment().expect("Nonce overflow."),
"Nonces must be strictly increasing without gaps."
);
}

self.0.push(tx);
}

Expand Down

0 comments on commit 9f6467f

Please sign in to comment.