Revert "Populate partitioned-rewards PDA during calculation (#34624)"

This reverts commit 4385ed11b1.
This commit is contained in:
Tyera Eulberg 2024-02-02 10:25:37 -07:00 committed by Tyera
parent d7179e4fa0
commit 57bbd3363c
5 changed files with 6 additions and 91 deletions

View File

@ -131,10 +131,6 @@ use {
UPDATED_HASHES_PER_TICK4, UPDATED_HASHES_PER_TICK5, UPDATED_HASHES_PER_TICK6,
},
epoch_info::EpochInfo,
epoch_rewards_partition_data::{
get_epoch_rewards_partition_data_address, EpochRewardsPartitionDataVersion, HasherKind,
PartitionData,
},
epoch_schedule::EpochSchedule,
feature,
feature_set::{self, include_loaded_accounts_data_size_in_fee_calculation, FeatureSet},
@ -864,7 +860,6 @@ struct PartitionedRewardsCalculation {
foundation_rate: f64,
prev_epoch_duration_in_years: f64,
capitalization: u64,
parent_blockhash: Hash,
}
/// result of calculating the stake rewards at beginning of new epoch
@ -882,8 +877,6 @@ struct CalculateRewardsAndDistributeVoteRewardsResult {
distributed_rewards: u64,
/// stake rewards that still need to be distributed, grouped by partition
stake_rewards_by_partition: Vec<StakeRewards>,
/// blockhash of parent, used to create EpochRewardsHasher
parent_blockhash: Hash,
}
pub(crate) type StakeRewards = Vec<StakeReward>;
@ -1591,7 +1584,6 @@ impl Bank {
total_rewards,
distributed_rewards,
stake_rewards_by_partition,
parent_blockhash,
} = self.calculate_rewards_and_distribute_vote_rewards(
parent_epoch,
reward_calc_tracer,
@ -1599,11 +1591,9 @@ impl Bank {
rewards_metrics,
);
let num_partitions = stake_rewards_by_partition.len();
let slot = self.slot();
let credit_start = self.block_height() + self.get_reward_calculation_num_blocks();
let credit_end_exclusive = credit_start + num_partitions as u64;
let credit_end_exclusive = credit_start + stake_rewards_by_partition.len() as u64;
self.set_epoch_reward_status_active(stake_rewards_by_partition);
@ -1611,8 +1601,6 @@ impl Bank {
// (total_rewards, distributed_rewards, credit_end_exclusive), total capital will increase by (total_rewards - distributed_rewards)
self.create_epoch_rewards_sysvar(total_rewards, distributed_rewards, credit_end_exclusive);
self.create_epoch_rewards_partition_data_account(num_partitions, parent_blockhash);
datapoint_info!(
"epoch-rewards-status-update",
("start_slot", slot, i64),
@ -2387,7 +2375,6 @@ impl Bank {
foundation_rate,
prev_epoch_duration_in_years,
capitalization,
parent_blockhash,
}
}
@ -2408,7 +2395,6 @@ impl Bank {
foundation_rate,
prev_epoch_duration_in_years,
capitalization,
parent_blockhash,
} = self.calculate_rewards_for_partitioning(
prev_epoch,
reward_calc_tracer,
@ -2478,7 +2464,6 @@ impl Bank {
total_rewards: validator_rewards_paid + total_stake_rewards_lamports,
distributed_rewards: validator_rewards_paid,
stake_rewards_by_partition,
parent_blockhash,
}
}
@ -3592,41 +3577,6 @@ impl Bank {
self.log_epoch_rewards_sysvar("update");
}
/// Create the persistent PDA containing the epoch-rewards data
fn create_epoch_rewards_partition_data_account(
&self,
num_partitions: usize,
parent_blockhash: Hash,
) {
let epoch_rewards_partition_data = EpochRewardsPartitionDataVersion::V0(PartitionData {
num_partitions,
parent_blockhash,
hasher_kind: HasherKind::Sip13,
});
let address = get_epoch_rewards_partition_data_address(self.epoch());
let data_len = bincode::serialized_size(&epoch_rewards_partition_data).unwrap() as usize;
let account_balance = self.get_minimum_balance_for_rent_exemption(data_len);
let new_account = AccountSharedData::new_data(
account_balance,
&epoch_rewards_partition_data,
&solana_sdk::stake::program::id(),
)
.unwrap();
info!(
"create epoch rewards partition data account {} {address} \
{epoch_rewards_partition_data:?}",
self.slot
);
// Skip storing data account when we are testing partitioned
// rewards but feature is not yet active
if !self.force_partition_rewards_in_first_block_of_epoch() {
self.store_account_and_update_capitalization(&address, &new_account);
}
}
fn update_recent_blockhashes_locked(&self, locked_blockhash_queue: &BlockhashQueue) {
#[allow(deprecated)]
self.update_sysvar_account(&sysvar::recent_blockhashes::id(), |account| {

View File

@ -9,7 +9,7 @@ pub(crate) fn hash_rewards_into_partitions(
num_partitions: usize,
) -> Vec<StakeRewards> {
let hasher = EpochRewardsHasher::new(num_partitions, parent_blockhash);
let mut rewards = vec![vec![]; num_partitions];
let mut result = vec![vec![]; num_partitions];
for reward in stake_rewards {
// clone here so the hasher's state is re-used on each call to `hash_address_to_partition`.
@ -18,9 +18,9 @@ pub(crate) fn hash_rewards_into_partitions(
let partition_index = hasher
.clone()
.hash_address_to_partition(&reward.stake_pubkey);
rewards[partition_index].push(reward);
result[partition_index].push(reward);
}
rewards
result
}
#[cfg(test)]

View File

@ -1,34 +0,0 @@
use {
crate::{hash::Hash, pubkey::Pubkey},
serde_derive::{Deserialize, Serialize},
};
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub enum EpochRewardsPartitionDataVersion {
V0(PartitionData),
}
#[repr(u8)]
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub enum HasherKind {
Sip13,
}
/// Data about a rewards partitions for an epoch
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct PartitionData {
/// Number of partitions used for epoch rewards this epoch
pub num_partitions: usize,
/// Blockhash of the last block of the previous epoch, used to create EpochRewardsHasher
pub parent_blockhash: Hash,
/// Kind of hasher used to generate partitions
pub hasher_kind: HasherKind,
}
pub fn get_epoch_rewards_partition_data_address(epoch: u64) -> Pubkey {
let (address, _bump_seed) = Pubkey::find_program_address(
&[b"EpochRewardsPartitionData", &epoch.to_le_bytes()],
&crate::stake::program::id(),
);
address
}

View File

@ -491,7 +491,6 @@ pub mod ed25519_program;
pub mod entrypoint;
pub mod entrypoint_deprecated;
pub mod epoch_rewards;
pub mod epoch_rewards_partition_data;
pub mod epoch_schedule;
pub mod feature;
pub mod fee_calculator;

View File

@ -48,8 +48,8 @@ pub use solana_program::{
account_info, address_lookup_table, alt_bn128, big_mod_exp, blake3, borsh, borsh0_10, borsh0_9,
borsh1, bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, clock, config,
custom_heap_default, custom_panic_default, debug_account_data, declare_deprecated_sysvar_id,
declare_sysvar_id, decode_error, ed25519_program, epoch_rewards, epoch_rewards_partition_data,
epoch_schedule, fee_calculator, impl_sysvar_get, incinerator, instruction, keccak, lamports,
declare_sysvar_id, decode_error, ed25519_program, epoch_rewards, epoch_schedule,
fee_calculator, impl_sysvar_get, incinerator, instruction, keccak, lamports,
loader_instruction, loader_upgradeable_instruction, loader_v4, loader_v4_instruction, message,
msg, native_token, nonce, poseidon, program, program_error, program_memory, program_option,
program_pack, rent, sanitize, sdk_ids, secp256k1_program, secp256k1_recover, serde_varint,