cleanup math in distribute_partitioned_epoch_rewards (#32164)

This commit is contained in:
Jeff Washington (jwash) 2023-06-15 18:17:38 -05:00 committed by GitHub
parent b4265217e6
commit b1b7ae5e09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 7 deletions

View File

@ -1934,15 +1934,15 @@ impl Bank {
return;
};
assert!(
self.epoch_schedule.get_slots_in_epoch(self.epoch)
> self.get_reward_total_num_blocks(status.calculated_epoch_stake_rewards.len())
);
let height = self.block_height();
let start_block_height = status.start_block_height;
let credit_start = start_block_height + self.get_reward_calculation_num_blocks();
let credit_end_exclusive = credit_start
+ self.get_reward_distribution_num_blocks(status.calculated_epoch_stake_rewards.len());
let credit_end_exclusive =
credit_start + status.calculated_epoch_stake_rewards.len() as u64;
assert!(
self.epoch_schedule.get_slots_in_epoch(self.epoch)
> credit_end_exclusive.saturating_sub(credit_start)
);
if height >= credit_start && height < credit_end_exclusive {
let partition_index = height - credit_start;

View File

@ -12633,7 +12633,30 @@ fn test_distribute_partitioned_epoch_rewards() {
.map(|_| StakeReward::new_random())
.collect::<Vec<_>>();
let stake_rewards = hash_rewards_into_partitions(stake_rewards, &Hash::new(&[1; 32]), 100);
let stake_rewards = hash_rewards_into_partitions(stake_rewards, &Hash::new(&[1; 32]), 2);
bank.set_epoch_reward_status_active(stake_rewards);
bank.distribute_partitioned_epoch_rewards();
}
#[test]
#[should_panic(expected = "assertion failed: self.epoch_schedule.get_slots_in_epoch")]
fn test_distribute_partitioned_epoch_rewards_too_many_partitions() {
let (genesis_config, _mint_keypair) = create_genesis_config(1_000_000 * LAMPORTS_PER_SOL);
let mut bank = Bank::new_for_tests(&genesis_config);
let expected_num = 1;
let stake_rewards = (0..expected_num)
.map(|_| StakeReward::new_random())
.collect::<Vec<_>>();
let stake_rewards = hash_rewards_into_partitions(
stake_rewards,
&Hash::new(&[1; 32]),
bank.epoch_schedule().slots_per_epoch as usize + 1,
);
bank.set_epoch_reward_status_active(stake_rewards);