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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 0 deletions

View File

@ -84,6 +84,7 @@ pub enum CliCommand {
timeout: Duration, timeout: Duration,
commitment_config: CommitmentConfig, commitment_config: CommitmentConfig,
}, },
ShowGossip,
ShowValidators { ShowValidators {
use_lamports_unit: bool, use_lamports_unit: bool,
}, },
@ -264,6 +265,10 @@ pub fn parse_command(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, Box<dyn
require_keypair: false, require_keypair: false,
}), }),
("ping", Some(matches)) => parse_cluster_ping(matches), ("ping", Some(matches)) => parse_cluster_ping(matches),
("show-gossip", Some(_matches)) => Ok(CliCommandInfo {
command: CliCommand::ShowGossip,
require_keypair: false,
}),
("show-validators", Some(matches)) => parse_show_validators(matches), ("show-validators", Some(matches)) => parse_show_validators(matches),
// Program Deployment // Program Deployment
("deploy", Some(matches)) => Ok(CliCommandInfo { ("deploy", Some(matches)) => Ok(CliCommandInfo {
@ -871,6 +876,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
timeout, timeout,
commitment_config, commitment_config,
), ),
CliCommand::ShowGossip => process_show_gossip(&rpc_client),
CliCommand::ShowValidators { use_lamports_unit } => { CliCommand::ShowValidators { use_lamports_unit } => {
process_show_validators(&rpc_client, *use_lamports_unit) process_show_validators(&rpc_client, *use_lamports_unit)
} }

View File

@ -20,6 +20,7 @@ use solana_sdk::{
}; };
use std::{ use std::{
collections::VecDeque, collections::VecDeque,
net::SocketAddr,
thread::sleep, thread::sleep,
time::{Duration, Instant}, 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(
SubCommand::with_name("show-validators") SubCommand::with_name("show-validators")
.about("Show information about the current validators") .about("Show information about the current validators")
@ -400,6 +405,42 @@ pub fn process_ping(
Ok("".to_string()) 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 { pub fn process_show_validators(rpc_client: &RpcClient, use_lamports_unit: bool) -> ProcessResult {
let vote_accounts = rpc_client.get_vote_accounts()?; let vote_accounts = rpc_client.get_vote_accounts()?;
let total_active_stake = vote_accounts let total_active_stake = vote_accounts