Skip to content

Commit

Permalink
Implement timely vote credits feature (#31291)
Browse files Browse the repository at this point in the history
  • Loading branch information
bji authored Aug 10, 2023
1 parent d26e3ff commit 35ec7bf
Show file tree
Hide file tree
Showing 7 changed files with 601 additions and 99 deletions.
36 changes: 16 additions & 20 deletions cli-output/src/cli_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ use {
},
solana_vote_program::{
authorized_voters::AuthorizedVoters,
vote_state::{
BlockTimestamp, LandedVote, Lockout, MAX_EPOCH_CREDITS_HISTORY, MAX_LOCKOUT_HISTORY,
},
vote_state::{BlockTimestamp, LandedVote, MAX_EPOCH_CREDITS_HISTORY, MAX_LOCKOUT_HISTORY},
},
std::{
collections::{BTreeMap, HashMap},
Expand Down Expand Up @@ -1047,7 +1045,7 @@ impl fmt::Display for CliKeyedEpochRewards {

fn show_votes_and_credits(
f: &mut fmt::Formatter,
votes: &[CliLockout],
votes: &[CliLandedVote],
epoch_voting_history: &[CliEpochVotingHistory],
) -> fmt::Result {
if votes.is_empty() {
Expand All @@ -1070,11 +1068,16 @@ fn show_votes_and_credits(
)?;

for vote in votes.iter().rev() {
writeln!(
write!(
f,
"- slot: {} (confirmation count: {})",
vote.slot, vote.confirmation_count
)?;
if vote.latency == 0 {
writeln!(f)?;
} else {
writeln!(f, " (latency {})", vote.latency)?;
}
}
if let Some(newest) = newest_history_entry {
writeln!(
Expand Down Expand Up @@ -1555,7 +1558,7 @@ pub struct CliVoteAccount {
pub commission: u8,
pub root_slot: Option<Slot>,
pub recent_timestamp: BlockTimestamp,
pub votes: Vec<CliLockout>,
pub votes: Vec<CliLandedVote>,
pub epoch_voting_history: Vec<CliEpochVotingHistory>,
#[serde(skip_serializing)]
pub use_lamports_unit: bool,
Expand Down Expand Up @@ -1637,25 +1640,18 @@ pub struct CliEpochVotingHistory {

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CliLockout {
pub struct CliLandedVote {
pub latency: u8,
pub slot: Slot,
pub confirmation_count: u32,
}

impl From<&Lockout> for CliLockout {
fn from(lockout: &Lockout) -> Self {
Self {
slot: lockout.slot(),
confirmation_count: lockout.confirmation_count(),
}
}
}

impl From<&LandedVote> for CliLockout {
fn from(vote: &LandedVote) -> Self {
impl From<&LandedVote> for CliLandedVote {
fn from(landed_vote: &LandedVote) -> Self {
Self {
slot: vote.slot(),
confirmation_count: vote.confirmation_count(),
latency: landed_vote.latency,
slot: landed_vote.slot(),
confirmation_count: landed_vote.confirmation_count(),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions cli/src/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use {
offline::*,
},
solana_cli_output::{
return_signers_with_config, CliEpochVotingHistory, CliLockout, CliVoteAccount,
return_signers_with_config, CliEpochVotingHistory, CliLandedVote, CliVoteAccount,
ReturnSignersConfig,
},
solana_remote_wallet::remote_wallet::RemoteWalletManager,
Expand Down Expand Up @@ -1215,7 +1215,7 @@ pub fn process_show_vote_account(

let epoch_schedule = rpc_client.get_epoch_schedule()?;

let mut votes: Vec<CliLockout> = vec![];
let mut votes: Vec<CliLandedVote> = vec![];
let mut epoch_voting_history: Vec<CliEpochVotingHistory> = vec![];
if !vote_state.votes.is_empty() {
for vote in &vote_state.votes {
Expand Down
2 changes: 1 addition & 1 deletion programs/vote/benches/process_vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn create_accounts() -> (Slot, SlotHashes, Vec<TransactionAccount>, Vec<AccountM
);

for next_vote_slot in 0..num_initial_votes {
vote_state.process_next_vote_slot(next_vote_slot, 0);
vote_state.process_next_vote_slot(next_vote_slot, 0, 0);
}
let mut vote_account_data: Vec<u8> = vec![0; VoteState::size_of()];
let versioned = VoteStateVersions::new_current(vote_state);
Expand Down
Loading

0 comments on commit 35ec7bf

Please sign in to comment.