Skip to content

Commit

Permalink
refactor(mempool): change address-to-tx value type to
Browse files Browse the repository at this point in the history
TransactionReference
  • Loading branch information
MohammadNassar1 committed Jul 9, 2024
1 parent cc32a70 commit 4fd12e9
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions crates/mempool/src/transaction_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ pub struct TransactionQueue {
// Priority queue of transactions with associated priority.
queue: BTreeSet<QueuedTransaction>,
// Set of account addresses for efficient existence checks.
// TODO(Mohammad): change to mapping to `QueuedTransaction`.
address_to_tx: HashMap<ContractAddress, Nonce>,
address_to_tx: HashMap<ContractAddress, TransactionReference>,
}

impl TransactionQueue {
/// Adds a transaction to the mempool, ensuring unique keys.
/// Panics: if given a duplicate tx.
pub fn insert(&mut self, tx: TransactionReference) {
assert_eq!(self.address_to_tx.insert(tx.sender_address, tx.nonce), None);
assert_eq!(self.address_to_tx.insert(tx.sender_address, tx), None);
assert!(
self.queue.insert(tx.into()),
"Keys should be unique; duplicates are checked prior."
Expand All @@ -47,7 +46,7 @@ impl TransactionQueue {
}

pub fn _get_nonce(&self, address: &ContractAddress) -> Option<&Nonce> {
self.address_to_tx.get(address)
self.address_to_tx.get(address).map(|tx| &tx.nonce)
}
}

Expand Down

0 comments on commit 4fd12e9

Please sign in to comment.