Add getClusterNodes/getSlotLeader JSON RPC API (#3940)

* Minor cleanup

* Include _this_ node in the contact info trace

* Add getClusterNodes/getSlotLeader RPC API
This commit is contained in:
Michael Vines
2019-04-23 14:46:41 -07:00
committed by GitHub
parent d22a1c9b1f
commit c309cd80aa
4 changed files with 159 additions and 17 deletions

View File

@ -245,6 +245,7 @@ impl ClusterInfo {
pub fn contact_info_trace(&self) -> String {
let now = timestamp();
let mut spy_nodes = 0;
let my_id = self.my_data().id;
let nodes: Vec<_> = self
.all_peers()
.into_iter()
@ -261,12 +262,13 @@ impl ClusterInfo {
}
format!(
"- gossip: {:20} | {:5}ms | {}\n \
"- gossip: {:20} | {:5}ms | {} {}\n \
tpu: {:20} | |\n \
rpc: {:20} | |\n",
addr_to_string(&node.gossip),
now.saturating_sub(node.wallclock),
node.id,
if node.id == my_id { "(me)" } else { "" }.to_string(),
addr_to_string(&node.tpu),
addr_to_string(&node.rpc),
)
@ -346,14 +348,12 @@ impl ClusterInfo {
}
// All nodes in gossip, including spy nodes
fn all_peers(&self) -> Vec<ContactInfo> {
let me = self.my_data().id;
pub(crate) fn all_peers(&self) -> Vec<ContactInfo> {
self.gossip
.crds
.table
.values()
.filter_map(|x| x.value.contact_info())
.filter(|x| x.id != me)
.cloned()
.collect()
}