Skip to content

Commit

Permalink
chore: logging a node's representitive record_key address
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi authored and joshuef committed Oct 18, 2023
1 parent d7124b3 commit d45112b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
9 changes: 8 additions & 1 deletion sn_networking/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ use libp2p::{
use libp2p_quic as quic;
#[cfg(feature = "open-metrics")]
use prometheus_client::registry::Registry;
use sn_protocol::messages::{Request, Response};
use sn_protocol::{
messages::{Request, Response},
NetworkAddress, PrettyPrintRecordKey,
};
use std::{
collections::{HashMap, HashSet},
net::SocketAddr,
Expand Down Expand Up @@ -292,6 +295,10 @@ impl NetworkBuilder {
) -> Result<(Network, mpsc::Receiver<NetworkEvent>, SwarmDriver)> {
let peer_id = PeerId::from(self.keypair.public());
info!("Node (PID: {}) with PeerId: {peer_id}", std::process::id());
info!(
"Self PeerID {peer_id} is represented as record_key {:?}",
PrettyPrintRecordKey::from(NetworkAddress::from_peer(peer_id).to_record_key())
);

#[cfg(feature = "open-metrics")]
let network_metrics = {
Expand Down
40 changes: 37 additions & 3 deletions sn_networking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,30 @@ impl Network {
sender,
})?;

receiver
.await
.map_err(|_e| Error::InternalMsgChannelDropped)
match receiver.await {
Ok(close_peers) => {
let close_peers_pretty_print: Vec<_> = close_peers
.iter()
.map(|peer_id| {
format!(
"{peer_id:?}({:?})",
PrettyPrintRecordKey::from(
NetworkAddress::from_peer(*peer_id).to_record_key()
)
)
})
.collect();

trace!(
"Local knowledge of close peers to {key:?} are: {close_peers_pretty_print:?}"
);
Ok(close_peers)
}
Err(err) => {
error!("When getting local knowledge of close peers to {key:?}, failed with error {err:?}");
Err(Error::InternalMsgChannelDropped)
}
}
}

/// Returns all the PeerId from all the KBuckets from our local Routing Table
Expand Down Expand Up @@ -585,6 +606,19 @@ impl Network {
if !client {
closest_peers.push(self.peer_id);
}

let close_peers_pretty_print: Vec<_> = closest_peers
.iter()
.map(|peer_id| {
format!(
"{peer_id:?}({:?})",
PrettyPrintRecordKey::from(NetworkAddress::from_peer(*peer_id).to_record_key())
)
})
.collect();

trace!("Network knowledge of close peers to {key:?} are: {close_peers_pretty_print:?}");

sort_peers_by_address(closest_peers, key, CLOSE_GROUP_SIZE)
}

Expand Down
13 changes: 12 additions & 1 deletion sn_node/src/replication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,20 @@ impl Node {
for key in all_records {
let sorted_based_on_key =
sort_peers_by_address(all_peers.clone(), &key, CLOSE_GROUP_SIZE + 1)?;
let sorted_peers_pretty_print: Vec<_> = sorted_based_on_key
.iter()
.map(|peer_id| {
format!(
"{peer_id:?}({:?})",
PrettyPrintRecordKey::from(
NetworkAddress::from_peer(*peer_id).to_record_key()
)
)
})
.collect();

if sorted_based_on_key.contains(&peer_id) {
trace!("replication: close for {key:?} are: {sorted_based_on_key:?}");
trace!("replication: close for {key:?} are: {sorted_peers_pretty_print:?}");
let target_peer = if is_removal {
// For dead peer, only replicate to farthest close_group peer,
// when the dead peer was one of the close_group peers to the record.
Expand Down

0 comments on commit d45112b

Please sign in to comment.