do not count dialing peers in the connection limit (#2856)

## Issue Addressed
#2841 

## Proposed Changes
Not counting dialing peers while deciding if we have reached the target peers in case of outbound peers.

## Additional Info
Checked this running in nodes and bandwidth looks normal, peer count looks normal too
This commit is contained in:
Divma 2021-12-15 05:48:45 +00:00
parent 52c69c4eee
commit eee0260a68
2 changed files with 11 additions and 12 deletions

View File

@ -350,8 +350,13 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
/// 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.

View File

@ -112,15 +112,7 @@ impl<TSpec: EthSpec> NetworkBehaviour for PeerManager<TSpec> {
_failed_addresses: Option<&Vec<Multiaddr>>,
) {
// 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<TSpec: EthSpec> NetworkBehaviour for PeerManager<TSpec> {
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