From 4fd12e9199aab055aa21892e8432dfd1d32a190d Mon Sep 17 00:00:00 2001 From: Mohammad Nassar Date: Tue, 9 Jul 2024 12:54:19 +0300 Subject: [PATCH] refactor(mempool): change address-to-tx value type to TransactionReference --- crates/mempool/src/transaction_queue.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/mempool/src/transaction_queue.rs b/crates/mempool/src/transaction_queue.rs index 1a50ca69d..754778b2b 100644 --- a/crates/mempool/src/transaction_queue.rs +++ b/crates/mempool/src/transaction_queue.rs @@ -14,15 +14,14 @@ pub struct TransactionQueue { // Priority queue of transactions with associated priority. queue: BTreeSet, // Set of account addresses for efficient existence checks. - // TODO(Mohammad): change to mapping to `QueuedTransaction`. - address_to_tx: HashMap, + address_to_tx: HashMap, } 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." @@ -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) } }