diff --git a/crates/mempool/src/transaction_queue.rs b/crates/mempool/src/transaction_queue.rs index 1e4c30eb39e..67bc1371d91 100644 --- a/crates/mempool/src/transaction_queue.rs +++ b/crates/mempool/src/transaction_queue.rs @@ -11,6 +11,9 @@ use crate::mempool::TransactionReference; pub struct TransactionQueue { // Priority queue of transactions with associated priority. priority_queue: BTreeSet, + // queue of transaction with low gas price. + pending_queue: BTreeSet, + gas_price_threshold: u128, // Set of account addresses for efficient existence checks. address_to_tx: HashMap, } @@ -27,10 +30,17 @@ impl TransactionQueue { "Only a single transaction from the same contract class can be in the mempool at a \ time." ); - assert!( - self.priority_queue.insert(tx.into()), - "Keys should be unique; duplicates are checked prior." - ); + if tx.get_l2_gas_price() < Some(self.gas_price_threshold) { + assert!( + self.pending_queue.insert(tx.into()), + "Keys should be unique; duplicates are checked prior." + ); + } else { + assert!( + self.priority_queue.insert(tx.into()), + "Keys should be unique; duplicates are checked prior." + ); + } } // TODO(gilad): remove collect @@ -58,13 +68,14 @@ impl TransactionQueue { /// This is well-defined, since there is at most one transaction per address in the queue. pub fn remove(&mut self, address: ContractAddress) -> bool { if let Some(tx) = self.address_to_tx.remove(&address) { - return self.priority_queue.remove(&tx.into()); + return self.priority_queue.remove(&tx.clone().into()) + || self.pending_queue.remove(&tx.into()); } false } pub fn is_empty(&self) -> bool { - self.priority_queue.is_empty() + self.priority_queue.is_empty() && self.pending_queue.is_empty() } }