Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
352bff0
Add bank::partitioned_epoch_rewards submodule
CriesofCarrots Mar 29, 2024
f59b7b0
Move helper structs and types to submodule
CriesofCarrots Mar 29, 2024
19d4fc4
Move partitioned-rewards-specific Bank methods to submodule
CriesofCarrots Mar 29, 2024
42d0382
Move unit tests into submodule
CriesofCarrots Mar 29, 2024
4d668bb
Update BankAbiTestWrapperNewer frozen_abi hash
CriesofCarrots Mar 30, 2024
0dea2fd
Add sysvar sub-submodule
CriesofCarrots Mar 29, 2024
ac36022
Move sysvar methods to sub-submodule
CriesofCarrots Mar 29, 2024
685043d
Move unit test to sysvar sub-submodule
CriesofCarrots Mar 29, 2024
e91f45c
Add new partitioned_epoch_rewards::sysvar method
CriesofCarrots Mar 29, 2024
1b3e0da
Remove superfluous method
CriesofCarrots Mar 29, 2024
2c80013
Add distribution sub-submodule
CriesofCarrots Mar 29, 2024
e1200e6
Move distribution methods to sub-submodule
CriesofCarrots Mar 29, 2024
bc78bd4
Move unit tests into distribution sub-submodule
CriesofCarrots Mar 29, 2024
cb6f4c1
Add calculation sub-submodule
CriesofCarrots Mar 29, 2024
4b7676b
Move calculation methods into sub-submodule
CriesofCarrots Mar 29, 2024
3f86ddd
Move unit tests into calculation sub-submodule
CriesofCarrots Mar 29, 2024
892666b
Move epoch_rewards_hasher into submodule
CriesofCarrots Mar 29, 2024
a49f46c
Move unit test into epoch_rewards_hasher sub-submodule
CriesofCarrots Mar 29, 2024
427cba3
Move integration-like tests into submodule
CriesofCarrots Mar 29, 2024
de5c43b
Move compare functionality into sub-submodule
CriesofCarrots Mar 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
773 changes: 6 additions & 767 deletions runtime/src/bank.rs

Large diffs are not rendered by default.

637 changes: 637 additions & 0 deletions runtime/src/bank/partitioned_epoch_rewards/calculation.rs

Large diffs are not rendered by default.

110 changes: 110 additions & 0 deletions runtime/src/bank/partitioned_epoch_rewards/compare.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
use {
super::{Bank, PartitionedRewardsCalculation},
crate::bank::{RewardCalcTracer, RewardsMetrics, VoteReward},
dashmap::DashMap,
log::info,
rayon::ThreadPool,
solana_accounts_db::stake_rewards::StakeReward,
solana_sdk::{
account::{AccountSharedData, WritableAccount},
clock::Epoch,
pubkey::Pubkey,
reward_info::RewardInfo,
},
std::collections::HashMap,
};

impl Bank {
/// compare the vote and stake accounts between the normal rewards calculation code
/// and the partitioned rewards calculation code
/// `stake_rewards_expected` and `vote_rewards_expected` are the results of the normal rewards calculation code
/// This fn should have NO side effects.
pub(in crate::bank) fn compare_with_partitioned_rewards(
&self,
stake_rewards_expected: &[StakeReward],
vote_rewards_expected: &DashMap<Pubkey, VoteReward>,
rewarded_epoch: Epoch,
thread_pool: &ThreadPool,
reward_calc_tracer: Option<impl RewardCalcTracer>,
) {
let partitioned_rewards = self.calculate_rewards_for_partitioning(
rewarded_epoch,
reward_calc_tracer,
thread_pool,
&mut RewardsMetrics::default(),
);
Self::compare_with_partitioned_rewards_results(
stake_rewards_expected,
vote_rewards_expected,
partitioned_rewards,
);
}

/// compare the vote and stake accounts between the normal rewards calculation code
/// and the partitioned rewards calculation code
/// `stake_rewards_expected` and `vote_rewards_expected` are the results of the normal rewards calculation code
/// This fn should have NO side effects.
/// This fn is only called in tests or with a debug cli arg prior to partitioned rewards feature activation.
fn compare_with_partitioned_rewards_results(
stake_rewards_expected: &[StakeReward],
vote_rewards_expected: &DashMap<Pubkey, VoteReward>,
partitioned_rewards: PartitionedRewardsCalculation,
) {
// put partitioned stake rewards in a hashmap
let mut stake_rewards: HashMap<Pubkey, &StakeReward> = HashMap::default();
partitioned_rewards
.stake_rewards_by_partition
.stake_rewards_by_partition
.iter()
.flatten()
.for_each(|stake_reward| {
stake_rewards.insert(stake_reward.stake_pubkey, stake_reward);
});

// verify stake rewards match expected
stake_rewards_expected.iter().for_each(|stake_reward| {
let partitioned = stake_rewards.remove(&stake_reward.stake_pubkey).unwrap();
assert_eq!(partitioned, stake_reward);
});
assert!(stake_rewards.is_empty(), "{stake_rewards:?}");

let mut vote_rewards: HashMap<Pubkey, (RewardInfo, AccountSharedData)> = HashMap::default();
partitioned_rewards
.vote_account_rewards
.accounts_to_store
.iter()
.enumerate()
.for_each(|(i, account)| {
if let Some(account) = account {
let reward = &partitioned_rewards.vote_account_rewards.rewards[i];
vote_rewards.insert(reward.0, (reward.1, account.clone()));
}
});

// verify vote rewards match expected
vote_rewards_expected.iter().for_each(|entry| {
if entry.value().vote_needs_store {
let partitioned = vote_rewards.remove(entry.key()).unwrap();
let mut to_store_partitioned = partitioned.1.clone();
to_store_partitioned.set_lamports(partitioned.0.post_balance);
let mut to_store_normal = entry.value().vote_account.clone();
_ = to_store_normal.checked_add_lamports(entry.value().vote_rewards);
assert_eq!(to_store_partitioned, to_store_normal, "{:?}", entry.key());
}
});
assert!(vote_rewards.is_empty(), "{vote_rewards:?}");
info!(
"verified partitioned rewards calculation matching: {}, {}",
partitioned_rewards
.stake_rewards_by_partition
.stake_rewards_by_partition
.iter()
.map(|rewards| rewards.len())
.sum::<usize>(),
partitioned_rewards
.vote_account_rewards
.accounts_to_store
.len()
);
}
}
Loading