Skip to content

Commit 5259eea

Browse files
wen-codingbw-solana
authored andcommitted
Allow Alpenglow accounts in StakesCache (anza-xyz#87)
1 parent 02431a0 commit 5259eea

File tree

7 files changed

+164
-61
lines changed

7 files changed

+164
-61
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ used_underscore_binding = "deny"
174174

175175
[workspace.dependencies]
176176
Inflector = "0.11.4"
177-
alpenglow-vote = { git = "ssh://[email protected]/solana-program/alpenglow-vote.git", rev = "80318d3" }
177+
alpenglow-vote = { git = "ssh://[email protected]/solana-program/alpenglow-vote.git", rev = "b3d25ff" }
178178
# alpenglow-vote = { path = "../alpenglow-vote/program" }
179179
aes-gcm-siv = "0.11.1"
180180
agave-banking-stage-ingress-types = { path = "banking-stage-ingress-types", version = "=3.0.0" }

programs/sbf/Cargo.lock

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

runtime/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ agave-precompiles = { workspace = true }
5252
agave-reserved-account-keys = { workspace = true }
5353
agave-syscalls = { workspace = true }
5454
ahash = { workspace = true }
55+
alpenglow-vote = { workspace = true }
5556
aquamarine = { workspace = true }
5657
arrayref = { workspace = true }
5758
assert_matches = { workspace = true }

runtime/src/bank/tests.rs

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -578,12 +578,20 @@ pub(in crate::bank) fn new_from_parent_next_epoch(
578578
new_bank_from_parent_with_bank_forks(bank_forks, parent, &Pubkey::default(), slot)
579579
}
580580

581-
#[test]
582-
fn test_bank_update_vote_stake_rewards() {
581+
fn test_bank_update_vote_stake_rewards(is_alpenglow: bool) {
583582
let thread_pool = ThreadPoolBuilder::new().num_threads(1).build().unwrap();
584-
check_bank_update_vote_stake_rewards(|bank: &Bank| {
585-
bank._load_vote_and_stake_accounts(&thread_pool, null_tracer())
586-
});
583+
check_bank_update_vote_stake_rewards(
584+
|bank: &Bank| bank._load_vote_and_stake_accounts(&thread_pool, null_tracer()),
585+
is_alpenglow,
586+
);
587+
}
588+
589+
#[test]
590+
fn test_bank_update_vote_stake_rewards_tests() {
591+
test_bank_update_vote_stake_rewards(false);
592+
//TODO(wen): rewards to Alpenglow vote accounts don't work until epoch_stakes calculation
593+
// is updated.
594+
// test_bank_update_vote_stake_rewards(true);
587595
}
588596

589597
impl Bank {
@@ -683,7 +691,7 @@ type StakeDelegations = Vec<(Pubkey, StakeAccount<Delegation>)>;
683691
type StakeDelegationsMap = DashMap<Pubkey, StakeDelegations>;
684692

685693
#[cfg(test)]
686-
fn check_bank_update_vote_stake_rewards<F>(load_vote_and_stake_accounts: F)
694+
fn check_bank_update_vote_stake_rewards<F>(load_vote_and_stake_accounts: F, is_alpenglow: bool)
687695
where
688696
F: Fn(&Bank) -> StakeDelegationsMap,
689697
{
@@ -718,27 +726,39 @@ where
718726
);
719727

720728
let ((vote_id, mut vote_account), (stake_id, stake_account)) =
721-
crate::stakes::tests::create_staked_node_accounts(10_000);
729+
crate::stakes::tests::create_staked_node_accounts(10_000, is_alpenglow);
722730
let starting_vote_and_stake_balance = 10_000 + 1;
723731

724732
// set up accounts
725733
bank0.store_account_and_update_capitalization(&stake_id, &stake_account);
726734

727735
// generate some rewards
728-
let mut vote_state = Some(vote_state::from(&vote_account).unwrap());
729-
for i in 0..MAX_LOCKOUT_HISTORY + 42 {
730-
if let Some(v) = vote_state.as_mut() {
731-
vote_state::process_slot_vote_unchecked(v, i as u64)
736+
if is_alpenglow {
737+
let mut vote_state =
738+
*alpenglow_vote::state::VoteState::deserialize(vote_account.data()).unwrap();
739+
for _ in 0..MAX_LOCKOUT_HISTORY + 42 {
740+
let mut epoch_credits = *vote_state.epoch_credits();
741+
epoch_credits.set_credits(epoch_credits.credits() + 16);
742+
vote_state.set_epoch_credits(epoch_credits);
743+
vote_state.serialize_into(vote_account.data_as_mut_slice());
744+
bank0.store_account_and_update_capitalization(&vote_id, &vote_account);
732745
}
733-
let versioned = VoteStateVersions::Current(Box::new(vote_state.take().unwrap()));
734-
vote_state::to(&versioned, &mut vote_account).unwrap();
735-
bank0.store_account_and_update_capitalization(&vote_id, &vote_account);
736-
match versioned {
737-
VoteStateVersions::Current(v) => {
738-
vote_state = Some(*v);
746+
} else {
747+
let mut vote_state = Some(vote_state::from(&vote_account).unwrap());
748+
for i in 0..MAX_LOCKOUT_HISTORY + 42 {
749+
if let Some(v) = vote_state.as_mut() {
750+
vote_state::process_slot_vote_unchecked(v, i as u64)
739751
}
740-
_ => panic!("Has to be of type Current"),
741-
};
752+
let versioned = VoteStateVersions::Current(Box::new(vote_state.take().unwrap()));
753+
vote_state::to(&versioned, &mut vote_account).unwrap();
754+
bank0.store_account_and_update_capitalization(&vote_id, &vote_account);
755+
match versioned {
756+
VoteStateVersions::Current(v) => {
757+
vote_state = Some(*v);
758+
}
759+
_ => panic!("Has to be of type Current"),
760+
};
761+
}
742762
}
743763
bank0.store_account_and_update_capitalization(&vote_id, &vote_account);
744764
bank0.freeze();
@@ -3512,8 +3532,7 @@ fn test_add_duplicate_static_program() {
35123532
);
35133533
}
35143534

3515-
#[test]
3516-
fn test_add_instruction_processor_for_existing_unrelated_accounts() {
3535+
fn test_add_instruction_processor_for_existing_unrelated_accounts(is_alpenglow: bool) {
35173536
for pass in 0..5 {
35183537
let mut bank = create_simple_test_bank(500);
35193538

@@ -3537,7 +3556,7 @@ fn test_add_instruction_processor_for_existing_unrelated_accounts() {
35373556
}
35383557

35393558
let ((vote_id, vote_account), (stake_id, stake_account)) =
3540-
crate::stakes::tests::create_staked_node_accounts(1_0000);
3559+
crate::stakes::tests::create_staked_node_accounts(1_0000, is_alpenglow);
35413560
bank.capitalization
35423561
.fetch_add(vote_account.lamports() + stake_account.lamports(), Relaxed);
35433562
bank.store_account(&vote_id, &vote_account);
@@ -3617,6 +3636,12 @@ fn test_add_instruction_processor_for_existing_unrelated_accounts() {
36173636
}
36183637
}
36193638

3639+
#[test]
3640+
fn test_add_instruction_processor_for_existing_unrelated_accounts_tests() {
3641+
test_add_instruction_processor_for_existing_unrelated_accounts(false);
3642+
test_add_instruction_processor_for_existing_unrelated_accounts(true);
3643+
}
3644+
36203645
#[allow(deprecated)]
36213646
#[test]
36223647
fn test_recent_blockhashes_sysvar() {

0 commit comments

Comments
 (0)