-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Improve vote-account for logical flow/reasoning #15237
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,25 +610,63 @@ 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:")?; | ||
| // Existence of this should guarantee the occurrence of vote truncation | ||
| let newest_history_entry = epoch_voting_history.iter().rev().next(); | ||
|
|
||
| writeln!( | ||
| f, | ||
| "* missed credits include slots unavailable to vote on due to delinquent leaders", | ||
| "{} Votes (using {}/{} entries):", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The subtle thing here is that 29/31 is possible even if vote truncation started because fork switch. So, the |
||
| (if newest_history_entry.is_none() { | ||
| "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) = newest_history_entry { | ||
| writeln!( | ||
| f, | ||
| "- ... (truncated {} rooted votes, which have been credited)", | ||
| newest.credits | ||
| )?; | ||
| } | ||
|
|
||
| if !epoch_voting_history.is_empty() { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, originally, showed titles for no good reason even if |
||
| writeln!( | ||
| f, | ||
| "{} Epoch Voting History (using {}/{} entries):", | ||
| (if epoch_voting_history.len() < MAX_EPOCH_CREDITS_HISTORY { | ||
| "All" | ||
| } else { | ||
| "Recent" | ||
| }), | ||
|
Comment on lines
+647
to
+651
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made this section dynamic; similar treatment was applied to the votes section for consistentcy. ... so that we can quickly determine the existence of truncation by looking either at the top or bottom of possibly long list. :) |
||
| 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() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: Maybe give this block the single-line treatment as well?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, I rather keep this as-is. Maybe, the single-line style condenses too much information in a single line. |
||
| writeln!( | ||
| f, // tame fmt so that this will be folded like following | ||
| "- epoch: {}", | ||
| entry.epoch | ||
| )?; | ||
| writeln!( | ||
| f, | ||
| " credits range: [{}..{})", | ||
| " credits range: ({}..{}]", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as this |
||
| entry.prev_credits, entry.credits | ||
| )?; | ||
| writeln!( | ||
|
|
@@ -637,6 +675,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, | ||
| "- ... (omitting {} past rooted votes, which have already been credited)", | ||
| count | ||
| )?; | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making this const |
||
|
|
||
| #[frozen_abi(digest = "Ch2vVEwos2EjAVqSHCyJjnN2MNX1yrpapZTGhMSCjWUH")] | ||
| #[derive(Serialize, Default, Deserialize, Debug, PartialEq, Eq, Clone, AbiExample)] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Condensed this two lines to one for the precious vertical screen estate. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: What do you think about saving the per-line field name redundancy with a header line at the top?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I actually like this
epoch-info-style (key: value). I might do this once I got enough motivation in the future. :)