From bf7960c87a261a167e6baec84eab1d26df645306 Mon Sep 17 00:00:00 2001 From: mempirate Date: Wed, 26 Apr 2023 14:08:20 +0200 Subject: [PATCH] fix(peers): rank dial candidates by reputation only (#2407) --- crates/net/network/src/peers/manager.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/crates/net/network/src/peers/manager.rs b/crates/net/network/src/peers/manager.rs index 65dcbd5add..88fede0077 100644 --- a/crates/net/network/src/peers/manager.rs +++ b/crates/net/network/src/peers/manager.rs @@ -610,7 +610,7 @@ impl PeersManager { /// Returns the idle peer with the highest reputation. /// /// Peers that are `trusted`, see [PeerKind], are prioritized as long as they're not currently - /// marked as banned. Peers with a `forkId` are considered better than peers without. + /// marked as banned. /// /// If `connect_trusted_nodes_only` is enabled, see [PeersConfig], then this will only consider /// `trusted` peers. @@ -631,19 +631,14 @@ impl PeersManager { } for maybe_better in unconnected { + // if the peer is trusted, return it immediately if maybe_better.1.is_trusted() { return Some((*maybe_better.0, maybe_better.1)) } - match (maybe_better.1.fork_id.as_ref(), best_peer.1.fork_id.as_ref()) { - (Some(_), Some(_)) | (None, None) => { - if maybe_better.1.reputation > best_peer.1.reputation { - best_peer = maybe_better; - } - } - (Some(_), None) => { - best_peer = maybe_better; - } - _ => {} + + // otherwise we keep track of the best peer using the reputation + if maybe_better.1.reputation > best_peer.1.reputation { + best_peer = maybe_better; } } Some((*best_peer.0, best_peer.1))