Prune blocks in consensus engine (#275)

* Add prune older blocks call

* Prune older blocks in simulation app

* Use latest safe view for failure case

* Pick parent view from high qc

* Add safety assertion on pruning method
This commit is contained in:
Daniel Sanchez 2023-08-01 16:47:47 +02:00 committed by GitHub
parent ae59be5466
commit fac42cd31d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -220,7 +220,7 @@ impl<O: Overlay> Carnot<O> {
)
}
/// 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<O: Overlay> Carnot<O> {
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)]

View File

@ -389,8 +389,20 @@ impl<L: UpdateableLeaderSelection, O: Overlay<LeaderSelection = L>> CarnotNode<O
parent_block=%block.parent(),
"receive approve message"
);
let (new, out) = self.engine.approve_block(block);
let block_grandparent_view = match &block.parent_qc {
Qc::Standard(qc) => 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;
}