From 14dd0e03c4f9b898ccc959f2caba702527c970d2 Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Wed, 4 Nov 2020 05:24:35 +0900 Subject: [PATCH 1/3] Show more detailed vote history in shorter format --- cli-output/src/cli_output.rs | 56 ++++++++++++++++++++++++------------ cli/src/vote.rs | 8 ++++-- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/cli-output/src/cli_output.rs b/cli-output/src/cli_output.rs index 92995eba8cd85f..385fbca2b61c5c 100644 --- a/cli-output/src/cli_output.rs +++ b/cli-output/src/cli_output.rs @@ -582,6 +582,41 @@ pub struct CliEpochReward { pub apr: f64, } +fn show_votes_and_credits( + f: &mut fmt::Formatter, + votes: &[CliLockout], + epoch_voting_history: &[CliEpochVotingHistory], +) -> fmt::Result { + if votes.is_empty() { + return Ok(()); + } + + writeln!(f, "Recent Votes:")?; + for vote in votes { + writeln!(f, "- slot: {}", vote.slot)?; + writeln!(f, " confirmation count: {}", vote.confirmation_count)?; + } + writeln!(f, "Epoch Voting History (without skipped slots):")?; + for entry in epoch_voting_history { + writeln!( + f, // tame fmt so that this will be folded like following + "- epoch: {}", + entry.epoch + )?; + writeln!( + f, + " credits range: [{}..{})", + entry.prev_credits, entry.credits + )?; + writeln!( + f, + " credits/slots: {}/{}", + entry.credits_earned, entry.slots_in_epoch + )?; + } + Ok(()) +} + fn show_epoch_rewards( f: &mut fmt::Formatter, epoch_rewards: &Option>, @@ -1009,24 +1044,7 @@ impl fmt::Display for CliVoteAccount { unix_timestamp_to_string(self.recent_timestamp.timestamp), self.recent_timestamp.slot )?; - if !self.votes.is_empty() { - writeln!(f, "Recent Votes:")?; - for vote in &self.votes { - writeln!( - f, - "- slot: {}\n confirmation count: {}", - vote.slot, vote.confirmation_count - )?; - } - writeln!(f, "Epoch Voting History:")?; - for epoch_info in &self.epoch_voting_history { - writeln!( - f, - "- epoch: {}\n slots in epoch: {}\n credits earned: {}", - epoch_info.epoch, epoch_info.slots_in_epoch, epoch_info.credits_earned, - )?; - } - } + show_votes_and_credits(f, &self.votes, &self.epoch_voting_history)?; show_epoch_rewards(f, &self.epoch_rewards)?; Ok(()) } @@ -1065,6 +1083,8 @@ pub struct CliEpochVotingHistory { pub epoch: Epoch, pub slots_in_epoch: u64, pub credits_earned: u64, + pub credits: u64, + pub prev_credits: u64, } #[derive(Serialize, Deserialize)] diff --git a/cli/src/vote.rs b/cli/src/vote.rs index e831cb5205e531..9bbbe353ffc23a 100644 --- a/cli/src/vote.rs +++ b/cli/src/vote.rs @@ -685,13 +685,15 @@ pub fn process_show_vote_account( for vote in &vote_state.votes { votes.push(vote.into()); } - for (epoch, credits, prev_credits) in vote_state.epoch_credits() { + for (epoch, credits, prev_credits) in vote_state.epoch_credits().iter().copied() { let credits_earned = credits - prev_credits; - let slots_in_epoch = epoch_schedule.get_slots_in_epoch(*epoch); + let slots_in_epoch = epoch_schedule.get_slots_in_epoch(epoch); epoch_voting_history.push(CliEpochVotingHistory { - epoch: *epoch, + epoch, slots_in_epoch, credits_earned, + credits, + prev_credits, }); } } From 14bdcba429c22289366494ea276560be967c8b9b Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Wed, 4 Nov 2020 21:54:30 +0900 Subject: [PATCH 2/3] Improve wording --- cli-output/src/cli_output.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli-output/src/cli_output.rs b/cli-output/src/cli_output.rs index 385fbca2b61c5c..453177103d2de0 100644 --- a/cli-output/src/cli_output.rs +++ b/cli-output/src/cli_output.rs @@ -596,7 +596,8 @@ fn show_votes_and_credits( writeln!(f, "- slot: {}", vote.slot)?; writeln!(f, " confirmation count: {}", vote.confirmation_count)?; } - writeln!(f, "Epoch Voting History (without skipped slots):")?; + writeln!(f, "Epoch Voting History:")?; + writeln!(f, "* missed credits include slots unavailable to vote on due to delinquent leaders")?; for entry in epoch_voting_history { writeln!( f, // tame fmt so that this will be folded like following From 2795a84bae1f3e561978628e1b3db322eba5b33c Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Wed, 4 Nov 2020 22:06:09 +0900 Subject: [PATCH 3/3] fmt --- cli-output/src/cli_output.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cli-output/src/cli_output.rs b/cli-output/src/cli_output.rs index 453177103d2de0..5572156ea2d1e7 100644 --- a/cli-output/src/cli_output.rs +++ b/cli-output/src/cli_output.rs @@ -597,7 +597,10 @@ fn show_votes_and_credits( writeln!(f, " confirmation count: {}", vote.confirmation_count)?; } writeln!(f, "Epoch Voting History:")?; - writeln!(f, "* missed credits include slots unavailable to vote on due to delinquent leaders")?; + writeln!( + f, + "* missed credits include slots unavailable to vote on due to delinquent leaders", + )?; for entry in epoch_voting_history { writeln!( f, // tame fmt so that this will be folded like following