diff --git a/crates/block-producer/src/batch_builder/mod.rs b/crates/block-producer/src/batch_builder/mod.rs index b63ee9bf..5d8f1c14 100644 --- a/crates/block-producer/src/batch_builder/mod.rs +++ b/crates/block-producer/src/batch_builder/mod.rs @@ -10,7 +10,7 @@ use tracing::{debug, info, instrument, Span}; use crate::{ block_builder::BlockBuilder, - mempool::{BatchId, Mempool}, + mempool::{BatchJobId, Mempool}, ProvenTransaction, SharedRwVec, COMPONENT, }; @@ -221,7 +221,7 @@ pub struct BatchProducer { pub tx_per_batch: usize, } -type BatchResult = Result<(BatchId, TransactionBatch), (BatchId, BuildBatchError)>; +type BatchResult = Result<(BatchJobId, TransactionBatch), (BatchJobId, BuildBatchError)>; /// Wrapper around tokio's JoinSet that remains pending if the set is empty, /// instead of returning None. @@ -243,7 +243,7 @@ impl WorkerPool { fn spawn( &mut self, - id: BatchId, + id: BatchJobId, transactions: Vec>, note_info: NoteAuthenticationInfo, ) { diff --git a/crates/block-producer/src/mempool/batch_graph.rs b/crates/block-producer/src/mempool/batch_graph.rs index d8716ebf..ef92679e 100644 --- a/crates/block-producer/src/mempool/batch_graph.rs +++ b/crates/block-producer/src/mempool/batch_graph.rs @@ -3,21 +3,21 @@ use std::collections::{BTreeMap, BTreeSet}; use miden_objects::transaction::TransactionId; use miden_tx::utils::collections::KvMap; -use super::BatchId; +use super::BatchJobId; #[derive(Default, Clone)] pub struct BatchGraph { - nodes: BTreeMap, - roots: BTreeSet, + nodes: BTreeMap, + roots: BTreeSet, /// Allows for reverse lookup of transaction -> batch. - transactions: BTreeMap, + transactions: BTreeMap, } impl BatchGraph { pub fn insert( &mut self, - id: BatchId, + id: BatchJobId, transactions: Vec, parents: BTreeSet, ) { @@ -59,7 +59,7 @@ impl BatchGraph { } /// Removes the batch and all of its descendents from the graph. - pub fn purge_subgraph(&mut self, id: BatchId) -> Vec<(BatchId, Vec)> { + pub fn purge_subgraph(&mut self, id: BatchJobId) -> Vec<(BatchJobId, Vec)> { let mut removed = Vec::new(); let mut to_process = vec![id]; @@ -100,7 +100,7 @@ impl BatchGraph { /// Removes a set of batches from the graph without removing any descendents. /// /// This is intended to cull completed batches from stale blocks. - pub fn remove_stale(&mut self, batches: Vec) -> Vec { + pub fn remove_stale(&mut self, batches: Vec) -> Vec { let mut transactions = Vec::new(); for batch in batches { @@ -124,7 +124,7 @@ impl BatchGraph { } /// Mark a batch as proven if it exists. - pub fn mark_proven(&mut self, id: BatchId) { + pub fn mark_proven(&mut self, id: BatchJobId) { // Its possible for inflight batches to have been removed as part // of another batches failure. if let Some(node) = self.nodes.get_mut(&id) { @@ -133,7 +133,7 @@ impl BatchGraph { } } - pub fn pop_for_blocking(&mut self) -> Option<(BatchId, Vec)> { + pub fn pop_for_blocking(&mut self) -> Option<(BatchJobId, Vec)> { let batch_id = self.roots.pop_first()?; let node = self.nodes.get_mut(&batch_id).expect("Root node must be in graph"); node.status = Status::InBlock; @@ -149,7 +149,7 @@ impl BatchGraph { Some((batch_id, transactions)) } - fn try_make_root(&mut self, id: BatchId) { + fn try_make_root(&mut self, id: BatchJobId) { let node = self.nodes.get_mut(&id).expect("Node must be in graph"); for parent in node.parents.clone() { @@ -167,8 +167,8 @@ impl BatchGraph { struct Node { status: Status, transactions: Vec, - parents: BTreeSet, - children: BTreeSet, + parents: BTreeSet, + children: BTreeSet, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/crates/block-producer/src/mempool/mod.rs b/crates/block-producer/src/mempool/mod.rs index b3bdc6db..c65e75e9 100644 --- a/crates/block-producer/src/mempool/mod.rs +++ b/crates/block-producer/src/mempool/mod.rs @@ -22,15 +22,15 @@ mod batch_graph; mod transaction_graph; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] -pub struct BatchId(u64); +pub struct BatchJobId(u64); -impl Display for BatchId { +impl Display for BatchJobId { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.0.fmt(f) } } -impl BatchId { +impl BatchJobId { pub fn increment(mut self) { self.0 += 1; } @@ -71,10 +71,10 @@ pub struct Mempool { batches: BatchGraph, /// The next batches ID. - next_batch_id: BatchId, + next_batch_id: BatchJobId, /// Blocks which are inflight or completed but not yet considered stale. - block_pool: BTreeMap>, + block_pool: BTreeMap>, /// The current block height of the chain. completed_blocks: BlockNumber, @@ -140,7 +140,10 @@ impl Mempool { /// Transactions are returned in a valid execution ordering. /// /// Returns `None` if no transactions are available. - pub fn select_batch(&mut self, count: usize) -> Option<(BatchId, Vec>)> { + pub fn select_batch( + &mut self, + count: usize, + ) -> Option<(BatchJobId, Vec>)> { let mut parents = BTreeSet::new(); let mut batch = Vec::with_capacity(count); @@ -171,7 +174,7 @@ impl Mempool { /// Drops the failed batch and all of its descendents. /// /// Transactions are placed back in the queue. - pub fn batch_failed(&mut self, batch: BatchId) { + pub fn batch_failed(&mut self, batch: BatchJobId) { let removed_batches = self.batches.purge_subgraph(batch); // Its possible to receive failures for batches which were already removed @@ -189,14 +192,14 @@ impl Mempool { } /// Marks a batch as proven if it exists. - pub fn batch_proved(&mut self, batch_id: BatchId) { + pub fn batch_proved(&mut self, batch_id: BatchJobId) { self.batches.mark_proven(batch_id); } /// Select at most `count` batches which are ready to be placed into the next block. /// /// May return an empty batch set if no batches are ready. - pub fn select_block(&mut self, count: usize) -> (BlockNumber, Vec) { + pub fn select_block(&mut self, count: usize) -> (BlockNumber, Vec) { // TODO: should return actual batch transaction data as well. let mut batches = Vec::with_capacity(count); diff --git a/crates/block-producer/src/mempool/transaction_graph.rs b/crates/block-producer/src/mempool/transaction_graph.rs index 2d37af0b..401c6628 100644 --- a/crates/block-producer/src/mempool/transaction_graph.rs +++ b/crates/block-producer/src/mempool/transaction_graph.rs @@ -5,7 +5,7 @@ use std::{ use miden_objects::transaction::{ProvenTransaction, TransactionId}; -use super::BatchId; +use super::BatchJobId; #[derive(Default, Clone, Debug)] pub struct TransactionGraph {