From c1c5b36687fa1a17958b02e8bc2b3543787b9dc3 Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Wed, 10 Feb 2021 10:57:14 +0900 Subject: [PATCH 1/3] Improve vote-account for logical flow/reasoning --- cli-output/src/cli_output.rs | 67 ++++++++++++++++++++++++----- programs/vote/src/vote_state/mod.rs | 2 +- 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/cli-output/src/cli_output.rs b/cli-output/src/cli_output.rs index ec5743bbde5..c41adcad190 100644 --- a/cli-output/src/cli_output.rs +++ b/cli-output/src/cli_output.rs @@ -29,7 +29,7 @@ use { solana_stake_program::stake_state::{Authorized, Lockup}, solana_vote_program::{ authorized_voters::AuthorizedVoters, - vote_state::{BlockTimestamp, Lockout}, + vote_state::{BlockTimestamp, Lockout, MAX_EPOCH_CREDITS_HISTORY, MAX_LOCKOUT_HISTORY}, }, std::{ collections::{BTreeMap, HashMap}, @@ -610,17 +610,48 @@ fn show_votes_and_credits( 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:")?; writeln!( f, - "* missed credits include slots unavailable to vote on due to delinquent leaders", + "{} Votes (using {}/{} entries):", + (if votes.len() < MAX_LOCKOUT_HISTORY { + "All" + } else { + "Recent" + }), + votes.len(), + MAX_LOCKOUT_HISTORY )?; - for entry in epoch_voting_history { + + for vote in votes.iter().rev() { + writeln!(f, "- slot: {} (confirmation count: {})", vote.slot, vote.confirmation_count)?; + } + if let Some(newest) = epoch_voting_history.iter().rev().next() { + writeln!( + f, + "- ... (truncated older {} votes, which was rooted and became credits)", + newest.credits + )?; + } + + if !epoch_voting_history.is_empty() { + writeln!( + f, + "{} Epoch Voting History (using {}/{} entries):", + (if epoch_voting_history.len() < MAX_EPOCH_CREDITS_HISTORY { + "All" + } else { + "Recent" + }), + epoch_voting_history.len(), + MAX_EPOCH_CREDITS_HISTORY + )?; + writeln!( + f, + "* missed credits include slots unavailable to vote on due to delinquent leaders", + )?; + } + + for entry in epoch_voting_history.iter().rev() { writeln!( f, // tame fmt so that this will be folded like following "- epoch: {}", @@ -628,7 +659,7 @@ fn show_votes_and_credits( )?; writeln!( f, - " credits range: [{}..{})", + " credits range: ({}..{}]", entry.prev_credits, entry.credits )?; writeln!( @@ -637,6 +668,22 @@ fn show_votes_and_credits( entry.credits_earned, entry.slots_in_epoch )?; } + if let Some(oldest) = epoch_voting_history.iter().next() { + if oldest.prev_credits > 0 { + // Oldest entry doesn't start with 0. so history must be truncated... + + // count of this combined pseudo credits range: (0..=oldest.prev_credits] like the above + // (or this is just [1..=oldest.prev_credits] for human's simpler minds) + let count = oldest.prev_credits; + + writeln!( + f, + "- ... (truncated older history covering {} credits/rooted votes)", + count + )?; + } + } + Ok(()) } diff --git a/programs/vote/src/vote_state/mod.rs b/programs/vote/src/vote_state/mod.rs index 99517389fe0..0d0b2b464f1 100644 --- a/programs/vote/src/vote_state/mod.rs +++ b/programs/vote/src/vote_state/mod.rs @@ -31,7 +31,7 @@ pub const MAX_LOCKOUT_HISTORY: usize = 31; pub const INITIAL_LOCKOUT: usize = 2; // Maximum number of credits history to keep around -const MAX_EPOCH_CREDITS_HISTORY: usize = 64; +pub const MAX_EPOCH_CREDITS_HISTORY: usize = 64; #[frozen_abi(digest = "Ch2vVEwos2EjAVqSHCyJjnN2MNX1yrpapZTGhMSCjWUH")] #[derive(Serialize, Default, Deserialize, Debug, PartialEq, Eq, Clone, AbiExample)] From def6ad1a4aab24094acc728d2364e7e571c8dfef Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Wed, 10 Feb 2021 22:39:46 +0900 Subject: [PATCH 2/3] Clean up --- cli-output/src/cli_output.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cli-output/src/cli_output.rs b/cli-output/src/cli_output.rs index c41adcad190..ccc8b8ac186 100644 --- a/cli-output/src/cli_output.rs +++ b/cli-output/src/cli_output.rs @@ -610,10 +610,13 @@ fn show_votes_and_credits( return Ok(()); } + // Existence of this should guarantee the occurrence of vote truncation + let newest_history_entry = epoch_voting_history.iter().rev().next(); + writeln!( f, "{} Votes (using {}/{} entries):", - (if votes.len() < MAX_LOCKOUT_HISTORY { + (if newest_history_entry.is_none() { "All" } else { "Recent" @@ -623,9 +626,13 @@ fn show_votes_and_credits( )?; for vote in votes.iter().rev() { - writeln!(f, "- slot: {} (confirmation count: {})", vote.slot, vote.confirmation_count)?; + writeln!( + f, + "- slot: {} (confirmation count: {})", + vote.slot, vote.confirmation_count + )?; } - if let Some(newest) = epoch_voting_history.iter().rev().next() { + if let Some(newest) = newest_history_entry { writeln!( f, "- ... (truncated older {} votes, which was rooted and became credits)", From 8ac27e7d221e024231f8a3e9b66bb85690a9f732 Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Thu, 11 Feb 2021 19:11:51 +0900 Subject: [PATCH 3/3] Update messages --- cli-output/src/cli_output.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli-output/src/cli_output.rs b/cli-output/src/cli_output.rs index ccc8b8ac186..cc7be5fd630 100644 --- a/cli-output/src/cli_output.rs +++ b/cli-output/src/cli_output.rs @@ -635,7 +635,7 @@ fn show_votes_and_credits( if let Some(newest) = newest_history_entry { writeln!( f, - "- ... (truncated older {} votes, which was rooted and became credits)", + "- ... (truncated {} rooted votes, which have been credited)", newest.credits )?; } @@ -685,7 +685,7 @@ fn show_votes_and_credits( writeln!( f, - "- ... (truncated older history covering {} credits/rooted votes)", + "- ... (omitting {} past rooted votes, which have already been credited)", count )?; }