Skip to content

Commit b96acd3

Browse files
wen-codingbw-solana
authored andcommitted
Allow Alpenglow accounts in StakesCache (anza-xyz#87)
1 parent 397f054 commit b96acd3

File tree

7 files changed

+183
-64
lines changed

7 files changed

+183
-64
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
@@ -172,7 +172,7 @@ check-cfg = [
172172

173173
[workspace.dependencies]
174174
Inflector = "0.11.4"
175-
alpenglow-vote = { git = "ssh://[email protected]/solana-program/alpenglow-vote.git", rev = "80318d3" }
175+
alpenglow-vote = { git = "ssh://[email protected]/solana-program/alpenglow-vote.git", rev = "b3d25ff" }
176176
# alpenglow-vote = { path = "../alpenglow-vote/program" }
177177
axum = "0.7.9"
178178
agave-banking-stage-ingress-types = { path = "banking-stage-ingress-types", version = "=2.3.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
@@ -11,6 +11,7 @@ edition = { workspace = true }
1111

1212
[dependencies]
1313
ahash = { workspace = true }
14+
alpenglow-vote = { workspace = true }
1415
aquamarine = { workspace = true }
1516
arrayref = { workspace = true }
1617
base64 = { workspace = true }

runtime/src/bank/tests.rs

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,12 +1906,20 @@ fn test_rent_eager_collect_rent_zero_lamport_deterministic() {
19061906
assert_ne!(hash2_with_zero, Hash::default());
19071907
}
19081908

1909-
#[test]
1910-
fn test_bank_update_vote_stake_rewards() {
1909+
fn test_bank_update_vote_stake_rewards(is_alpenglow: bool) {
19111910
let thread_pool = ThreadPoolBuilder::new().num_threads(1).build().unwrap();
1912-
check_bank_update_vote_stake_rewards(|bank: &Bank| {
1913-
bank._load_vote_and_stake_accounts(&thread_pool, null_tracer())
1914-
});
1911+
check_bank_update_vote_stake_rewards(
1912+
|bank: &Bank| bank._load_vote_and_stake_accounts(&thread_pool, null_tracer()),
1913+
is_alpenglow,
1914+
);
1915+
}
1916+
1917+
#[test]
1918+
fn test_bank_update_vote_stake_rewards_tests() {
1919+
test_bank_update_vote_stake_rewards(false);
1920+
//TODO(wen): rewards to Alpenglow vote accounts don't work until epoch_stakes calculation
1921+
// is updated.
1922+
// test_bank_update_vote_stake_rewards(true);
19151923
}
19161924

19171925
impl Bank {
@@ -2011,7 +2019,7 @@ type StakeDelegations = Vec<(Pubkey, StakeAccount<Delegation>)>;
20112019
type StakeDelegationsMap = DashMap<Pubkey, StakeDelegations>;
20122020

20132021
#[cfg(test)]
2014-
fn check_bank_update_vote_stake_rewards<F>(load_vote_and_stake_accounts: F)
2022+
fn check_bank_update_vote_stake_rewards<F>(load_vote_and_stake_accounts: F, is_alpenglow: bool)
20152023
where
20162024
F: Fn(&Bank) -> StakeDelegationsMap,
20172025
{
@@ -2050,27 +2058,39 @@ where
20502058
);
20512059

20522060
let ((vote_id, mut vote_account), (stake_id, stake_account)) =
2053-
crate::stakes::tests::create_staked_node_accounts(10_000);
2061+
crate::stakes::tests::create_staked_node_accounts(10_000, is_alpenglow);
20542062
let starting_vote_and_stake_balance = 10_000 + 1;
20552063

20562064
// set up accounts
20572065
bank0.store_account_and_update_capitalization(&stake_id, &stake_account);
20582066

20592067
// generate some rewards
2060-
let mut vote_state = Some(vote_state::from(&vote_account).unwrap());
2061-
for i in 0..MAX_LOCKOUT_HISTORY + 42 {
2062-
if let Some(v) = vote_state.as_mut() {
2063-
vote_state::process_slot_vote_unchecked(v, i as u64)
2068+
if is_alpenglow {
2069+
let mut vote_state =
2070+
*alpenglow_vote::state::VoteState::deserialize(vote_account.data()).unwrap();
2071+
for _ in 0..MAX_LOCKOUT_HISTORY + 42 {
2072+
let mut epoch_credits = *vote_state.epoch_credits();
2073+
epoch_credits.set_credits(epoch_credits.credits() + 16);
2074+
vote_state.set_epoch_credits(epoch_credits);
2075+
vote_state.serialize_into(vote_account.data_as_mut_slice());
2076+
bank0.store_account_and_update_capitalization(&vote_id, &vote_account);
20642077
}
2065-
let versioned = VoteStateVersions::Current(Box::new(vote_state.take().unwrap()));
2066-
vote_state::to(&versioned, &mut vote_account).unwrap();
2067-
bank0.store_account_and_update_capitalization(&vote_id, &vote_account);
2068-
match versioned {
2069-
VoteStateVersions::Current(v) => {
2070-
vote_state = Some(*v);
2078+
} else {
2079+
let mut vote_state = Some(vote_state::from(&vote_account).unwrap());
2080+
for i in 0..MAX_LOCKOUT_HISTORY + 42 {
2081+
if let Some(v) = vote_state.as_mut() {
2082+
vote_state::process_slot_vote_unchecked(v, i as u64)
20712083
}
2072-
_ => panic!("Has to be of type Current"),
2073-
};
2084+
let versioned = VoteStateVersions::Current(Box::new(vote_state.take().unwrap()));
2085+
vote_state::to(&versioned, &mut vote_account).unwrap();
2086+
bank0.store_account_and_update_capitalization(&vote_id, &vote_account);
2087+
match versioned {
2088+
VoteStateVersions::Current(v) => {
2089+
vote_state = Some(*v);
2090+
}
2091+
_ => panic!("Has to be of type Current"),
2092+
};
2093+
}
20742094
}
20752095
bank0.store_account_and_update_capitalization(&vote_id, &vote_account);
20762096
bank0.freeze();
@@ -4897,8 +4917,7 @@ fn test_add_duplicate_static_program() {
48974917
);
48984918
}
48994919

4900-
#[test]
4901-
fn test_add_instruction_processor_for_existing_unrelated_accounts() {
4920+
fn test_add_instruction_processor_for_existing_unrelated_accounts(is_alpenglow: bool) {
49024921
for pass in 0..5 {
49034922
let mut bank = create_simple_test_bank(500);
49044923

@@ -4919,7 +4938,7 @@ fn test_add_instruction_processor_for_existing_unrelated_accounts() {
49194938
}
49204939

49214940
let ((vote_id, vote_account), (stake_id, stake_account)) =
4922-
crate::stakes::tests::create_staked_node_accounts(1_0000);
4941+
crate::stakes::tests::create_staked_node_accounts(1_0000, is_alpenglow);
49234942
bank.capitalization
49244943
.fetch_add(vote_account.lamports() + stake_account.lamports(), Relaxed);
49254944
bank.store_account(&vote_id, &vote_account);
@@ -4992,6 +5011,12 @@ fn test_add_instruction_processor_for_existing_unrelated_accounts() {
49925011
}
49935012
}
49945013

5014+
#[test]
5015+
fn test_add_instruction_processor_for_existing_unrelated_accounts_tests() {
5016+
test_add_instruction_processor_for_existing_unrelated_accounts(false);
5017+
test_add_instruction_processor_for_existing_unrelated_accounts(true);
5018+
}
5019+
49955020
#[allow(deprecated)]
49965021
#[test]
49975022
fn test_recent_blockhashes_sysvar() {

0 commit comments

Comments
 (0)