diff --git a/beacon_node/eth2_libp2p/src/peer_manager/mod.rs b/beacon_node/eth2_libp2p/src/peer_manager/mod.rs index 9aa041000e9..95be059f45c 100644 --- a/beacon_node/eth2_libp2p/src/peer_manager/mod.rs +++ b/beacon_node/eth2_libp2p/src/peer_manager/mod.rs @@ -13,7 +13,7 @@ use futures::Stream; use hashset_delay::HashSetDelay; use libp2p::core::ConnectedPoint; use libp2p::identify::IdentifyInfo; -use slog::{crit, debug, error, warn}; +use slog::{debug, error, warn}; use smallvec::SmallVec; use std::{ pin::Pin, @@ -529,7 +529,7 @@ impl PeerManager { }; } } else { - crit!(self.log, "Received an Identify response from an unknown peer"; "peer_id" => peer_id.to_string()); + error!(self.log, "Received an Identify response from an unknown peer"; "peer_id" => peer_id.to_string()); } } @@ -672,7 +672,7 @@ impl PeerManager { self.events.push(PeerManagerEvent::MetaData(*peer_id)); } } else { - crit!(self.log, "Received a PING from an unknown peer"; + error!(self.log, "Received a PING from an unknown peer"; "peer_id" => %peer_id); } } @@ -696,7 +696,7 @@ impl PeerManager { self.events.push(PeerManagerEvent::MetaData(*peer_id)); } } else { - crit!(self.log, "Received a PONG from an unknown peer"; "peer_id" => %peer_id); + error!(self.log, "Received a PONG from an unknown peer"; "peer_id" => %peer_id); } } @@ -720,7 +720,7 @@ impl PeerManager { } peer_info.meta_data = Some(meta_data); } else { - crit!(self.log, "Received METADATA from an unknown peer"; + error!(self.log, "Received METADATA from an unknown peer"; "peer_id" => %peer_id); } } @@ -842,7 +842,7 @@ impl PeerManager { let mut peerdb = self.network_globals.peers.write(); if !matches!(peerdb.ban_status(peer_id), BanResult::NotBanned) { // don't connect if the peer is banned - slog::crit!(self.log, "Connection has been allowed to a banned peer"; "peer_id" => %peer_id); + error!(self.log, "Connection has been allowed to a banned peer"; "peer_id" => %peer_id); } match connection { diff --git a/beacon_node/eth2_libp2p/src/peer_manager/peerdb.rs b/beacon_node/eth2_libp2p/src/peer_manager/peerdb.rs index 7506b94ebae..542ba07e724 100644 --- a/beacon_node/eth2_libp2p/src/peer_manager/peerdb.rs +++ b/beacon_node/eth2_libp2p/src/peer_manager/peerdb.rs @@ -515,10 +515,15 @@ impl PeerDB { /// Notifies the peer manager that the peer is undergoing a normal disconnect. Optionally tag /// the peer to be banned after the disconnect. pub fn notify_disconnecting(&mut self, peer_id: PeerId, to_ban_afterwards: bool) { - self.peers - .entry(peer_id) - .or_default() - .disconnecting(to_ban_afterwards); + let peer_info = self.peers.entry(peer_id).or_default(); + + if matches!( + peer_info.connection_status(), + PeerConnectionStatus::Disconnected { .. } + ) { + self.disconnected_peers = self.disconnected_peers.saturating_sub(1); + } + peer_info.disconnecting(to_ban_afterwards); } /// Marks a peer to be disconnected and then banned. @@ -609,7 +614,7 @@ impl PeerDB { info.update_state(); // This transitions a banned peer to a disconnected peer - self.disconnected_peers = self.disconnected_peers.saturating_add(1); + self.disconnected_peers = self.disconnected_peers().count().saturating_add(1); self.shrink_to_fit(); Ok(()) } diff --git a/beacon_node/eth2_libp2p/src/service.rs b/beacon_node/eth2_libp2p/src/service.rs index 278b16216b8..66bec0db4fb 100644 --- a/beacon_node/eth2_libp2p/src/service.rs +++ b/beacon_node/eth2_libp2p/src/service.rs @@ -138,14 +138,14 @@ impl Service { .with_max_established_incoming(Some( (config.target_peers as f32 * (1.0 + PEER_EXCESS_FACTOR - MIN_OUTBOUND_ONLY_FACTOR)) - as u32, + .ceil() as u32, )) .with_max_established_outgoing(Some( - (config.target_peers as f32 * (1.0 + PEER_EXCESS_FACTOR)) as u32, + (config.target_peers as f32 * (1.0 + PEER_EXCESS_FACTOR)).ceil() as u32, )) .with_max_established(Some( (config.target_peers as f32 * (1.0 + PEER_EXCESS_FACTOR + PRIORITY_PEER_EXCESS)) - as u32, + .ceil() as u32, )) .with_max_established_per_peer(Some(MAX_CONNECTIONS_PER_PEER)); diff --git a/beacon_node/network/src/sync/manager.rs b/beacon_node/network/src/sync/manager.rs index f6d5a954db0..3b04ec21f2d 100644 --- a/beacon_node/network/src/sync/manager.rs +++ b/beacon_node/network/src/sync/manager.rs @@ -672,7 +672,7 @@ impl SyncManager { } peer_info.is_connected() } else { - crit!(self.log, "Status'd peer is unknown"; "peer_id" => %peer_id); + error!(self.log, "Status'd peer is unknown"; "peer_id" => %peer_id); false } }