Simulation prune tally (#299)

* Add pruning methods

* Call pruning on node step method

* Fix tally retain closure
This commit is contained in:
Daniel Sanchez 2023-08-10 13:12:48 +02:00 committed by GitHub
parent da60d8fc95
commit ef5935d572
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 0 deletions

View File

@ -36,6 +36,15 @@ impl EventBuilder {
}
}
/// At some point we need to clear old votes or RAM just goes brrrrrr
pub fn prune_by_view(&mut self, view: View) {
self.vote_message.prune(view);
self.leader_vote_message.prune(view);
self.timeout_message.prune(view);
self.leader_new_view_message.prune(view);
self.new_view_message.prune(view);
}
fn local_timeout(&mut self, view: View, elapsed: Duration) -> bool {
if self.timeout_handler.step(view, elapsed) {
self.timeout_handler.prune_by_view(view);

View File

@ -533,6 +533,8 @@ impl<
|| matches!(m, CarnotMessage::Proposal(_) | CarnotMessage::TimeoutQc(_))
});
self.message_cache.prune(self.engine.current_view().prev());
self.event_builder
.prune_by_view(self.engine.current_view().prev());
self.message_cache.update(other_view_messages);
current_view_messages.append(&mut self.message_cache.retrieve(self.engine.current_view()));

View File

@ -22,4 +22,8 @@ impl<T: core::hash::Hash + Eq + Clone> Tally<T> {
None
}
}
pub fn prune(&mut self, view: View) {
self.cache.retain(|v, _| v > &view);
}
}