Skip to content

Commit

Permalink
Include validator status in the ListValidators output, fix show_inactive
Browse files Browse the repository at this point in the history
  • Loading branch information
zbuc authored and hdevalence committed Apr 20, 2022
1 parent 7227487 commit 33d6499
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
8 changes: 7 additions & 1 deletion pcli/src/command/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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![
Expand Down
12 changes: 8 additions & 4 deletions pd/src/info/oblivious.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use penumbra_proto::{
stake::ValidatorInfo,
Protobuf,
};
use penumbra_stake::ValidatorState;
use tonic::Status;
use tracing::instrument;

Expand Down Expand Up @@ -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();
}
};
Expand Down
13 changes: 13 additions & 0 deletions stake/src/validator_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<pb::ValidatorState> for ValidatorState {}

impl From<ValidatorState> for pb::ValidatorState {
Expand Down

0 comments on commit 33d6499

Please sign in to comment.