Skip to content

Commit

Permalink
refactor: replace more uses of VoteState with TowerVoteState (#4976)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry authored Feb 26, 2025
1 parent 29e8ff4 commit d546280
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
12 changes: 6 additions & 6 deletions core/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ use {
vote_error::VoteError,
vote_instruction,
vote_state::{
process_slot_vote_unchecked, BlockTimestamp, Lockout, TowerSync, Vote,
VoteState1_14_11, VoteStateUpdate, MAX_LOCKOUT_HISTORY,
BlockTimestamp, Lockout, TowerSync, Vote, VoteState1_14_11, VoteStateUpdate,
MAX_LOCKOUT_HISTORY,
},
},
std::{
Expand Down Expand Up @@ -406,10 +406,10 @@ impl Tower {
continue;
}
trace!("{} {} with stake {}", vote_account_pubkey, key, voted_stake);
let mut vote_state = account.vote_state().clone();
let mut vote_state = TowerVoteState::from(account.vote_state().clone());
for vote in &vote_state.votes {
lockout_intervals
.entry(vote.lockout.last_locked_out_slot())
.entry(vote.last_locked_out_slot())
.or_default()
.push((vote.slot(), key));
}
Expand Down Expand Up @@ -450,7 +450,7 @@ impl Tower {
);
}

process_slot_vote_unchecked(&mut vote_state, bank_slot);
vote_state.process_next_vote_slot(bank_slot);

for vote in &vote_state.votes {
vote_slots.insert(vote.slot());
Expand Down Expand Up @@ -1795,7 +1795,7 @@ pub mod test {
},
solana_vote::vote_account::VoteAccount,
solana_vote_program::vote_state::{
Vote, VoteState, VoteStateVersions, MAX_LOCKOUT_HISTORY,
process_slot_vote_unchecked, Vote, VoteState, VoteStateVersions, MAX_LOCKOUT_HISTORY,
},
std::{
collections::{HashMap, VecDeque},
Expand Down
6 changes: 3 additions & 3 deletions core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3624,7 +3624,7 @@ impl ReplayStage {
let Some(vote_account) = bank.get_vote_account(my_vote_pubkey) else {
return;
};
let mut bank_vote_state = vote_account.vote_state().clone();
let mut bank_vote_state = TowerVoteState::from(vote_account.vote_state().clone());
if bank_vote_state.last_voted_slot() <= tower.vote_state.last_voted_slot() {
return;
}
Expand Down Expand Up @@ -3673,8 +3673,8 @@ impl ReplayStage {
}
}

tower.vote_state.root_slot = bank_vote_state.root_slot;
tower.vote_state.votes = bank_vote_state.votes.into_iter().map(Into::into).collect();
// adopt the bank vote state
tower.vote_state = bank_vote_state;

let last_voted_slot = tower.vote_state.last_voted_slot().unwrap_or(
// If our local root is higher than the highest slot in `bank_vote_state` due to
Expand Down
17 changes: 6 additions & 11 deletions core/src/vote_simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use {
heaviest_subtree_fork_choice::HeaviestSubtreeForkChoice,
latest_validator_votes_for_frozen_banks::LatestValidatorVotesForFrozenBanks,
progress_map::{ForkProgress, ProgressMap},
tower_vote_state::TowerVoteState,
Tower,
},
repair::cluster_slot_state_verifier::{
Expand All @@ -27,7 +28,7 @@ use {
},
solana_sdk::{clock::Slot, hash::Hash, pubkey::Pubkey, signature::Signer},
solana_vote::vote_transaction,
solana_vote_program::vote_state::{process_vote_unchecked, Lockout, TowerSync},
solana_vote_program::vote_state::{Lockout, TowerSync},
std::{
collections::{HashMap, HashSet, VecDeque},
sync::{Arc, RwLock},
Expand Down Expand Up @@ -102,17 +103,11 @@ impl VoteSimulator {
let tower_sync = if let Some(vote_account) =
parent_bank.get_vote_account(&keypairs.vote_keypair.pubkey())
{
let mut vote_state = vote_account.vote_state().clone();
process_vote_unchecked(
&mut vote_state,
solana_vote_program::vote_state::Vote::new(
vec![parent],
parent_bank.hash(),
),
)
.unwrap();
let mut vote_state =
TowerVoteState::from(vote_account.vote_state().clone());
vote_state.process_next_vote_slot(parent);
TowerSync::new(
vote_state.votes.iter().map(|vote| vote.lockout).collect(),
vote_state.votes,
vote_state.root_slot,
parent_bank.hash(),
Hash::default(),
Expand Down

0 comments on commit d546280

Please sign in to comment.