From adf935830e2c0bb0a427fbb8bba490f04dd4be6f Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Date: Wed, 19 Jul 2023 18:04:08 +0200 Subject: [PATCH] Do not remove entry cache when the threshold is reached (#266) Co-authored-by: Gusto --- simulations/src/node/carnot/tally.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/simulations/src/node/carnot/tally.rs b/simulations/src/node/carnot/tally.rs index 00bc5324..5902e7e0 100644 --- a/simulations/src/node/carnot/tally.rs +++ b/simulations/src/node/carnot/tally.rs @@ -1,18 +1,18 @@ use consensus_engine::View; use std::collections::{HashMap, HashSet}; -pub(crate) struct Tally { +pub(crate) struct Tally { cache: HashMap>, threshold: usize, } -impl Default for Tally { +impl Default for Tally { fn default() -> Self { Self::new(2) } } -impl Tally { +impl Tally { pub fn new(threshold: usize) -> Self { Self { cache: Default::default(), @@ -27,9 +27,9 @@ impl Tally { pub fn tally_by(&mut self, view: View, message: T, threshold: usize) -> Option> { let entries = self.cache.entry(view).or_default(); entries.insert(message); - let entries = entries.len(); - if entries == threshold { - Some(self.cache.remove(&view).unwrap()) + let entries_len = entries.len(); + if entries_len == threshold { + Some(entries.clone()) } else { None }