Skip to content

Commit

Permalink
Merge pull request #570 from starkware-libs/mohammad/transaction-queu…
Browse files Browse the repository at this point in the history
…e/rename-method

refactor(mempool): rename tx queue methods (#570)
  • Loading branch information
MohammadNassar1 authored Aug 25, 2024
2 parents 72fa342 + bd16ff4 commit cd9fcf5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions crates/mempool/src/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = &TransactionReference> {
self.tx_queue.iter()
self.tx_queue.iter_over_ready_txs()
}

/// Retrieves up to `n_txs` transactions with the highest priority from the mempool.
Expand All @@ -44,8 +44,8 @@ impl Mempool {
let mut eligible_tx_references: Vec<TransactionReference> = 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);
Expand Down
6 changes: 3 additions & 3 deletions crates/mempool/src/transaction_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl TransactionQueue {
}

// TODO(gilad): remove collect
pub fn pop_chunk(&mut self, n_txs: usize) -> Vec<TransactionReference> {
pub fn pop_ready_chunk(&mut self, n_txs: usize) -> Vec<TransactionReference> {
let txs: Vec<TransactionReference> =
(0..n_txs).filter_map(|_| self.priority_queue.pop_last().map(|tx| tx.0)).collect();
for tx in &txs {
Expand All @@ -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<Item = &TransactionReference> {
pub fn iter_over_ready_txs(&self) -> impl Iterator<Item = &TransactionReference> {
self.priority_queue.iter().rev().map(|tx| &tx.0)
}

Expand All @@ -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()
}
}
Expand Down

0 comments on commit cd9fcf5

Please sign in to comment.