From 9bc27485903e55706345998956c24d5783abf689 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Sat, 23 Nov 2024 10:27:52 +0100 Subject: [PATCH] fix(iota-network): `PeerBalancer::new` peers total order --- crates/iota-network/src/state_sync/mod.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/iota-network/src/state_sync/mod.rs b/crates/iota-network/src/state_sync/mod.rs index 6334c9e6b4e..b4658b4d9e2 100644 --- a/crates/iota-network/src/state_sync/mod.rs +++ b/crates/iota-network/src/state_sync/mod.rs @@ -314,13 +314,18 @@ impl PeerBalancer { .unwrap() .peers_on_same_chain() // Filter out any peers who we aren't connected with. - .filter_map(|(peer_id, info)| network.peer(*peer_id).map(|peer| (peer, *info))) + .filter_map(|(peer_id, info)| { + network + .peer(*peer_id) + .map(|peer| (peer.connection_rtt(), peer, *info)) + }) .collect(); - peers.sort_by(|(peer_a, _), (peer_b, _)| { - peer_a.connection_rtt().cmp(&peer_b.connection_rtt()) - }); + peers.sort_by(|(rtt_a, _, _), (rtt_b, _, _)| rtt_a.cmp(rtt_b)); Self { - peers: peers.into(), + peers: peers + .into_iter() + .map(|(_, peer, info)| (peer, info)) + .collect(), requested_checkpoint: None, request_type, }