Skip to content

Commit ea019b8

Browse files
v2.1: cli: show max vote credits in vote-account based on TVC activation epoch (backport of #3776) (#3780)
cli: show max vote credits in vote-account based on TVC activation epoch (#3776) (cherry picked from commit b543f25) Co-authored-by: Ashwin Sekar <[email protected]>
1 parent d07fc9b commit ea019b8

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

cli-output/src/cli_output.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,8 +1163,9 @@ fn show_votes_and_credits(
11631163
)?;
11641164
writeln!(
11651165
f,
1166-
" credits/slots: {}/{}",
1167-
entry.credits_earned, entry.slots_in_epoch
1166+
" credits/max credits: {}/{}",
1167+
entry.credits_earned,
1168+
entry.slots_in_epoch * u64::from(entry.max_credits_per_slot)
11681169
)?;
11691170
}
11701171
if let Some(oldest) = epoch_voting_history.iter().next() {
@@ -1740,6 +1741,7 @@ pub struct CliEpochVotingHistory {
17401741
pub credits_earned: u64,
17411742
pub credits: u64,
17421743
pub prev_credits: u64,
1744+
pub max_credits_per_slot: u8,
17431745
}
17441746

17451747
#[derive(Serialize, Deserialize)]

cli/src/vote.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ use {
4040
solana_vote_program::{
4141
vote_error::VoteError,
4242
vote_instruction::{self, withdraw, CreateVoteAccountConfig},
43-
vote_state::{VoteAuthorize, VoteInit, VoteState, VoteStateVersions},
43+
vote_state::{
44+
VoteAuthorize, VoteInit, VoteState, VoteStateVersions, VOTE_CREDITS_MAXIMUM_PER_SLOT,
45+
},
4446
},
4547
std::rc::Rc,
4648
};
@@ -1277,6 +1279,9 @@ pub fn process_show_vote_account(
12771279
get_vote_account(rpc_client, vote_account_address, config.commitment)?;
12781280

12791281
let epoch_schedule = rpc_client.get_epoch_schedule()?;
1282+
let tvc_activation_slot =
1283+
rpc_client.get_feature_activation_slot(&solana_feature_set::timely_vote_credits::id())?;
1284+
let tvc_activation_epoch = tvc_activation_slot.map(|s| epoch_schedule.get_epoch(s));
12801285

12811286
let mut votes: Vec<CliLandedVote> = vec![];
12821287
let mut epoch_voting_history: Vec<CliEpochVotingHistory> = vec![];
@@ -1287,12 +1292,19 @@ pub fn process_show_vote_account(
12871292
for (epoch, credits, prev_credits) in vote_state.epoch_credits().iter().copied() {
12881293
let credits_earned = credits.saturating_sub(prev_credits);
12891294
let slots_in_epoch = epoch_schedule.get_slots_in_epoch(epoch);
1295+
let is_tvc_active = tvc_activation_epoch.map(|e| epoch >= e).unwrap_or_default();
1296+
let max_credits_per_slot = if is_tvc_active {
1297+
VOTE_CREDITS_MAXIMUM_PER_SLOT
1298+
} else {
1299+
1
1300+
};
12901301
epoch_voting_history.push(CliEpochVotingHistory {
12911302
epoch,
12921303
slots_in_epoch,
12931304
credits_earned,
12941305
credits,
12951306
prev_credits,
1307+
max_credits_per_slot,
12961308
});
12971309
}
12981310
}

0 commit comments

Comments
 (0)