From bd16ff42fb906826671f060ea3835ac5f6e83964 Mon Sep 17 00:00:00 2001 From: Mohammad Nassar Date: Thu, 22 Aug 2024 17:52:13 +0300 Subject: [PATCH] refactor(mempool): rename tx queue methods --- crates/mempool/src/mempool.rs | 6 +++--- crates/mempool/src/transaction_queue.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/mempool/src/mempool.rs b/crates/mempool/src/mempool.rs index 9d600ebba8..a34e4d0ec3 100644 --- a/crates/mempool/src/mempool.rs +++ b/crates/mempool/src/mempool.rs @@ -32,7 +32,7 @@ impl Mempool { /// Returns an iterator of the current eligible transactions for sequencing, ordered by their /// priority. pub fn iter(&self) -> impl Iterator { - self.tx_queue.iter() + self.tx_queue.iter_over_ready_txs() } /// Retrieves up to `n_txs` transactions with the highest priority from the mempool. @@ -44,8 +44,8 @@ impl Mempool { let mut eligible_tx_references: Vec = Vec::with_capacity(n_txs); let mut n_remaining_txs = n_txs; - while n_remaining_txs > 0 && !self.tx_queue.is_empty() { - let chunk = self.tx_queue.pop_chunk(n_remaining_txs); + while n_remaining_txs > 0 && !self.tx_queue.has_ready_txs() { + let chunk = self.tx_queue.pop_ready_chunk(n_remaining_txs); self.enqueue_next_eligible_txs(&chunk)?; n_remaining_txs -= chunk.len(); eligible_tx_references.extend(chunk); diff --git a/crates/mempool/src/transaction_queue.rs b/crates/mempool/src/transaction_queue.rs index 099770e341..60935e784d 100644 --- a/crates/mempool/src/transaction_queue.rs +++ b/crates/mempool/src/transaction_queue.rs @@ -34,7 +34,7 @@ impl TransactionQueue { } // TODO(gilad): remove collect - pub fn pop_chunk(&mut self, n_txs: usize) -> Vec { + pub fn pop_ready_chunk(&mut self, n_txs: usize) -> Vec { let txs: Vec = (0..n_txs).filter_map(|_| self.priority_queue.pop_last().map(|tx| tx.0)).collect(); for tx in &txs { @@ -46,7 +46,7 @@ impl TransactionQueue { /// Returns an iterator of the current eligible transactions for sequencing, ordered by their /// priority. - pub fn iter(&self) -> impl Iterator { + pub fn iter_over_ready_txs(&self) -> impl Iterator { self.priority_queue.iter().rev().map(|tx| &tx.0) } @@ -63,7 +63,7 @@ impl TransactionQueue { false } - pub fn is_empty(&self) -> bool { + pub fn has_ready_txs(&self) -> bool { self.priority_queue.is_empty() } }