Skip to content

Commit 4277eed

Browse files
wen-codingbw-solana
authored andcommitted
Add AlpenglowVoteState to VoteAccount. (anza-xyz#84)
1 parent d4d3caf commit 4277eed

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
@@ -202,8 +202,11 @@ impl AggregateCommitmentService {
202202
let vote_state = if pubkey == node_vote_pubkey {
203203
// Override old vote_state in bank with latest one for my own vote pubkey
204204
node_vote_state.clone()
205+
} else if let Some(vote_state_view) = account.vote_state_view() {
206+
TowerVoteState::from(vote_state_view)
205207
} else {
206-
TowerVoteState::from(account.vote_state_view())
208+
// Alpenglow doesn't need to aggregate commitment.
209+
continue;
207210
};
208211
Self::aggregate_commitment_for_vote_account(
209212
&mut commitment,
@@ -537,7 +540,7 @@ mod tests {
537540
fn test_highest_super_majority_root_advance() {
538541
fn get_vote_state(vote_pubkey: Pubkey, bank: &Bank) -> TowerVoteState {
539542
let vote_account = bank.get_vote_account(&vote_pubkey).unwrap();
540-
TowerVoteState::from(vote_account.vote_state_view())
543+
TowerVoteState::from(vote_account.vote_state_view().unwrap())
541544
}
542545

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

core/src/consensus.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,10 @@ impl Tower {
406406
continue;
407407
}
408408
trace!("{} {} with stake {}", vote_account_pubkey, key, voted_stake);
409-
let mut vote_state = TowerVoteState::from(account.vote_state_view());
409+
let Some(vote_state_view) = account.vote_state_view() else {
410+
continue; // not relevant to Alpenglow.
411+
};
412+
let mut vote_state = TowerVoteState::from(vote_state_view);
410413
for vote in &vote_state.votes {
411414
lockout_intervals
412415
.entry(vote.last_locked_out_slot())
@@ -608,7 +611,9 @@ impl Tower {
608611

609612
pub fn last_voted_slot_in_bank(bank: &Bank, vote_account_pubkey: &Pubkey) -> Option<Slot> {
610613
let vote_account = bank.get_vote_account(vote_account_pubkey)?;
611-
vote_account.vote_state_view().last_voted_slot()
614+
// TODO(wen): make this work for Alpenglow.
615+
let vote_state_view = vote_account.vote_state_view()?;
616+
vote_state_view.last_voted_slot()
612617
}
613618

614619
pub fn record_bank_vote(&mut self, bank: &Bank) -> Option<Slot> {
@@ -1617,7 +1622,11 @@ impl Tower {
16171622
bank: &Bank,
16181623
) {
16191624
if let Some(vote_account) = bank.get_vote_account(vote_account_pubkey) {
1620-
self.vote_state = TowerVoteState::from(vote_account.vote_state_view());
1625+
self.vote_state = TowerVoteState::from(
1626+
vote_account
1627+
.vote_state_view()
1628+
.expect("must be TowerBFT account"),
1629+
);
16211630
self.initialize_root(root);
16221631
self.initialize_lockouts(|v| v.slot() > root);
16231632
} else {
@@ -2445,7 +2454,7 @@ pub mod test {
24452454
.unwrap()
24462455
.get_vote_account(&vote_pubkey)
24472456
.unwrap();
2448-
let state = observed.vote_state_view();
2457+
let state = observed.vote_state_view().unwrap();
24492458
info!("observed tower: {:#?}", state.votes_iter().collect_vec());
24502459

24512460
let num_slots_to_try = 200;

core/src/replay_stage.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2970,7 +2970,16 @@ impl ReplayStage {
29702970
}
29712971
Some(vote_account) => vote_account,
29722972
};
2973-
let vote_state = vote_account.vote_state_view();
2973+
let vote_state = match vote_account.alpenglow_vote_state() {
2974+
None => {
2975+
warn!(
2976+
"Vote account {} does not have an Alpenglow vote state. Unable to vote",
2977+
vote_account_pubkey,
2978+
);
2979+
return GenerateVoteTxResult::Failed;
2980+
}
2981+
Some(vote_state) => vote_state,
2982+
};
29742983
if *vote_state.node_pubkey() != node_keypair.pubkey() {
29752984
info!(
29762985
"Vote account node_pubkey mismatch: {} (expected: {}). Unable to vote",
@@ -2991,7 +3000,7 @@ impl ReplayStage {
29913000

29923001
let authorized_voter_keypair = match authorized_voter_keypairs
29933002
.iter()
2994-
.find(|keypair| keypair.pubkey() == *authorized_voter_pubkey)
3003+
.find(|keypair| keypair.pubkey() == authorized_voter_pubkey)
29953004
{
29963005
None => {
29973006
warn!(
@@ -3058,7 +3067,16 @@ impl ReplayStage {
30583067
}
30593068
Some(vote_account) => vote_account,
30603069
};
3061-
let vote_state_view = vote_account.vote_state_view();
3070+
let vote_state_view = match vote_account.vote_state_view() {
3071+
None => {
3072+
warn!(
3073+
"Vote account {} does not have a vote state. Unable to vote",
3074+
vote_account_pubkey,
3075+
);
3076+
return GenerateVoteTxResult::Failed;
3077+
}
3078+
Some(vote_state_view) => vote_state_view,
3079+
};
30623080
if vote_state_view.node_pubkey() != &node_keypair.pubkey() {
30633081
info!(
30643082
"Vote account node_pubkey mismatch: {} (expected: {}). Unable to vote",
@@ -4289,7 +4307,10 @@ impl ReplayStage {
42894307
let Some(vote_account) = bank.get_vote_account(my_vote_pubkey) else {
42904308
return;
42914309
};
4292-
let mut bank_vote_state = TowerVoteState::from(vote_account.vote_state_view());
4310+
let Some(vote_state_view) = vote_account.vote_state_view() else {
4311+
return;
4312+
};
4313+
let mut bank_vote_state = TowerVoteState::from(vote_state_view);
42934314
if bank_vote_state.last_voted_slot() <= tower.vote_state.last_voted_slot() {
42944315
return;
42954316
}
@@ -8719,6 +8740,7 @@ pub(crate) mod tests {
87198740
assert_eq!(
87208741
vote_account
87218742
.vote_state_view()
8743+
.unwrap()
87228744
.votes_iter()
87238745
.map(|lockout| lockout.slot())
87248746
.collect_vec(),
@@ -10417,4 +10439,4 @@ pub(crate) mod tests {
1041710439
&mut PurgeRepairSlotCounter::default(),
1041810440
);
1041910441
}
10420-
}
10442+
}

core/src/vote_simulator.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ impl VoteSimulator {
103103
let tower_sync = if let Some(vote_account) =
104104
parent_bank.get_vote_account(&keypairs.vote_keypair.pubkey())
105105
{
106-
let mut vote_state = TowerVoteState::from(vote_account.vote_state_view());
106+
let mut vote_state = TowerVoteState::from(
107+
vote_account.vote_state_view().expect("must be TowerBFT"),
108+
);
107109
vote_state.process_next_vote_slot(parent);
108110
TowerSync::new(
109111
vote_state.votes,
@@ -134,7 +136,7 @@ impl VoteSimulator {
134136
let vote_account = new_bank
135137
.get_vote_account(&keypairs.vote_keypair.pubkey())
136138
.unwrap();
137-
let vote_state_view = vote_account.vote_state_view();
139+
let vote_state_view = vote_account.vote_state_view().unwrap();
138140
assert!(vote_state_view
139141
.votes_iter()
140142
.any(|lockout| lockout.slot() == parent));

ledger-tool/src/main.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,10 @@ fn graph_forks(bank_forks: &BankForks, config: &GraphConfig) -> String {
222222
.map(|(_, (stake, _))| stake)
223223
.sum();
224224
for (stake, vote_account) in bank.vote_accounts().values() {
225-
let vote_state_view = vote_account.vote_state_view();
225+
// TODO(wen): make this work for Alpenglow
226+
let Some(vote_state_view) = vote_account.vote_state_view() else {
227+
continue;
228+
};
226229
if let Some(last_vote) = vote_state_view.last_voted_slot() {
227230
let entry = last_votes.entry(*vote_state_view.node_pubkey()).or_insert((
228231
last_vote,
@@ -262,7 +265,10 @@ fn graph_forks(bank_forks: &BankForks, config: &GraphConfig) -> String {
262265
let mut first = true;
263266
loop {
264267
for (_, vote_account) in bank.vote_accounts().values() {
265-
let vote_state_view = vote_account.vote_state_view();
268+
// TODO(wen): make this work for Alpenglow
269+
let Some(vote_state_view) = vote_account.vote_state_view() else {
270+
continue;
271+
};
266272
if let Some(last_vote) = vote_state_view.last_voted_slot() {
267273
let validator_votes =
268274
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
@@ -2098,7 +2098,11 @@ fn supermajority_root_from_vote_accounts(
20982098
return None;
20992099
}
21002100

2101-
Some((account.vote_state_view().root_slot()?, *stake))
2101+
if let Some(vote_state_view) = account.vote_state_view() {
2102+
Some((vote_state_view.root_slot()?, *stake))
2103+
} else {
2104+
None
2105+
}
21022106
})
21032107
.collect();
21042108

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
@@ -1173,7 +1173,8 @@ impl JsonRpcRequestProcessor {
11731173
}
11741174
}
11751175

1176-
let vote_state_view = account.vote_state_view();
1176+
// TODO(wen): make this work for Alpenglow
1177+
let vote_state_view = account.vote_state_view()?;
11771178
let last_vote = vote_state_view.last_voted_slot().unwrap_or(0);
11781179
let num_epoch_credits = vote_state_view.num_epoch_credits();
11791180
let epoch_credits = vote_state_view

runtime/src/bank.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2504,7 +2504,8 @@ impl Bank {
25042504
let slots_per_epoch = self.epoch_schedule().slots_per_epoch;
25052505
let vote_accounts = self.vote_accounts();
25062506
let recent_timestamps = vote_accounts.iter().filter_map(|(pubkey, (_, account))| {
2507-
let vote_state = account.vote_state_view();
2507+
// TODO(wen): make this work for Alpenglow.
2508+
let vote_state = account.vote_state_view()?;
25082509
let last_timestamp = vote_state.last_timestamp();
25092510
let slot_delta = self.slot().checked_sub(last_timestamp.slot)?;
25102511
(slot_delta <= slots_per_epoch)

0 commit comments

Comments
 (0)