Add show-gossip command (#6982)

This commit is contained in:
Michael Vines
2019-11-15 13:15:34 -07:00
committed by GitHub
parent d565ec7968
commit b2db0b97fc
2 changed files with 47 additions and 0 deletions

View File

@@ -20,6 +20,7 @@ use solana_sdk::{
};
use std::{
collections::VecDeque,
net::SocketAddr,
thread::sleep,
time::{Duration, Instant},
};
@@ -101,6 +102,10 @@ impl ClusterQuerySubCommands for App<'_, '_> {
),
),
)
.subcommand(
SubCommand::with_name("show-gossip")
.about("Show the current gossip network nodes"),
)
.subcommand(
SubCommand::with_name("show-validators")
.about("Show information about the current validators")
@@ -400,6 +405,42 @@ pub fn process_ping(
Ok("".to_string())
}
pub fn process_show_gossip(rpc_client: &RpcClient) -> ProcessResult {
let cluster_nodes = rpc_client.get_cluster_nodes()?;
fn format_port(addr: Option<SocketAddr>) -> String {
addr.map(|addr| addr.port().to_string())
.unwrap_or_else(|| "none".to_string())
}
let s: Vec<_> = cluster_nodes
.iter()
.map(|node| {
format!(
"{:15} | {:44} | {:6} | {:5} | {:5}",
node.gossip
.map(|addr| addr.ip().to_string())
.unwrap_or_else(|| "none".to_string()),
node.pubkey,
format_port(node.gossip),
format_port(node.tpu),
format_port(node.rpc),
)
})
.collect();
Ok(format!(
"IP Address | Node identifier \
| Gossip | TPU | RPC\n\
----------------+----------------------------------------------+\
--------+-------+-------\n\
{}\n\
Nodes: {}",
s.join("\n"),
s.len(),
))
}
pub fn process_show_validators(rpc_client: &RpcClient, use_lamports_unit: bool) -> ProcessResult {
let vote_accounts = rpc_client.get_vote_accounts()?;
let total_active_stake = vote_accounts