From 33d6499cf2c1f256dcdea1cb59b42c01ea08ddaf Mon Sep 17 00:00:00 2001 From: Chris Czub Date: Tue, 19 Apr 2022 23:02:06 -0400 Subject: [PATCH] Include validator status in the ListValidators output, fix show_inactive --- pcli/src/command/stake.rs | 8 +++++++- pd/src/info/oblivious.rs | 12 ++++++++---- stake/src/validator_state.rs | 13 +++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/pcli/src/command/stake.rs b/pcli/src/command/stake.rs index ab52efb422..0ada8f03fd 100644 --- a/pcli/src/command/stake.rs +++ b/pcli/src/command/stake.rs @@ -277,7 +277,12 @@ impl StakeCmd { let mut table = Table::new(); table.load_preset(presets::NOTHING); - table.set_header(vec!["Voting Power", "Commission", "Validator Info"]); + table.set_header(vec![ + "Voting Power", + "Commission", + "State", + "Validator Info", + ]); for v in validators { let power_percent = 100.0 * (v.status.voting_power as f64) / total_voting_power; @@ -292,6 +297,7 @@ impl StakeCmd { table.add_row(vec![ format!("{:.2}%", power_percent), format!("{}bps", commission_bps), + v.status.state.to_string(), v.validator.name, ]); table.add_row(vec![ diff --git a/pd/src/info/oblivious.rs b/pd/src/info/oblivious.rs index 212e5ee9a1..402fc846f4 100644 --- a/pd/src/info/oblivious.rs +++ b/pd/src/info/oblivious.rs @@ -11,6 +11,7 @@ use penumbra_proto::{ stake::ValidatorInfo, Protobuf, }; +use penumbra_stake::ValidatorState; use tonic::Status; use tracing::instrument; @@ -76,13 +77,16 @@ impl ObliviousQuery for Storage { .await .map_err(|_| tonic::Status::unavailable("database error"))?; - let _show_inactive = request.get_ref().show_inactive; + let show_inactive = request.get_ref().show_inactive; let s = try_stream! { - for validator in validators { - let info = overlay.validator_info(&validator) + for identity_key in validators { + let info = overlay.validator_info(&identity_key) .await? .expect("known validator must be present"); - // TODO: filter by show_inactive + // Slashed and inactive validators are not shown by default. + if !show_inactive && info.status.state != ValidatorState::Active { + continue; + } yield info.to_proto(); } }; diff --git a/stake/src/validator_state.rs b/stake/src/validator_state.rs index f8e8e4e916..81c16a331b 100644 --- a/stake/src/validator_state.rs +++ b/stake/src/validator_state.rs @@ -21,6 +21,19 @@ pub enum ValidatorState { Slashed, } +impl std::fmt::Display for ValidatorState { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + ValidatorState::Inactive => write!(f, "Inactive"), + ValidatorState::Active => write!(f, "Active"), + ValidatorState::Unbonding { unbonding_epoch } => { + write!(f, "Unbonding (unbonding epoch: {})", unbonding_epoch) + } + ValidatorState::Slashed => write!(f, "Slashed"), + } + } +} + impl Protobuf for ValidatorState {} impl From for pb::ValidatorState {