Skip to content

Commit d546280

Browse files
authored
refactor: replace more uses of VoteState with TowerVoteState (#4976)
1 parent 29e8ff4 commit d546280

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

core/src/consensus.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ use {
3939
vote_error::VoteError,
4040
vote_instruction,
4141
vote_state::{
42-
process_slot_vote_unchecked, BlockTimestamp, Lockout, TowerSync, Vote,
43-
VoteState1_14_11, VoteStateUpdate, MAX_LOCKOUT_HISTORY,
42+
BlockTimestamp, Lockout, TowerSync, Vote, VoteState1_14_11, VoteStateUpdate,
43+
MAX_LOCKOUT_HISTORY,
4444
},
4545
},
4646
std::{
@@ -406,10 +406,10 @@ impl Tower {
406406
continue;
407407
}
408408
trace!("{} {} with stake {}", vote_account_pubkey, key, voted_stake);
409-
let mut vote_state = account.vote_state().clone();
409+
let mut vote_state = TowerVoteState::from(account.vote_state().clone());
410410
for vote in &vote_state.votes {
411411
lockout_intervals
412-
.entry(vote.lockout.last_locked_out_slot())
412+
.entry(vote.last_locked_out_slot())
413413
.or_default()
414414
.push((vote.slot(), key));
415415
}
@@ -450,7 +450,7 @@ impl Tower {
450450
);
451451
}
452452

453-
process_slot_vote_unchecked(&mut vote_state, bank_slot);
453+
vote_state.process_next_vote_slot(bank_slot);
454454

455455
for vote in &vote_state.votes {
456456
vote_slots.insert(vote.slot());
@@ -1795,7 +1795,7 @@ pub mod test {
17951795
},
17961796
solana_vote::vote_account::VoteAccount,
17971797
solana_vote_program::vote_state::{
1798-
Vote, VoteState, VoteStateVersions, MAX_LOCKOUT_HISTORY,
1798+
process_slot_vote_unchecked, Vote, VoteState, VoteStateVersions, MAX_LOCKOUT_HISTORY,
17991799
},
18001800
std::{
18011801
collections::{HashMap, VecDeque},

core/src/replay_stage.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3624,7 +3624,7 @@ impl ReplayStage {
36243624
let Some(vote_account) = bank.get_vote_account(my_vote_pubkey) else {
36253625
return;
36263626
};
3627-
let mut bank_vote_state = vote_account.vote_state().clone();
3627+
let mut bank_vote_state = TowerVoteState::from(vote_account.vote_state().clone());
36283628
if bank_vote_state.last_voted_slot() <= tower.vote_state.last_voted_slot() {
36293629
return;
36303630
}
@@ -3673,8 +3673,8 @@ impl ReplayStage {
36733673
}
36743674
}
36753675

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

36793679
let last_voted_slot = tower.vote_state.last_voted_slot().unwrap_or(
36803680
// If our local root is higher than the highest slot in `bank_vote_state` due to

core/src/vote_simulator.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use {
88
heaviest_subtree_fork_choice::HeaviestSubtreeForkChoice,
99
latest_validator_votes_for_frozen_banks::LatestValidatorVotesForFrozenBanks,
1010
progress_map::{ForkProgress, ProgressMap},
11+
tower_vote_state::TowerVoteState,
1112
Tower,
1213
},
1314
repair::cluster_slot_state_verifier::{
@@ -27,7 +28,7 @@ use {
2728
},
2829
solana_sdk::{clock::Slot, hash::Hash, pubkey::Pubkey, signature::Signer},
2930
solana_vote::vote_transaction,
30-
solana_vote_program::vote_state::{process_vote_unchecked, Lockout, TowerSync},
31+
solana_vote_program::vote_state::{Lockout, TowerSync},
3132
std::{
3233
collections::{HashMap, HashSet, VecDeque},
3334
sync::{Arc, RwLock},
@@ -102,17 +103,11 @@ impl VoteSimulator {
102103
let tower_sync = if let Some(vote_account) =
103104
parent_bank.get_vote_account(&keypairs.vote_keypair.pubkey())
104105
{
105-
let mut vote_state = vote_account.vote_state().clone();
106-
process_vote_unchecked(
107-
&mut vote_state,
108-
solana_vote_program::vote_state::Vote::new(
109-
vec![parent],
110-
parent_bank.hash(),
111-
),
112-
)
113-
.unwrap();
106+
let mut vote_state =
107+
TowerVoteState::from(vote_account.vote_state().clone());
108+
vote_state.process_next_vote_slot(parent);
114109
TowerSync::new(
115-
vote_state.votes.iter().map(|vote| vote.lockout).collect(),
110+
vote_state.votes,
116111
vote_state.root_slot,
117112
parent_bank.hash(),
118113
Hash::default(),

0 commit comments

Comments
 (0)