Skip to content

Commit 714af03

Browse files
wen-codingbw-solana
authored andcommitted
Add AlpenglowVoteState to VoteAccount. (anza-xyz#84)
1 parent 5957c23 commit 714af03

File tree

16 files changed

+269
-51
lines changed

16 files changed

+269
-51
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/src/commitment_service.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,11 @@ impl AggregateCommitmentService {
208208
let vote_state = if pubkey == node_vote_pubkey {
209209
// Override old vote_state in bank with latest one for my own vote pubkey
210210
node_vote_state.clone()
211+
} else if let Some(vote_state_view) = account.vote_state_view() {
212+
TowerVoteState::from(vote_state_view)
211213
} else {
212-
TowerVoteState::from(account.vote_state_view())
214+
// Alpenglow doesn't need to aggregate commitment.
215+
continue;
213216
};
214217
Self::aggregate_commitment_for_vote_account(
215218
&mut commitment,
@@ -544,7 +547,7 @@ mod tests {
544547
fn test_highest_super_majority_root_advance() {
545548
fn get_vote_state(vote_pubkey: Pubkey, bank: &Bank) -> TowerVoteState {
546549
let vote_account = bank.get_vote_account(&vote_pubkey).unwrap();
547-
TowerVoteState::from(vote_account.vote_state_view())
550+
TowerVoteState::from(vote_account.vote_state_view().unwrap())
548551
}
549552

550553
let block_commitment_cache = RwLock::new(BlockCommitmentCache::new_for_tests());

core/src/consensus.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,11 @@ impl Tower {
407407
if voted_stake == 0 {
408408
continue;
409409
}
410-
trace!("{vote_account_pubkey} {key} with stake {voted_stake}");
411-
let mut vote_state = TowerVoteState::from(account.vote_state_view());
410+
trace!("{} {} with stake {}", vote_account_pubkey, key, voted_stake);
411+
let Some(vote_state_view) = account.vote_state_view() else {
412+
continue; // not relevant to Alpenglow.
413+
};
414+
let mut vote_state = TowerVoteState::from(vote_state_view);
412415
for vote in &vote_state.votes {
413416
lockout_intervals
414417
.entry(vote.last_locked_out_slot())
@@ -610,7 +613,9 @@ impl Tower {
610613

611614
pub fn last_voted_slot_in_bank(bank: &Bank, vote_account_pubkey: &Pubkey) -> Option<Slot> {
612615
let vote_account = bank.get_vote_account(vote_account_pubkey)?;
613-
vote_account.vote_state_view().last_voted_slot()
616+
// TODO(wen): make this work for Alpenglow.
617+
let vote_state_view = vote_account.vote_state_view()?;
618+
vote_state_view.last_voted_slot()
614619
}
615620

616621
pub fn record_bank_vote(&mut self, bank: &Bank) -> Option<Slot> {
@@ -1615,7 +1620,11 @@ impl Tower {
16151620
bank: &Bank,
16161621
) {
16171622
if let Some(vote_account) = bank.get_vote_account(vote_account_pubkey) {
1618-
self.vote_state = TowerVoteState::from(vote_account.vote_state_view());
1623+
self.vote_state = TowerVoteState::from(
1624+
vote_account
1625+
.vote_state_view()
1626+
.expect("must be TowerBFT account"),
1627+
);
16191628
self.initialize_root(root);
16201629
self.initialize_lockouts(|v| v.slot() > root);
16211630
} else {
@@ -2439,7 +2448,7 @@ pub mod test {
24392448
.unwrap()
24402449
.get_vote_account(&vote_pubkey)
24412450
.unwrap();
2442-
let state = observed.vote_state_view();
2451+
let state = observed.vote_state_view().unwrap();
24432452
info!("observed tower: {:#?}", state.votes_iter().collect_vec());
24442453

24452454
let num_slots_to_try = 200;

core/src/replay_stage.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2975,7 +2975,16 @@ impl ReplayStage {
29752975
}
29762976
Some(vote_account) => vote_account,
29772977
};
2978-
let vote_state = vote_account.vote_state_view();
2978+
let vote_state = match vote_account.alpenglow_vote_state() {
2979+
None => {
2980+
warn!(
2981+
"Vote account {} does not have an Alpenglow vote state. Unable to vote",
2982+
vote_account_pubkey,
2983+
);
2984+
return GenerateVoteTxResult::Failed;
2985+
}
2986+
Some(vote_state) => vote_state,
2987+
};
29792988
if *vote_state.node_pubkey() != node_keypair.pubkey() {
29802989
info!(
29812990
"Vote account node_pubkey mismatch: {} (expected: {}). Unable to vote",
@@ -2996,7 +3005,7 @@ impl ReplayStage {
29963005

29973006
let authorized_voter_keypair = match authorized_voter_keypairs
29983007
.iter()
2999-
.find(|keypair| keypair.pubkey() == *authorized_voter_pubkey)
3008+
.find(|keypair| keypair.pubkey() == authorized_voter_pubkey)
30003009
{
30013010
None => {
30023011
warn!(
@@ -3063,7 +3072,16 @@ impl ReplayStage {
30633072
}
30643073
Some(vote_account) => vote_account,
30653074
};
3066-
let vote_state_view = vote_account.vote_state_view();
3075+
let vote_state_view = match vote_account.vote_state_view() {
3076+
None => {
3077+
warn!(
3078+
"Vote account {} does not have a vote state. Unable to vote",
3079+
vote_account_pubkey,
3080+
);
3081+
return GenerateVoteTxResult::Failed;
3082+
}
3083+
Some(vote_state_view) => vote_state_view,
3084+
};
30673085
if vote_state_view.node_pubkey() != &node_keypair.pubkey() {
30683086
info!(
30693087
"Vote account node_pubkey mismatch: {} (expected: {}). Unable to vote",
@@ -4304,7 +4322,10 @@ impl ReplayStage {
43044322
let Some(vote_account) = bank.get_vote_account(my_vote_pubkey) else {
43054323
return;
43064324
};
4307-
let mut bank_vote_state = TowerVoteState::from(vote_account.vote_state_view());
4325+
let Some(vote_state_view) = vote_account.vote_state_view() else {
4326+
return;
4327+
};
4328+
let mut bank_vote_state = TowerVoteState::from(vote_state_view);
43084329
if bank_vote_state.last_voted_slot() <= tower.vote_state.last_voted_slot() {
43094330
return;
43104331
}
@@ -8710,6 +8731,7 @@ pub(crate) mod tests {
87108731
assert_eq!(
87118732
vote_account
87128733
.vote_state_view()
8734+
.unwrap()
87138735
.votes_iter()
87148736
.map(|lockout| lockout.slot())
87158737
.collect_vec(),

core/src/vote_simulator.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ impl VoteSimulator {
105105
let tower_sync = if let Some(vote_account) =
106106
parent_bank.get_vote_account(&keypairs.vote_keypair.pubkey())
107107
{
108-
let mut vote_state = TowerVoteState::from(vote_account.vote_state_view());
108+
let mut vote_state = TowerVoteState::from(
109+
vote_account.vote_state_view().expect("must be TowerBFT"),
110+
);
109111
vote_state.process_next_vote_slot(parent);
110112
TowerSync::new(
111113
vote_state.votes,
@@ -136,7 +138,7 @@ impl VoteSimulator {
136138
let vote_account = new_bank
137139
.get_vote_account(&keypairs.vote_keypair.pubkey())
138140
.unwrap();
139-
let vote_state_view = vote_account.vote_state_view();
141+
let vote_state_view = vote_account.vote_state_view().unwrap();
140142
assert!(vote_state_view
141143
.votes_iter()
142144
.any(|lockout| lockout.slot() == parent));

ledger-tool/src/main.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,10 @@ fn graph_forks(bank_forks: &BankForks, config: &GraphConfig) -> String {
210210
.map(|(_, (stake, _))| stake)
211211
.sum();
212212
for (stake, vote_account) in bank.vote_accounts().values() {
213-
let vote_state_view = vote_account.vote_state_view();
213+
// TODO(wen): make this work for Alpenglow
214+
let Some(vote_state_view) = vote_account.vote_state_view() else {
215+
continue;
216+
};
214217
if let Some(last_vote) = vote_state_view.last_voted_slot() {
215218
let entry = last_votes.entry(*vote_state_view.node_pubkey()).or_insert((
216219
last_vote,
@@ -250,7 +253,10 @@ fn graph_forks(bank_forks: &BankForks, config: &GraphConfig) -> String {
250253
let mut first = true;
251254
loop {
252255
for (_, vote_account) in bank.vote_accounts().values() {
253-
let vote_state_view = vote_account.vote_state_view();
256+
// TODO(wen): make this work for Alpenglow
257+
let Some(vote_state_view) = vote_account.vote_state_view() else {
258+
continue;
259+
};
254260
if let Some(last_vote) = vote_state_view.last_voted_slot() {
255261
let validator_votes =
256262
all_votes.entry(*vote_state_view.node_pubkey()).or_default();

ledger/src/blockstore_processor.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2060,7 +2060,11 @@ fn supermajority_root_from_vote_accounts(
20602060
return None;
20612061
}
20622062

2063-
Some((account.vote_state_view().root_slot()?, *stake))
2063+
if let Some(vote_state_view) = account.vote_state_view() {
2064+
Some((vote_state_view.root_slot()?, *stake))
2065+
} else {
2066+
None
2067+
}
20642068
})
20652069
.collect();
20662070

programs/sbf/Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/src/rpc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,8 @@ impl JsonRpcRequestProcessor {
11711171
}
11721172
}
11731173

1174-
let vote_state_view = account.vote_state_view();
1174+
// TODO(wen): make this work for Alpenglow
1175+
let vote_state_view = account.vote_state_view()?;
11751176
let last_vote = vote_state_view.last_voted_slot().unwrap_or(0);
11761177
let num_epoch_credits = vote_state_view.num_epoch_credits();
11771178
let epoch_credits = vote_state_view

runtime/src/bank.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2432,7 +2432,8 @@ impl Bank {
24322432
let slots_per_epoch = self.epoch_schedule().slots_per_epoch;
24332433
let vote_accounts = self.vote_accounts();
24342434
let recent_timestamps = vote_accounts.iter().filter_map(|(pubkey, (_, account))| {
2435-
let vote_state = account.vote_state_view();
2435+
// TODO(wen): make this work for Alpenglow.
2436+
let vote_state = account.vote_state_view()?;
24362437
let last_timestamp = vote_state.last_timestamp();
24372438
let slot_delta = self.slot().checked_sub(last_timestamp.slot)?;
24382439
(slot_delta <= slots_per_epoch)

0 commit comments

Comments
 (0)