From 1e001a7c7da95cc9aa2f58be3a369276a878b6c9 Mon Sep 17 00:00:00 2001 From: Shariq Naiyer Date: Sun, 22 Feb 2026 19:01:36 -0700 Subject: [PATCH] fix: case when tally is equal common_highest_checkpoint --- crates/networking/network_state/lean/src/lib.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/crates/networking/network_state/lean/src/lib.rs b/crates/networking/network_state/lean/src/lib.rs index d21d68bca..b69ffad31 100644 --- a/crates/networking/network_state/lean/src/lib.rs +++ b/crates/networking/network_state/lean/src/lib.rs @@ -82,8 +82,6 @@ impl NetworkState { pub fn common_highest_checkpoint(&self) -> Option { let peer_table = self.peer_table.lock(); - let mut common_checkpoint: Option = None; - let mut checkpoint_tally: HashMap = HashMap::new(); for peer in peer_table.values() { if let (ConnectionState::Connected, Some(head_checkpoint)) = @@ -92,15 +90,11 @@ impl NetworkState { *checkpoint_tally.entry(*head_checkpoint).or_insert(0) += 1; } } - let mut highest_tally = 0; - for (checkpoint, tally) in checkpoint_tally { - if tally > highest_tally { - highest_tally = tally; - common_checkpoint = Some(checkpoint); - } - } - common_checkpoint + checkpoint_tally + .into_iter() + .max_by_key(|(checkpoint, tally)| (*tally, checkpoint.slot)) + .map(|(checkpoint, _)| checkpoint) } pub fn successful_response_from_peer(&self, peer_id: PeerId) {