diff --git a/beacon_node/lighthouse_network/src/peer_manager/mod.rs b/beacon_node/lighthouse_network/src/peer_manager/mod.rs index fa33ea9ff..d8de221dd 100644 --- a/beacon_node/lighthouse_network/src/peer_manager/mod.rs +++ b/beacon_node/lighthouse_network/src/peer_manager/mod.rs @@ -350,8 +350,13 @@ impl PeerManager { /// Reports whether the peer limit is reached in which case we stop allowing new incoming /// connections. - pub fn peer_limit_reached(&self) -> bool { - self.network_globals.connected_or_dialing_peers() >= self.max_peers() + pub fn peer_limit_reached(&self, count_dialing: bool) -> bool { + let max_peers = self.max_peers(); + if count_dialing { + self.network_globals.connected_or_dialing_peers() >= max_peers + } else { + self.network_globals.connected_peers() >= max_peers + } } /// Updates `PeerInfo` with `identify` information. diff --git a/beacon_node/lighthouse_network/src/peer_manager/network_behaviour.rs b/beacon_node/lighthouse_network/src/peer_manager/network_behaviour.rs index c8b062da4..a11f3739e 100644 --- a/beacon_node/lighthouse_network/src/peer_manager/network_behaviour.rs +++ b/beacon_node/lighthouse_network/src/peer_manager/network_behaviour.rs @@ -112,15 +112,7 @@ impl NetworkBehaviour for PeerManager { _failed_addresses: Option<&Vec>, ) { // Log the connection - match &endpoint { - ConnectedPoint::Listener { .. } => { - debug!(self.log, "Connection established"; "peer_id" => %peer_id, "connection" => "Incoming"); - } - ConnectedPoint::Dialer { .. } => { - debug!(self.log, "Connection established"; "peer_id" => %peer_id, "connection" => "Outgoing"); - // TODO: Ensure we have that address registered. - } - } + debug!(self.log, "Connection established"; "peer_id" => %peer_id, "connection" => ?endpoint.to_endpoint()); // Check to make sure the peer is not supposed to be banned match self.ban_status(peer_id) { @@ -142,8 +134,10 @@ impl NetworkBehaviour for PeerManager { BanResult::NotBanned => {} } + // Count dialing peers in the limit if the peer dialied us. + let count_dialing = endpoint.is_listener(); // Check the connection limits - if self.peer_limit_reached() + if self.peer_limit_reached(count_dialing) && self .network_globals .peers