From 44b1d15dc8b58c1c937bea7a088369b7231d0929 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Sat, 29 May 2021 10:37:25 +1000 Subject: [PATCH] Revert "More stringent dialing (#2363)" This reverts commit 55aada006f831e8140a7a2a6b16e280061408699. --- .../eth2_libp2p/src/peer_manager/mod.rs | 21 ++++++++++++++----- .../eth2_libp2p/src/peer_manager/peerdb.rs | 12 +---------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/beacon_node/eth2_libp2p/src/peer_manager/mod.rs b/beacon_node/eth2_libp2p/src/peer_manager/mod.rs index 659c8d9a392..3269fbf26ea 100644 --- a/beacon_node/eth2_libp2p/src/peer_manager/mod.rs +++ b/beacon_node/eth2_libp2p/src/peer_manager/mod.rs @@ -668,16 +668,18 @@ impl PeerManager { .cached_enrs() .filter_map(|(peer_id, enr)| { let peers = self.network_globals.peers.read(); - if predicate(enr) && peers.should_dial(peer_id) { + if predicate(enr) + && !peers.is_connected_or_dialing(peer_id) + && !peers.is_banned(peer_id) + { Some(*peer_id) } else { None } }) .collect(); - for peer_id in &peers_to_dial { - debug!(self.log, "Dialing cached ENR peer"; "peer_id" => %peer_id); - self.dial_peer(peer_id); + for peer in &peers_to_dial { + self.dial_peer(peer); } } @@ -696,7 +698,16 @@ impl PeerManager { // we attempt a connection if this peer is a subnet peer or if the max peer count // is not yet filled (including dialing peers) if (min_ttl.is_some() || connected_or_dialing + to_dial_peers.len() < self.max_peers) - && self.network_globals.peers.read().should_dial(&peer_id) + && !self + .network_globals + .peers + .read() + .is_connected_or_dialing(&peer_id) + && !self + .network_globals + .peers + .read() + .is_banned_or_disconnected(&peer_id) { // This should be updated with the peer dialing. In fact created once the peer is // dialed diff --git a/beacon_node/eth2_libp2p/src/peer_manager/peerdb.rs b/beacon_node/eth2_libp2p/src/peer_manager/peerdb.rs index 44fcedbbd45..6803f49ed11 100644 --- a/beacon_node/eth2_libp2p/src/peer_manager/peerdb.rs +++ b/beacon_node/eth2_libp2p/src/peer_manager/peerdb.rs @@ -153,16 +153,6 @@ impl PeerDB { ) } - /// Returns true if the peer should be dialed. This checks the connection state and the - /// score state and determines if the peer manager should dial this peer. - pub fn should_dial(&self, peer_id: &PeerId) -> bool { - matches!( - self.connection_status(peer_id), - Some(PeerConnectionStatus::Disconnected { .. }) - | Some(PeerConnectionStatus::Unknown { .. }) - ) && !self.is_banned_or_disconnected(peer_id) - } - /// Returns true if the peer is synced at least to our current head. pub fn is_synced(&self, peer_id: &PeerId) -> bool { match self.peers.get(peer_id).map(|info| &info.sync_status) { @@ -351,7 +341,7 @@ impl PeerDB { } if let Err(e) = info.dialing_peer() { - error!(self.log, "{}", e; "peer_id" => %peer_id); + error!(self.log, "{}", e); } }