Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate EpochRewards with correct data #763

Merged
Prev Previous commit
Next Next commit
Populate EpochRewards::total_points correctly
CriesofCarrots committed Apr 13, 2024
commit f25ac0f16346483f658764be72ea76911faf74b2
1 change: 1 addition & 0 deletions runtime/src/bank/partitioned_epoch_rewards/calculation.rs
Original file line number Diff line number Diff line change
@@ -62,6 +62,7 @@ impl Bank {
distributed_rewards,
credit_start,
num_partitions,
total_points,
);

datapoint_info!(
3 changes: 2 additions & 1 deletion runtime/src/bank/partitioned_epoch_rewards/distribution.rs
Original file line number Diff line number Diff line change
@@ -215,7 +215,8 @@ mod tests {
// Set up epoch_rewards sysvar with rewards with 1e9 lamports to distribute.
let total_rewards = 1_000_000_000;
let num_partitions = 2; // num_partitions is arbitrary and unimportant for this test
bank.create_epoch_rewards_sysvar(total_rewards, 0, 42, num_partitions);
let total_points = (total_rewards * 42) as u128; // total_points is arbitrary for the purposes of this test
bank.create_epoch_rewards_sysvar(total_rewards, 0, 42, num_partitions, total_points);
let pre_epoch_rewards_account = bank.get_account(&sysvar::epoch_rewards::id()).unwrap();
let expected_balance =
bank.get_minimum_balance_for_rent_exemption(pre_epoch_rewards_account.data().len());
14 changes: 8 additions & 6 deletions runtime/src/bank/partitioned_epoch_rewards/sysvar.rs
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ impl Bank {
distributed_rewards: u64,
distribution_starting_block_height: u64,
num_partitions: u64,
total_points: u128,
) {
assert!(self.is_partitioned_rewards_code_enabled());

@@ -44,8 +45,8 @@ impl Bank {
distribution_starting_block_height,
parent_blockhash,
num_partitions,
total_points,
active: true,
..sysvar::epoch_rewards::EpochRewards::default()
};

self.update_sysvar_account(&sysvar::epoch_rewards::id(), |account| {
@@ -138,13 +139,14 @@ mod tests {

let total_rewards = 1_000_000_000; // a large rewards so that the sysvar account is rent-exempted.
let num_partitions = 2; // num_partitions is arbitrary and unimportant for this test
let total_points = (total_rewards * 42) as u128; // total_points is arbitrary for the purposes of this test

// create epoch rewards sysvar
let expected_epoch_rewards = sysvar::epoch_rewards::EpochRewards {
distribution_starting_block_height: 42,
num_partitions,
parent_blockhash: Hash::default(),
total_points: 0,
total_points,
total_rewards,
distributed_rewards: 10,
active: true,
@@ -156,7 +158,7 @@ mod tests {
sysvar::epoch_rewards::EpochRewards::default()
);

bank.create_epoch_rewards_sysvar(total_rewards, 10, 42, num_partitions);
bank.create_epoch_rewards_sysvar(total_rewards, 10, 42, num_partitions, total_points);
let account = bank.get_account(&sysvar::epoch_rewards::id()).unwrap();
let expected_balance = bank.get_minimum_balance_for_rent_exemption(account.data().len());
// Expected balance is the sysvar rent-exempt balance
@@ -170,13 +172,13 @@ mod tests {
let bank = Bank::new_from_parent(Arc::new(bank), &Pubkey::default(), parent_slot + 1);
// Also note that running `create_epoch_rewards_sysvar()` against a bank
// with an existing EpochRewards sysvar clobbers the previous values
bank.create_epoch_rewards_sysvar(total_rewards, 10, 42, num_partitions);
bank.create_epoch_rewards_sysvar(total_rewards, 10, 42, num_partitions, total_points);

let expected_epoch_rewards = sysvar::epoch_rewards::EpochRewards {
distribution_starting_block_height: 42,
num_partitions,
parent_blockhash,
total_points: 0,
total_points,
total_rewards,
distributed_rewards: 10,
active: true,
@@ -195,7 +197,7 @@ mod tests {
distribution_starting_block_height: 42,
num_partitions,
parent_blockhash,
total_points: 0,
total_points,
total_rewards,
distributed_rewards: 20,
active: true,
4 changes: 3 additions & 1 deletion runtime/src/bank/sysvar_cache.rs
Original file line number Diff line number Diff line change
@@ -121,11 +121,12 @@ mod tests {
// inject a reward sysvar for test
bank1.activate_feature(&feature_set::enable_partitioned_epoch_reward::id());
let num_partitions = 2; // num_partitions is arbitrary and unimportant for this test
let total_points = 42_000; // total_points is arbitrary for the purposes of this test
let expected_epoch_rewards = EpochRewards {
distribution_starting_block_height: 42,
num_partitions,
parent_blockhash: bank1.parent().unwrap().last_blockhash(),
total_points: 0,
total_points,
total_rewards: 100,
distributed_rewards: 10,
active: true,
@@ -135,6 +136,7 @@ mod tests {
expected_epoch_rewards.distributed_rewards,
expected_epoch_rewards.distribution_starting_block_height,
num_partitions,
total_points,
);

bank1