solana-gossip now displays other spy nodes and contact info age (#3867)

This commit is contained in:
Michael Vines
2019-04-18 09:48:21 -07:00
committed by GitHub
parent e9b82bacda
commit f8543a268f

View File

@ -244,40 +244,48 @@ impl ClusterInfo {
} }
pub fn contact_info_trace(&self) -> String { pub fn contact_info_trace(&self) -> String {
let leader_id = self.gossip_leader_id; let now = timestamp();
let mut spy_nodes = 0;
let nodes: Vec<_> = self let nodes: Vec<_> = self
.tvu_peers() .all_peers()
.into_iter() .into_iter()
.map(|node| { .map(|node| {
let mut annotation = String::new(); if !ContactInfo::is_valid_address(&node.gossip) {
if node.id == leader_id { spy_nodes += 1;
annotation.push_str(" [leader]");
} }
fn addr_to_string(addr: &SocketAddr) -> String {
format!( if ContactInfo::is_valid_address(addr) {
"- gossip: {:20} | {}{}\n \ addr.to_string()
tpu: {:20} |\n \
rpc: {:20} |\n",
node.gossip.to_string(),
node.id,
annotation,
node.tpu.to_string(),
if ContactInfo::is_valid_address(&node.rpc) {
node.rpc.to_string()
} else { } else {
"none".to_string() "none".to_string()
} }
}
format!(
"- gossip: {:20} | {:5}ms | {}\n \
tpu: {:20} | |\n \
rpc: {:20} | |\n",
addr_to_string(&node.gossip),
now.saturating_sub(node.wallclock),
node.id,
addr_to_string(&node.tpu),
addr_to_string(&node.rpc),
) )
}) })
.collect(); .collect();
format!( format!(
" Node contact info | Node identifier\n\ " Node contact info | Age | Node identifier \n\
-------------------------------+------------------\n\ -------------------------------+---------+-----------------------------------\n\
{}\ {}\
Nodes: {}", Nodes: {}{}",
nodes.join(""), nodes.join(""),
nodes.len() nodes.len() - spy_nodes,
if spy_nodes > 0 {
format!("\nSpies: {}", spy_nodes)
} else {
"".to_string()
}
) )
} }
@ -338,6 +346,19 @@ impl ClusterInfo {
.collect() .collect()
} }
// All nodes in gossip, including spy nodes
fn all_peers(&self) -> Vec<ContactInfo> {
let me = self.my_data().id;
self.gossip
.crds
.table
.values()
.filter_map(|x| x.value.contact_info())
.filter(|x| x.id != me)
.cloned()
.collect()
}
pub fn gossip_peers(&self) -> Vec<ContactInfo> { pub fn gossip_peers(&self) -> Vec<ContactInfo> {
let me = self.my_data().id; let me = self.my_data().id;
self.gossip self.gossip