Skip to content

Commit

Permalink
feat(networking): remove self.close_group and checks there as unused
Browse files Browse the repository at this point in the history
check_for_changes_in_close_group only updated self,
which was only used in the process of calling the function.
The boolean was not used anywhere in the code, so we could safely remove this
  • Loading branch information
joshuef committed Jul 17, 2024
1 parent 7a16c14 commit 27bf1ac
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 33 deletions.
1 change: 0 additions & 1 deletion sn_networking/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,6 @@ impl SwarmDriver {
warn!("Cleaning out bad_peer {peer_id:?}");
if let Some(dead_peer) = self.swarm.behaviour_mut().kademlia.remove_peer(&peer_id) {
self.update_on_peer_removal(*dead_peer.node.key.preimage());
let _ = self.check_for_change_in_our_close_group();
}

if is_new_bad {
Expand Down
2 changes: 0 additions & 2 deletions sn_networking/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,6 @@ impl NetworkBuilder {
peers_in_rt: 0,
bootstrap,
relay_manager,
close_group: Default::default(),
replication_fetcher,
#[cfg(feature = "open-metrics")]
network_metrics,
Expand Down Expand Up @@ -635,7 +634,6 @@ pub struct SwarmDriver {
pub(crate) bootstrap: ContinuousBootstrap,
pub(crate) relay_manager: RelayManager,
/// The peers that are closer to our PeerId. Includes self.
pub(crate) close_group: Vec<PeerId>,
pub(crate) replication_fetcher: ReplicationFetcher,
#[cfg(feature = "open-metrics")]
pub(crate) network_metrics: Option<NetworkMetrics>,
Expand Down
1 change: 0 additions & 1 deletion sn_networking/src/event/kad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ impl SwarmDriver {
info!("Evicted old peer on new peer join: {old_peer:?}");
self.update_on_peer_removal(old_peer);
}
let _ = self.check_for_change_in_our_close_group();
}
kad::Event::InboundRequest {
request: InboundRequest::PutRecord { .. },
Expand Down
27 changes: 2 additions & 25 deletions sn_networking/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod kad;
mod request_response;
mod swarm;

use crate::{driver::SwarmDriver, error::Result, CLOSE_GROUP_SIZE};
use crate::{driver::SwarmDriver, error::Result};
use core::fmt;
use custom_debug::Debug as CustomDebug;
#[cfg(feature = "local-discovery")]
Expand All @@ -27,7 +27,7 @@ use sn_protocol::{
};
use sn_transfers::PaymentQuote;
use std::{
collections::{BTreeSet, HashSet},
collections::BTreeSet,
fmt::{Debug, Formatter},
};
use tokio::sync::oneshot;
Expand Down Expand Up @@ -236,29 +236,6 @@ impl Debug for NetworkEvent {
}

impl SwarmDriver {
/// Check for changes in our close group
pub(crate) fn check_for_change_in_our_close_group(&mut self) -> bool {
// this includes self
let closest_k_peers = self.get_closest_k_value_local_peers();

let new_closest_peers: Vec<_> =
closest_k_peers.into_iter().take(CLOSE_GROUP_SIZE).collect();

let old = self.close_group.iter().cloned().collect::<HashSet<_>>();
let new_members: Vec<_> = new_closest_peers
.iter()
.filter(|p| !old.contains(p))
.collect();
if !new_members.is_empty() {
debug!("The close group has been updated. The new members are {new_members:?}");
debug!("New close group: {new_closest_peers:?}");
self.close_group = new_closest_peers;
true
} else {
false
}
}

/// Update state on addition of a peer to the routing table.
pub(crate) fn update_on_peer_addition(&mut self, added_peer: PeerId) {
self.peers_in_rt = self.peers_in_rt.saturating_add(1);
Expand Down
4 changes: 0 additions & 4 deletions sn_networking/src/event/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ impl SwarmDriver {
{
error!("Clearing out a protocol mistmatch peer from RT. Something went wrong, we should not have added this peer to RT: {peer_id:?}");
self.update_on_peer_removal(*dead_peer.node.key.preimage());
let _ = self.check_for_change_in_our_close_group();
}

return Ok(());
Expand Down Expand Up @@ -549,8 +548,6 @@ impl SwarmDriver {
peer_id: failed_peer_id,
issue: crate::NodeIssue::ConnectionIssue,
})?;

let _ = self.check_for_change_in_our_close_group();
}
}
}
Expand Down Expand Up @@ -661,7 +658,6 @@ impl SwarmDriver {
.remove_peer(&to_be_removed_bootstrap);
if let Some(removed_peer) = entry {
self.update_on_peer_removal(*removed_peer.node.key.preimage());
let _ = self.check_for_change_in_our_close_group();
}
}
}
Expand Down

0 comments on commit 27bf1ac

Please sign in to comment.