From 163efc3bdf4671eef5105a6fbfb57f48110b8e0c Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 2 Mar 2021 19:20:55 +0000 Subject: [PATCH] coalesces vote packets into one Packets (#15566) (#15630) (cherry picked from commit f7a049f87f83093df1bff6855bf18880e04564b6) Co-authored-by: behzad nouri --- core/src/cluster_info_vote_listener.rs | 2 +- core/src/verified_vote_packets.rs | 25 ++++++++++--------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/core/src/cluster_info_vote_listener.rs b/core/src/cluster_info_vote_listener.rs index f89cc16424..97ebbfd1ea 100644 --- a/core/src/cluster_info_vote_listener.rs +++ b/core/src/cluster_info_vote_listener.rs @@ -397,7 +397,7 @@ impl ClusterInfoVoteListener { if let Some(bank) = bank { let last_version = bank.last_vote_sync.load(Ordering::Relaxed); let (new_version, msgs) = verified_vote_packets.get_latest_votes(last_version); - verified_packets_sender.send(msgs)?; + verified_packets_sender.send(vec![msgs])?; #[allow(deprecated)] bank.last_vote_sync.compare_and_swap( last_version, diff --git a/core/src/verified_vote_packets.rs b/core/src/verified_vote_packets.rs index ae2087dbe3..2d186afc3d 100644 --- a/core/src/verified_vote_packets.rs +++ b/core/src/verified_vote_packets.rs @@ -33,22 +33,18 @@ impl VerifiedVotePackets { self.0.get(key) } - pub fn get_latest_votes(&self, last_update_version: u64) -> (u64, Vec) { + pub fn get_latest_votes(&self, last_update_version: u64) -> (u64, Packets) { let mut new_update_version = last_update_version; - let msgs: Vec<_> = self + let packets = self .0 - .iter() - .filter_map(|(_, (msg_update_version, msg))| { - if *msg_update_version > last_update_version { - new_update_version = std::cmp::max(*msg_update_version, new_update_version); - Some(msg) - } else { - None - } + .values() + .filter(|(v, _)| *v > last_update_version) + .flat_map(|(v, packets)| { + new_update_version = std::cmp::max(*v, new_update_version); + packets.packets.clone() }) - .cloned() .collect(); - (new_update_version, msgs) + (new_update_version, Packets::new(packets)) } } @@ -86,13 +82,12 @@ mod tests { // Both updates have timestamps greater than 0, so both should be returned let (new_update_version, updates) = verified_vote_packets.get_latest_votes(0); assert_eq!(new_update_version, 2); - assert_eq!(updates.len(), 2); + assert_eq!(updates.packets.len(), 2); // Only the nonempty packet had a timestamp greater than 1 let (new_update_version, updates) = verified_vote_packets.get_latest_votes(1); assert_eq!(new_update_version, 2); - assert_eq!(updates.len(), 1); - assert_eq!(updates[0].packets.is_empty(), false); + assert_eq!(updates.packets.is_empty(), false); // If the given timestamp is greater than all timestamps in any update, // returned timestamp should be the same as the given timestamp, and