diff --git a/node/bft/src/helpers/ready.rs b/node/bft/src/helpers/ready.rs index 6fa581ccdb..7a366dff81 100644 --- a/node/bft/src/helpers/ready.rs +++ b/node/bft/src/helpers/ready.rs @@ -126,6 +126,14 @@ impl Ready { // Drain the transmission IDs. transmissions.drain(range).collect::>() } + + /// Clears all solutions from the ready queue. + pub(crate) fn clear_solutions(&self) { + // Acquire the write lock. + let mut transmissions = self.transmissions.write(); + // Remove all solutions. + transmissions.retain(|id, _| !matches!(id, TransmissionID::Solution(..))); + } } #[cfg(test)] diff --git a/node/bft/src/primary.rs b/node/bft/src/primary.rs index 05069d2aa4..d90576a2f9 100644 --- a/node/bft/src/primary.rs +++ b/node/bft/src/primary.rs @@ -319,6 +319,13 @@ impl Primary { } } +impl Primary { + /// Clears the worker solutions. + pub fn clear_worker_solutions(&self) { + self.workers.iter().for_each(Worker::clear_solutions); + } +} + impl Primary { /// Proposes the batch for the current round. /// diff --git a/node/bft/src/worker.rs b/node/bft/src/worker.rs index dc82d775ce..96a3f71622 100644 --- a/node/bft/src/worker.rs +++ b/node/bft/src/worker.rs @@ -151,6 +151,13 @@ impl Worker { } } +impl Worker { + /// Clears the solutions from the ready queue. + pub(super) fn clear_solutions(&self) { + self.ready.clear_solutions() + } +} + impl Worker { /// Returns `true` if the transmission ID exists in the ready queue, proposed batch, storage, or ledger. pub fn contains_transmission(&self, transmission_id: impl Into>) -> bool { diff --git a/node/consensus/src/lib.rs b/node/consensus/src/lib.rs index 530893893d..fdf247dfdd 100644 --- a/node/consensus/src/lib.rs +++ b/node/consensus/src/lib.rs @@ -484,6 +484,14 @@ impl Consensus { // Advance to the next block. self.ledger.advance_to_next_block(&next_block)?; + // If the next block starts a new epoch, clear the existing solutions. + if next_block.height() % N::NUM_BLOCKS_PER_EPOCH == 0 { + // Clear the solutions queue. + self.solutions_queue.lock().clear(); + // Clear the worker solutions. + self.bft.primary().clear_worker_solutions(); + } + #[cfg(feature = "metrics")] { let elapsed = std::time::Duration::from_secs((snarkos_node_bft::helpers::now() - start) as u64);