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 }