From bb00b262d7f8408240fd1086bc405e628db3ad77 Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 27 Feb 2023 14:43:15 +0400 Subject: [PATCH] [client/network] Remove unused argument (#13444) * improve error message * removed unused argument * docs: disconnect_peer_inner no longer accepts `ban` * remove redundant trace message ``` sync: Too many full nodes, rejecting 12D3KooWSQAP2fh4qBkLXBW4mvCtbAiK8sqMnExWHHTZtVAxZ8bQ sync: 12D3KooWSQAP2fh4qBkLXBW4mvCtbAiK8sqMnExWHHTZtVAxZ8bQ disconnected ``` is enough to understand that we've refused to connect to the given peer * Revert "removed unused argument" This reverts commit c87f755b1fd03494fb446b604fe25c2418da7c87. * ban peer for 10s after disconnect * do not accept incoming conns if peer was banned * Revert "do not accept incoming conns if peer was banned" This reverts commit 7e59d05975765f2547468e9dcfd1361516c41e06. * Revert "ban peer for 10s after disconnect" This reverts commit 3859201ced42a5b2d18c0600e29efd20962a7289. * Revert "Revert "removed unused argument"" This reverts commit f1dc623646dc5a69e1822c35f428e90dffe34d95. * format code * Revert "remove redundant trace message" This reverts commit a87e65f08553dbe69027e9aa4f7ca4779ccaa7f2. --- .../src/protocol/notifications/behaviour.rs | 30 ++++--------------- substrate/client/network/sync/src/lib.rs | 2 +- 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/substrate/client/network/src/protocol/notifications/behaviour.rs b/substrate/client/network/src/protocol/notifications/behaviour.rs index ebfb95afae..027ea0ab53 100644 --- a/substrate/client/network/src/protocol/notifications/behaviour.rs +++ b/substrate/client/network/src/protocol/notifications/behaviour.rs @@ -415,17 +415,11 @@ impl Notifications { /// Disconnects the given peer if we are connected to it. pub fn disconnect_peer(&mut self, peer_id: &PeerId, set_id: sc_peerset::SetId) { trace!(target: "sub-libp2p", "External API => Disconnect({}, {:?})", peer_id, set_id); - self.disconnect_peer_inner(peer_id, set_id, None); + self.disconnect_peer_inner(peer_id, set_id); } - /// Inner implementation of `disconnect_peer`. If `ban` is `Some`, we ban the peer - /// for the specific duration. - fn disconnect_peer_inner( - &mut self, - peer_id: &PeerId, - set_id: sc_peerset::SetId, - ban: Option, - ) { + /// Inner implementation of `disconnect_peer`. + fn disconnect_peer_inner(&mut self, peer_id: &PeerId, set_id: sc_peerset::SetId) { let mut entry = if let Entry::Occupied(entry) = self.peers.entry((*peer_id, set_id)) { entry } else { @@ -443,12 +437,8 @@ impl Notifications { PeerState::DisabledPendingEnable { connections, timer_deadline, timer: _ } => { trace!(target: "sub-libp2p", "PSM <= Dropped({}, {:?})", peer_id, set_id); self.peerset.dropped(set_id, *peer_id, DropReason::Unknown); - let backoff_until = Some(if let Some(ban) = ban { - cmp::max(timer_deadline, Instant::now() + ban) - } else { - timer_deadline - }); - *entry.into_mut() = PeerState::Disabled { connections, backoff_until } + *entry.into_mut() = + PeerState::Disabled { connections, backoff_until: Some(timer_deadline) } }, // Enabled => Disabled. @@ -496,8 +486,7 @@ impl Notifications { .iter() .any(|(_, s)| matches!(s, ConnectionState::Opening))); - let backoff_until = ban.map(|dur| Instant::now() + dur); - *entry.into_mut() = PeerState::Disabled { connections, backoff_until } + *entry.into_mut() = PeerState::Disabled { connections, backoff_until: None } }, // Incoming => Disabled. @@ -532,13 +521,6 @@ impl Notifications { *connec_state = ConnectionState::Closing; } - let backoff_until = match (backoff_until, ban) { - (Some(a), Some(b)) => Some(cmp::max(a, Instant::now() + b)), - (Some(a), None) => Some(a), - (None, Some(b)) => Some(Instant::now() + b), - (None, None) => None, - }; - debug_assert!(!connections .iter() .any(|(_, s)| matches!(s, ConnectionState::OpenDesiredByRemote))); diff --git a/substrate/client/network/sync/src/lib.rs b/substrate/client/network/sync/src/lib.rs index 5c1496e751..f710215e74 100644 --- a/substrate/client/network/sync/src/lib.rs +++ b/substrate/client/network/sync/src/lib.rs @@ -1015,7 +1015,7 @@ where let peer = if let Some(peer) = self.peers.get_mut(&who) { peer } else { - error!(target: "sync", "💔 Called on_block_justification with a bad peer ID"); + error!(target: "sync", "💔 Called on_block_justification with a peer ID of an unknown peer"); return Ok(OnBlockJustification::Nothing) };