From 489fe01787a84b6180e7c8994b292d4ec8b4fea0 Mon Sep 17 00:00:00 2001 From: Jan Bujak Date: Thu, 17 Feb 2022 13:38:58 +0000 Subject: [PATCH 1/5] Simplify `num_connected_peers` --- client/network/src/protocol.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/network/src/protocol.rs b/client/network/src/protocol.rs index b39d0d1b8428b..38f7a01a0890a 100644 --- a/client/network/src/protocol.rs +++ b/client/network/src/protocol.rs @@ -496,7 +496,7 @@ impl Protocol { /// Returns the number of peers we're connected to. pub fn num_connected_peers(&self) -> usize { - self.peers.values().count() + self.peers.len() } /// Returns the number of peers we're connected to and that are being queried. From 9f1c8704353df6afc17ed7e9f4ab8d8e29466ae4 Mon Sep 17 00:00:00 2001 From: Jan Bujak Date: Thu, 17 Feb 2022 13:40:07 +0000 Subject: [PATCH 2/5] Track requested peer counts --- client/network/src/protocol.rs | 6 +- .../src/protocol/notifications/behaviour.rs | 83 +++++++++++++++++-- client/network/src/service.rs | 8 +- 3 files changed, 81 insertions(+), 16 deletions(-) diff --git a/client/network/src/protocol.rs b/client/network/src/protocol.rs index 38f7a01a0890a..04780dd412f2a 100644 --- a/client/network/src/protocol.rs +++ b/client/network/src/protocol.rs @@ -465,10 +465,10 @@ impl Protocol { self.behaviour.open_peers() } - /// Returns the list of all the peers that the peerset currently requests us to be connected + /// Returns the number of all the peers that the peerset currently requests us to be connected /// to on the default set. - pub fn requested_peers(&self) -> impl Iterator { - self.behaviour.requested_peers(HARDCODED_PEERSETS_SYNC) + pub fn requested_peers_count(&self) -> usize { + self.behaviour.requested_peers_count(HARDCODED_PEERSETS_SYNC) } /// Returns the number of discovered nodes that we keep in memory. diff --git a/client/network/src/protocol/notifications/behaviour.rs b/client/network/src/protocol/notifications/behaviour.rs index 97047201c308c..0bd579bcc97ed 100644 --- a/client/network/src/protocol/notifications/behaviour.rs +++ b/client/network/src/protocol/notifications/behaviour.rs @@ -110,6 +110,10 @@ pub struct Notifications { /// List of peers in our state. peers: FnvHashMap<(PeerId, sc_peerset::SetId), PeerState>, + /// A map containing the number of all the peers that the peerset currently requests us to be + /// connected to. + requested_peer_counts: FnvHashMap, + /// The elements in `peers` occasionally contain `Delay` objects that we would normally have /// to be polled one by one. In order to avoid doing so, as an optimization, every `Delay` is /// instead put inside of `delays` and reference by a [`DelayId`]. This stream @@ -363,6 +367,32 @@ pub enum NotificationsOut { }, } +fn increment_requested_peer_counts( + requested_peer_counts: &mut FnvHashMap, + set_id: sc_peerset::SetId, +) { + *requested_peer_counts.entry(set_id).or_insert(0) += 1; +} + +fn decrement_requested_peer_counts( + requested_peer_counts: &mut FnvHashMap, + set_id: sc_peerset::SetId, +) { + match requested_peer_counts.entry(set_id) { + Entry::Occupied(mut entry) => { + let value = entry.get_mut(); + if *value == 1 { + entry.remove(); + } else { + *value -= 1; + } + }, + Entry::Vacant(..) => { + warn!(target: "sub-libp2p", "Underflow of requested peer count for {:?}", set_id) + }, + } +} + impl Notifications { /// Creates a `CustomProtos`. pub fn new( @@ -384,6 +414,7 @@ impl Notifications { notif_protocols, peerset, peers: FnvHashMap::default(), + requested_peer_counts: Default::default(), delays: Default::default(), next_delay_id: DelayId(0), incoming: SmallVec::new(), @@ -457,6 +488,7 @@ impl Notifications { } else { timer_deadline }); + decrement_requested_peer_counts(&mut self.requested_peer_counts, set_id); *entry.into_mut() = PeerState::Disabled { connections, backoff_until } }, @@ -506,6 +538,7 @@ impl Notifications { .any(|(_, s)| matches!(s, ConnectionState::Opening))); let backoff_until = ban.map(|dur| Instant::now() + dur); + decrement_requested_peer_counts(&mut self.requested_peer_counts, set_id); *entry.into_mut() = PeerState::Disabled { connections, backoff_until } }, @@ -560,15 +593,18 @@ impl Notifications { } } - /// Returns the list of all the peers that the peerset currently requests us to be connected to. - pub fn requested_peers<'a>( - &'a self, - set_id: sc_peerset::SetId, - ) -> impl Iterator + 'a { - self.peers - .iter() - .filter(move |((_, set), state)| *set == set_id && state.is_requested()) - .map(|((id, _), _)| id) + /// Returns the number of all the peers that the peerset currently requests us to be connected + /// to. + pub fn requested_peers_count(&self, set_id: sc_peerset::SetId) -> usize { + let count = self.requested_peer_counts.get(&set_id).copied().unwrap_or(0); + debug_assert_eq!( + self.peers + .iter() + .filter(move |((_, set), state)| *set == set_id && state.is_requested()) + .count(), + count + ); + count } /// Returns the list of reserved peers. @@ -647,6 +683,7 @@ impl Notifications { condition: DialPeerCondition::Disconnected, handler, }); + increment_requested_peer_counts(&mut self.requested_peer_counts, set_id); entry.insert(PeerState::Requested); return }, @@ -665,6 +702,7 @@ impl Notifications { set_id, timer_deadline, ); + increment_requested_peer_counts(&mut self.requested_peer_counts, set_id); *occ_entry.into_mut() = PeerState::PendingRequest { timer: *timer, timer_deadline: *timer_deadline }; }, @@ -684,6 +722,7 @@ impl Notifications { condition: DialPeerCondition::Disconnected, handler, }); + increment_requested_peer_counts(&mut self.requested_peer_counts, set_id); *occ_entry.into_mut() = PeerState::Requested; }, @@ -711,6 +750,7 @@ impl Notifications { .boxed(), ); + increment_requested_peer_counts(&mut self.requested_peer_counts, set_id); *occ_entry.into_mut() = PeerState::DisabledPendingEnable { connections, timer: delay_id, @@ -737,6 +777,7 @@ impl Notifications { event: NotifsHandlerIn::Open { protocol_index: set_id.into() }, }); *connec_state = ConnectionState::Opening; + increment_requested_peer_counts(&mut self.requested_peer_counts, set_id); *occ_entry.into_mut() = PeerState::Enabled { connections }; } else { // If no connection is available, switch to `DisabledPendingEnable` in order @@ -771,6 +812,7 @@ impl Notifications { .boxed(), ); + increment_requested_peer_counts(&mut self.requested_peer_counts, set_id); *occ_entry.into_mut() = PeerState::DisabledPendingEnable { connections, timer: delay_id, @@ -813,6 +855,7 @@ impl Notifications { *connec_state = ConnectionState::Opening; } + increment_requested_peer_counts(&mut self.requested_peer_counts, set_id); *occ_entry.into_mut() = PeerState::Enabled { connections }; }, @@ -870,6 +913,7 @@ impl Notifications { trace!(target: "sub-libp2p", "PSM => Drop({}, {:?}): Interrupting pending enabling.", entry.key().0, set_id); + decrement_requested_peer_counts(&mut self.requested_peer_counts, set_id); *entry.into_mut() = PeerState::Disabled { connections, backoff_until: Some(timer_deadline) }; }, @@ -919,6 +963,7 @@ impl Notifications { *connec_state = ConnectionState::Closing; } + decrement_requested_peer_counts(&mut self.requested_peer_counts, set_id); *entry.into_mut() = PeerState::Disabled { connections, backoff_until: None } }, @@ -929,6 +974,8 @@ impl Notifications { // well at the same time. trace!(target: "sub-libp2p", "PSM => Drop({}, {:?}): Not yet connected.", entry.key().0, set_id); + + decrement_requested_peer_counts(&mut self.requested_peer_counts, set_id); entry.remove(); }, @@ -936,6 +983,8 @@ impl Notifications { PeerState::PendingRequest { timer, timer_deadline } => { trace!(target: "sub-libp2p", "PSM => Drop({}, {:?}): Not yet connected", entry.key().0, set_id); + + decrement_requested_peer_counts(&mut self.requested_peer_counts, set_id); *entry.into_mut() = PeerState::Backoff { timer, timer_deadline } }, @@ -1010,6 +1059,7 @@ impl Notifications { *connec_state = ConnectionState::Opening; } + increment_requested_peer_counts(&mut self.requested_peer_counts, incoming.set_id); *state = PeerState::Enabled { connections }; }, @@ -1230,6 +1280,7 @@ impl NetworkBehaviour for Notifications { if connections.is_empty() { trace!(target: "sub-libp2p", "PSM <= Dropped({}, {:?})", peer_id, set_id); self.peerset.dropped(set_id, *peer_id, DropReason::Unknown); + decrement_requested_peer_counts(&mut self.requested_peer_counts, set_id); *entry.get_mut() = PeerState::Backoff { timer, timer_deadline }; } else { *entry.get_mut() = @@ -1382,6 +1433,7 @@ impl NetworkBehaviour for Notifications { .boxed(), ); + decrement_requested_peer_counts(&mut self.requested_peer_counts, set_id); *entry.get_mut() = PeerState::Backoff { timer: delay_id, timer_deadline: Instant::now() + Duration::from_secs(ban_dur), @@ -1392,6 +1444,7 @@ impl NetworkBehaviour for Notifications { trace!(target: "sub-libp2p", "PSM <= Dropped({}, {:?})", peer_id, set_id); self.peerset.dropped(set_id, *peer_id, DropReason::Unknown); + decrement_requested_peer_counts(&mut self.requested_peer_counts, set_id); *entry.get_mut() = PeerState::Disabled { connections, backoff_until: None }; } else { *entry.get_mut() = PeerState::Enabled { connections }; @@ -1465,6 +1518,10 @@ impl NetworkBehaviour for Notifications { .boxed(), ); + decrement_requested_peer_counts( + &mut self.requested_peer_counts, + set_id, + ); *entry.into_mut() = PeerState::Backoff { timer: delay_id, timer_deadline: now + ban_duration, @@ -1751,6 +1808,10 @@ impl NetworkBehaviour for Notifications { { trace!(target: "sub-libp2p", "PSM <= Dropped({}, {:?})", source, set_id); self.peerset.dropped(set_id, source, DropReason::Refused); + decrement_requested_peer_counts( + &mut self.requested_peer_counts, + set_id, + ); *entry.into_mut() = PeerState::Disabled { connections, backoff_until: None }; } else { @@ -1928,6 +1989,10 @@ impl NetworkBehaviour for Notifications { self.peerset.dropped(set_id, source, DropReason::Refused); let ban_dur = Uniform::new(5, 10).sample(&mut rand::thread_rng()); + decrement_requested_peer_counts( + &mut self.requested_peer_counts, + set_id, + ); *entry.into_mut() = PeerState::Disabled { connections, backoff_until: Some(Instant::now() + Duration::from_secs(ban_dur)), diff --git a/client/network/src/service.rs b/client/network/src/service.rs index b6a1d3c88e7f3..8a0816831aeec 100644 --- a/client/network/src/service.rs +++ b/client/network/src/service.rs @@ -2108,10 +2108,10 @@ impl Future for NetworkWorker { .peerset_num_discovered .set(this.network_service.behaviour_mut().user_protocol().num_discovered_peers() as u64); - metrics.peerset_num_requested.set( - this.network_service.behaviour_mut().user_protocol().requested_peers().count() - as u64, - ); + metrics + .peerset_num_requested + .set(this.network_service.behaviour_mut().user_protocol().requested_peers_count() + as u64); metrics.pending_connections.set( Swarm::network_info(&this.network_service).connection_counters().num_pending() as u64, From 5d4eb05129a273ead2cbab1d340c4d32c29c9ee5 Mon Sep 17 00:00:00 2001 From: Jan Bujak Date: Fri, 18 Feb 2022 10:24:43 +0000 Subject: [PATCH 3/5] Revert "Track requested peer counts" This reverts commit 9f1c8704353df6afc17ed7e9f4ab8d8e29466ae4. --- client/network/src/protocol.rs | 6 +- .../src/protocol/notifications/behaviour.rs | 83 ++----------------- client/network/src/service.rs | 8 +- 3 files changed, 16 insertions(+), 81 deletions(-) diff --git a/client/network/src/protocol.rs b/client/network/src/protocol.rs index 04780dd412f2a..38f7a01a0890a 100644 --- a/client/network/src/protocol.rs +++ b/client/network/src/protocol.rs @@ -465,10 +465,10 @@ impl Protocol { self.behaviour.open_peers() } - /// Returns the number of all the peers that the peerset currently requests us to be connected + /// Returns the list of all the peers that the peerset currently requests us to be connected /// to on the default set. - pub fn requested_peers_count(&self) -> usize { - self.behaviour.requested_peers_count(HARDCODED_PEERSETS_SYNC) + pub fn requested_peers(&self) -> impl Iterator { + self.behaviour.requested_peers(HARDCODED_PEERSETS_SYNC) } /// Returns the number of discovered nodes that we keep in memory. diff --git a/client/network/src/protocol/notifications/behaviour.rs b/client/network/src/protocol/notifications/behaviour.rs index 0bd579bcc97ed..97047201c308c 100644 --- a/client/network/src/protocol/notifications/behaviour.rs +++ b/client/network/src/protocol/notifications/behaviour.rs @@ -110,10 +110,6 @@ pub struct Notifications { /// List of peers in our state. peers: FnvHashMap<(PeerId, sc_peerset::SetId), PeerState>, - /// A map containing the number of all the peers that the peerset currently requests us to be - /// connected to. - requested_peer_counts: FnvHashMap, - /// The elements in `peers` occasionally contain `Delay` objects that we would normally have /// to be polled one by one. In order to avoid doing so, as an optimization, every `Delay` is /// instead put inside of `delays` and reference by a [`DelayId`]. This stream @@ -367,32 +363,6 @@ pub enum NotificationsOut { }, } -fn increment_requested_peer_counts( - requested_peer_counts: &mut FnvHashMap, - set_id: sc_peerset::SetId, -) { - *requested_peer_counts.entry(set_id).or_insert(0) += 1; -} - -fn decrement_requested_peer_counts( - requested_peer_counts: &mut FnvHashMap, - set_id: sc_peerset::SetId, -) { - match requested_peer_counts.entry(set_id) { - Entry::Occupied(mut entry) => { - let value = entry.get_mut(); - if *value == 1 { - entry.remove(); - } else { - *value -= 1; - } - }, - Entry::Vacant(..) => { - warn!(target: "sub-libp2p", "Underflow of requested peer count for {:?}", set_id) - }, - } -} - impl Notifications { /// Creates a `CustomProtos`. pub fn new( @@ -414,7 +384,6 @@ impl Notifications { notif_protocols, peerset, peers: FnvHashMap::default(), - requested_peer_counts: Default::default(), delays: Default::default(), next_delay_id: DelayId(0), incoming: SmallVec::new(), @@ -488,7 +457,6 @@ impl Notifications { } else { timer_deadline }); - decrement_requested_peer_counts(&mut self.requested_peer_counts, set_id); *entry.into_mut() = PeerState::Disabled { connections, backoff_until } }, @@ -538,7 +506,6 @@ impl Notifications { .any(|(_, s)| matches!(s, ConnectionState::Opening))); let backoff_until = ban.map(|dur| Instant::now() + dur); - decrement_requested_peer_counts(&mut self.requested_peer_counts, set_id); *entry.into_mut() = PeerState::Disabled { connections, backoff_until } }, @@ -593,18 +560,15 @@ impl Notifications { } } - /// Returns the number of all the peers that the peerset currently requests us to be connected - /// to. - pub fn requested_peers_count(&self, set_id: sc_peerset::SetId) -> usize { - let count = self.requested_peer_counts.get(&set_id).copied().unwrap_or(0); - debug_assert_eq!( - self.peers - .iter() - .filter(move |((_, set), state)| *set == set_id && state.is_requested()) - .count(), - count - ); - count + /// Returns the list of all the peers that the peerset currently requests us to be connected to. + pub fn requested_peers<'a>( + &'a self, + set_id: sc_peerset::SetId, + ) -> impl Iterator + 'a { + self.peers + .iter() + .filter(move |((_, set), state)| *set == set_id && state.is_requested()) + .map(|((id, _), _)| id) } /// Returns the list of reserved peers. @@ -683,7 +647,6 @@ impl Notifications { condition: DialPeerCondition::Disconnected, handler, }); - increment_requested_peer_counts(&mut self.requested_peer_counts, set_id); entry.insert(PeerState::Requested); return }, @@ -702,7 +665,6 @@ impl Notifications { set_id, timer_deadline, ); - increment_requested_peer_counts(&mut self.requested_peer_counts, set_id); *occ_entry.into_mut() = PeerState::PendingRequest { timer: *timer, timer_deadline: *timer_deadline }; }, @@ -722,7 +684,6 @@ impl Notifications { condition: DialPeerCondition::Disconnected, handler, }); - increment_requested_peer_counts(&mut self.requested_peer_counts, set_id); *occ_entry.into_mut() = PeerState::Requested; }, @@ -750,7 +711,6 @@ impl Notifications { .boxed(), ); - increment_requested_peer_counts(&mut self.requested_peer_counts, set_id); *occ_entry.into_mut() = PeerState::DisabledPendingEnable { connections, timer: delay_id, @@ -777,7 +737,6 @@ impl Notifications { event: NotifsHandlerIn::Open { protocol_index: set_id.into() }, }); *connec_state = ConnectionState::Opening; - increment_requested_peer_counts(&mut self.requested_peer_counts, set_id); *occ_entry.into_mut() = PeerState::Enabled { connections }; } else { // If no connection is available, switch to `DisabledPendingEnable` in order @@ -812,7 +771,6 @@ impl Notifications { .boxed(), ); - increment_requested_peer_counts(&mut self.requested_peer_counts, set_id); *occ_entry.into_mut() = PeerState::DisabledPendingEnable { connections, timer: delay_id, @@ -855,7 +813,6 @@ impl Notifications { *connec_state = ConnectionState::Opening; } - increment_requested_peer_counts(&mut self.requested_peer_counts, set_id); *occ_entry.into_mut() = PeerState::Enabled { connections }; }, @@ -913,7 +870,6 @@ impl Notifications { trace!(target: "sub-libp2p", "PSM => Drop({}, {:?}): Interrupting pending enabling.", entry.key().0, set_id); - decrement_requested_peer_counts(&mut self.requested_peer_counts, set_id); *entry.into_mut() = PeerState::Disabled { connections, backoff_until: Some(timer_deadline) }; }, @@ -963,7 +919,6 @@ impl Notifications { *connec_state = ConnectionState::Closing; } - decrement_requested_peer_counts(&mut self.requested_peer_counts, set_id); *entry.into_mut() = PeerState::Disabled { connections, backoff_until: None } }, @@ -974,8 +929,6 @@ impl Notifications { // well at the same time. trace!(target: "sub-libp2p", "PSM => Drop({}, {:?}): Not yet connected.", entry.key().0, set_id); - - decrement_requested_peer_counts(&mut self.requested_peer_counts, set_id); entry.remove(); }, @@ -983,8 +936,6 @@ impl Notifications { PeerState::PendingRequest { timer, timer_deadline } => { trace!(target: "sub-libp2p", "PSM => Drop({}, {:?}): Not yet connected", entry.key().0, set_id); - - decrement_requested_peer_counts(&mut self.requested_peer_counts, set_id); *entry.into_mut() = PeerState::Backoff { timer, timer_deadline } }, @@ -1059,7 +1010,6 @@ impl Notifications { *connec_state = ConnectionState::Opening; } - increment_requested_peer_counts(&mut self.requested_peer_counts, incoming.set_id); *state = PeerState::Enabled { connections }; }, @@ -1280,7 +1230,6 @@ impl NetworkBehaviour for Notifications { if connections.is_empty() { trace!(target: "sub-libp2p", "PSM <= Dropped({}, {:?})", peer_id, set_id); self.peerset.dropped(set_id, *peer_id, DropReason::Unknown); - decrement_requested_peer_counts(&mut self.requested_peer_counts, set_id); *entry.get_mut() = PeerState::Backoff { timer, timer_deadline }; } else { *entry.get_mut() = @@ -1433,7 +1382,6 @@ impl NetworkBehaviour for Notifications { .boxed(), ); - decrement_requested_peer_counts(&mut self.requested_peer_counts, set_id); *entry.get_mut() = PeerState::Backoff { timer: delay_id, timer_deadline: Instant::now() + Duration::from_secs(ban_dur), @@ -1444,7 +1392,6 @@ impl NetworkBehaviour for Notifications { trace!(target: "sub-libp2p", "PSM <= Dropped({}, {:?})", peer_id, set_id); self.peerset.dropped(set_id, *peer_id, DropReason::Unknown); - decrement_requested_peer_counts(&mut self.requested_peer_counts, set_id); *entry.get_mut() = PeerState::Disabled { connections, backoff_until: None }; } else { *entry.get_mut() = PeerState::Enabled { connections }; @@ -1518,10 +1465,6 @@ impl NetworkBehaviour for Notifications { .boxed(), ); - decrement_requested_peer_counts( - &mut self.requested_peer_counts, - set_id, - ); *entry.into_mut() = PeerState::Backoff { timer: delay_id, timer_deadline: now + ban_duration, @@ -1808,10 +1751,6 @@ impl NetworkBehaviour for Notifications { { trace!(target: "sub-libp2p", "PSM <= Dropped({}, {:?})", source, set_id); self.peerset.dropped(set_id, source, DropReason::Refused); - decrement_requested_peer_counts( - &mut self.requested_peer_counts, - set_id, - ); *entry.into_mut() = PeerState::Disabled { connections, backoff_until: None }; } else { @@ -1989,10 +1928,6 @@ impl NetworkBehaviour for Notifications { self.peerset.dropped(set_id, source, DropReason::Refused); let ban_dur = Uniform::new(5, 10).sample(&mut rand::thread_rng()); - decrement_requested_peer_counts( - &mut self.requested_peer_counts, - set_id, - ); *entry.into_mut() = PeerState::Disabled { connections, backoff_until: Some(Instant::now() + Duration::from_secs(ban_dur)), diff --git a/client/network/src/service.rs b/client/network/src/service.rs index 8a0816831aeec..b6a1d3c88e7f3 100644 --- a/client/network/src/service.rs +++ b/client/network/src/service.rs @@ -2108,10 +2108,10 @@ impl Future for NetworkWorker { .peerset_num_discovered .set(this.network_service.behaviour_mut().user_protocol().num_discovered_peers() as u64); - metrics - .peerset_num_requested - .set(this.network_service.behaviour_mut().user_protocol().requested_peers_count() - as u64); + metrics.peerset_num_requested.set( + this.network_service.behaviour_mut().user_protocol().requested_peers().count() + as u64, + ); metrics.pending_connections.set( Swarm::network_info(&this.network_service).connection_counters().num_pending() as u64, From 73d769ab23f9f1d4bfaf3ce89d6ed3a864751dbe Mon Sep 17 00:00:00 2001 From: Jan Bujak Date: Fri, 18 Feb 2022 10:24:53 +0000 Subject: [PATCH 4/5] Remove `substrate_sub_libp2p_peerset_num_requested` metric --- client/network/src/protocol.rs | 6 ------ client/network/src/service.rs | 4 ---- client/network/src/service/metrics.rs | 5 ----- 3 files changed, 15 deletions(-) diff --git a/client/network/src/protocol.rs b/client/network/src/protocol.rs index 38f7a01a0890a..eb634ca5be764 100644 --- a/client/network/src/protocol.rs +++ b/client/network/src/protocol.rs @@ -465,12 +465,6 @@ impl Protocol { self.behaviour.open_peers() } - /// Returns the list of all the peers that the peerset currently requests us to be connected - /// to on the default set. - pub fn requested_peers(&self) -> impl Iterator { - self.behaviour.requested_peers(HARDCODED_PEERSETS_SYNC) - } - /// Returns the number of discovered nodes that we keep in memory. pub fn num_discovered_peers(&self) -> usize { self.behaviour.num_discovered_peers() diff --git a/client/network/src/service.rs b/client/network/src/service.rs index b6a1d3c88e7f3..a02aa982318a9 100644 --- a/client/network/src/service.rs +++ b/client/network/src/service.rs @@ -2108,10 +2108,6 @@ impl Future for NetworkWorker { .peerset_num_discovered .set(this.network_service.behaviour_mut().user_protocol().num_discovered_peers() as u64); - metrics.peerset_num_requested.set( - this.network_service.behaviour_mut().user_protocol().requested_peers().count() - as u64, - ); metrics.pending_connections.set( Swarm::network_info(&this.network_service).connection_counters().num_pending() as u64, diff --git a/client/network/src/service/metrics.rs b/client/network/src/service/metrics.rs index bf94287d12918..ad30b1b093ff9 100644 --- a/client/network/src/service/metrics.rs +++ b/client/network/src/service/metrics.rs @@ -69,7 +69,6 @@ pub struct Metrics { pub notifications_streams_closed_total: CounterVec, pub notifications_streams_opened_total: CounterVec, pub peerset_num_discovered: Gauge, - pub peerset_num_requested: Gauge, pub pending_connections: Gauge, pub pending_connections_errors_total: CounterVec, pub requests_in_failure_total: CounterVec, @@ -204,10 +203,6 @@ impl Metrics { "substrate_sub_libp2p_peerset_num_discovered", "Number of nodes stored in the peerset manager", )?, registry)?, - peerset_num_requested: prometheus::register(Gauge::new( - "substrate_sub_libp2p_peerset_num_requested", - "Number of nodes that the peerset manager wants us to be connected to", - )?, registry)?, pending_connections: prometheus::register(Gauge::new( "substrate_sub_libp2p_pending_connections", "Number of connections in the process of being established", From 5ae994b01e72a544c41e2b1ceee2bf82b5f2e7c4 Mon Sep 17 00:00:00 2001 From: Jan Bujak Date: Fri, 18 Feb 2022 10:40:41 +0000 Subject: [PATCH 5/5] Remove two unused functions that I forgot to get rid of in previous commit --- .../src/protocol/notifications/behaviour.rs | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/client/network/src/protocol/notifications/behaviour.rs b/client/network/src/protocol/notifications/behaviour.rs index 97047201c308c..b47216473970e 100644 --- a/client/network/src/protocol/notifications/behaviour.rs +++ b/client/network/src/protocol/notifications/behaviour.rs @@ -251,16 +251,6 @@ impl PeerState { _ => None, } } - - /// True if that node has been requested by the PSM. - fn is_requested(&self) -> bool { - matches!( - self, - Self::PendingRequest { .. } | - Self::Requested | Self::DisabledPendingEnable { .. } | - Self::Enabled { .. } - ) - } } /// State of the handler of a single connection visible from this state machine. @@ -560,17 +550,6 @@ impl Notifications { } } - /// Returns the list of all the peers that the peerset currently requests us to be connected to. - pub fn requested_peers<'a>( - &'a self, - set_id: sc_peerset::SetId, - ) -> impl Iterator + 'a { - self.peers - .iter() - .filter(move |((_, set), state)| *set == set_id && state.is_requested()) - .map(|((id, _), _)| id) - } - /// Returns the list of reserved peers. pub fn reserved_peers<'a>( &'a self,