show-validators: display current/delinquent stake, and flag delinquent nodes (#6525)
This commit is contained in:
parent
39fc677781
commit
d398898c38
|
@ -8,7 +8,7 @@ use crate::{
|
||||||
use clap::{value_t_or_exit, App, Arg, ArgMatches, SubCommand};
|
use clap::{value_t_or_exit, App, Arg, ArgMatches, SubCommand};
|
||||||
use console::{style, Emoji};
|
use console::{style, Emoji};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use solana_client::rpc_client::RpcClient;
|
use solana_client::{rpc_client::RpcClient, rpc_request::RpcVoteAccountInfo};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
clock,
|
clock,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
|
@ -22,6 +22,7 @@ use std::{
|
||||||
|
|
||||||
static CHECK_MARK: Emoji = Emoji("✅ ", "");
|
static CHECK_MARK: Emoji = Emoji("✅ ", "");
|
||||||
static CROSS_MARK: Emoji = Emoji("❌ ", "");
|
static CROSS_MARK: Emoji = Emoji("❌ ", "");
|
||||||
|
static WARNING: Emoji = Emoji("⚠️", "!");
|
||||||
|
|
||||||
pub trait ClusterQuerySubCommands {
|
pub trait ClusterQuerySubCommands {
|
||||||
fn cluster_query_subcommands(self) -> Self;
|
fn cluster_query_subcommands(self) -> Self;
|
||||||
|
@ -303,17 +304,48 @@ pub fn process_ping(
|
||||||
|
|
||||||
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_activate_stake = vote_accounts
|
let total_active_stake = vote_accounts
|
||||||
.current
|
.current
|
||||||
.iter()
|
.iter()
|
||||||
.chain(vote_accounts.delinquent.iter())
|
.chain(vote_accounts.delinquent.iter())
|
||||||
.fold(0, |acc, vote_account| acc + vote_account.activated_stake)
|
.fold(0, |acc, vote_account| acc + vote_account.activated_stake)
|
||||||
as f64;
|
as f64;
|
||||||
|
|
||||||
|
let total_deliquent_stake = vote_accounts
|
||||||
|
.delinquent
|
||||||
|
.iter()
|
||||||
|
.fold(0, |acc, vote_account| acc + vote_account.activated_stake)
|
||||||
|
as f64;
|
||||||
|
let total_current_stake = total_active_stake - total_deliquent_stake;
|
||||||
|
|
||||||
|
println_name_value(
|
||||||
|
"Active Stake:",
|
||||||
|
&build_balance_message(total_active_stake as u64, use_lamports_unit),
|
||||||
|
);
|
||||||
|
if total_deliquent_stake > 0. {
|
||||||
|
println_name_value(
|
||||||
|
"Current Stake:",
|
||||||
|
&format!(
|
||||||
|
"{} ({:0.2}%)",
|
||||||
|
&build_balance_message(total_current_stake as u64, use_lamports_unit),
|
||||||
|
100. * total_current_stake / total_active_stake
|
||||||
|
),
|
||||||
|
);
|
||||||
|
println_name_value(
|
||||||
|
"Delinquent Stake:",
|
||||||
|
&format!(
|
||||||
|
"{} ({:0.2}%)",
|
||||||
|
&build_balance_message(total_deliquent_stake as u64, use_lamports_unit),
|
||||||
|
100. * total_deliquent_stake / total_active_stake
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
println!();
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"{}",
|
"{}",
|
||||||
style(format!(
|
style(format!(
|
||||||
"{:<44} {:<44} {:<11} {:>10} {:>11} {}",
|
" {:<44} {:<44} {:<11} {:>10} {:>11} {}",
|
||||||
"Identity Pubkey",
|
"Identity Pubkey",
|
||||||
"Vote Account Pubkey",
|
"Vote Account Pubkey",
|
||||||
"Commission",
|
"Commission",
|
||||||
|
@ -324,11 +356,12 @@ pub fn process_show_validators(rpc_client: &RpcClient, use_lamports_unit: bool)
|
||||||
.bold()
|
.bold()
|
||||||
);
|
);
|
||||||
|
|
||||||
for vote_account in vote_accounts
|
fn print_vote_account(
|
||||||
.current
|
vote_account: &RpcVoteAccountInfo,
|
||||||
.iter()
|
total_active_stake: f64,
|
||||||
.chain(vote_accounts.delinquent.iter())
|
use_lamports_unit: bool,
|
||||||
{
|
delinquent: bool,
|
||||||
|
) {
|
||||||
fn non_zero_or_dash(v: u64) -> String {
|
fn non_zero_or_dash(v: u64) -> String {
|
||||||
if v == 0 {
|
if v == 0 {
|
||||||
"-".into()
|
"-".into()
|
||||||
|
@ -336,9 +369,13 @@ pub fn process_show_validators(rpc_client: &RpcClient, use_lamports_unit: bool)
|
||||||
format!("{}", v)
|
format!("{}", v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"{:<44} {:<44} {:>3} ({:>4.1}%) {:>10} {:>11} {:>11}",
|
"{} {:<44} {:<44} {:>3} ({:>4.1}%) {:>10} {:>11} {:>11}",
|
||||||
|
if delinquent {
|
||||||
|
WARNING.to_string()
|
||||||
|
} else {
|
||||||
|
" ".to_string()
|
||||||
|
},
|
||||||
vote_account.node_pubkey,
|
vote_account.node_pubkey,
|
||||||
vote_account.vote_pubkey,
|
vote_account.vote_pubkey,
|
||||||
vote_account.commission,
|
vote_account.commission,
|
||||||
|
@ -349,7 +386,7 @@ pub fn process_show_validators(rpc_client: &RpcClient, use_lamports_unit: bool)
|
||||||
format!(
|
format!(
|
||||||
"{} ({:.2}%)",
|
"{} ({:.2}%)",
|
||||||
build_balance_message(vote_account.activated_stake, use_lamports_unit),
|
build_balance_message(vote_account.activated_stake, use_lamports_unit),
|
||||||
100. * vote_account.activated_stake as f64 / total_activate_stake
|
100. * vote_account.activated_stake as f64 / total_active_stake
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
"-".into()
|
"-".into()
|
||||||
|
@ -357,6 +394,13 @@ pub fn process_show_validators(rpc_client: &RpcClient, use_lamports_unit: bool)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for vote_account in vote_accounts.current.iter() {
|
||||||
|
print_vote_account(vote_account, total_active_stake, use_lamports_unit, false);
|
||||||
|
}
|
||||||
|
for vote_account in vote_accounts.delinquent.iter() {
|
||||||
|
print_vote_account(vote_account, total_active_stake, use_lamports_unit, true);
|
||||||
|
}
|
||||||
|
|
||||||
Ok("".to_string())
|
Ok("".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue