diff --git a/consensus-engine/src/lib.rs b/consensus-engine/src/lib.rs index db467c34..371c8c26 100644 --- a/consensus-engine/src/lib.rs +++ b/consensus-engine/src/lib.rs @@ -220,7 +220,7 @@ impl Carnot { ) } - /// Upon a configurable amout of time has elapsed since the last view change + /// Upon a configurable amount of time has elapsed since the last view change /// /// Preconditions: none! /// Just notice that the timer only reset after a view change, i.e. a node can't timeout @@ -396,6 +396,12 @@ impl Carnot { Err(e) => Err(e), } } + + /// Blocks newer than the last committed block are not safe to be pruned + pub fn prune_older_blocks_by_view(&mut self, threshold_view: View) { + assert!(threshold_view < self.latest_committed_block().view); + self.safe_blocks.retain(|_, b| b.view < threshold_view); + } } #[cfg(test)] diff --git a/simulations/src/node/carnot/mod.rs b/simulations/src/node/carnot/mod.rs index efc8042b..5b6484a5 100644 --- a/simulations/src/node/carnot/mod.rs +++ b/simulations/src/node/carnot/mod.rs @@ -389,8 +389,20 @@ impl> CarnotNode qc.view, + Qc::Aggregated(qc) => { + self.engine + .safe_blocks() + .get(&qc.high_qc.id) + .expect("Parent block must be present") + .view + } + } - View::new(3); + let (mut new, out) = self.engine.approve_block(block); tracing::info!(vote=?out, node=%self.id); + // pruning old blocks older than the grandparent block needed to check validity + new.prune_older_blocks_by_view(block_grandparent_view); output = Some(Output::Send(out)); self.engine = new; }