From d45112b5cf399e74055f2366d4dde10eeeb6d018 Mon Sep 17 00:00:00 2001 From: qima Date: Wed, 18 Oct 2023 00:10:29 +0800 Subject: [PATCH] chore: logging a node's representitive record_key address --- sn_networking/src/driver.rs | 9 ++++++++- sn_networking/src/lib.rs | 40 ++++++++++++++++++++++++++++++++++--- sn_node/src/replication.rs | 13 +++++++++++- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/sn_networking/src/driver.rs b/sn_networking/src/driver.rs index 93420b7446..7d19e73c98 100644 --- a/sn_networking/src/driver.rs +++ b/sn_networking/src/driver.rs @@ -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, @@ -292,6 +295,10 @@ impl NetworkBuilder { ) -> Result<(Network, mpsc::Receiver, 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 = { diff --git a/sn_networking/src/lib.rs b/sn_networking/src/lib.rs index d18017f615..81fddc5fff 100644 --- a/sn_networking/src/lib.rs +++ b/sn_networking/src/lib.rs @@ -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 @@ -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) } diff --git a/sn_node/src/replication.rs b/sn_node/src/replication.rs index 1b6acf26e9..8a19f5a9e2 100644 --- a/sn_node/src/replication.rs +++ b/sn_node/src/replication.rs @@ -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.