From 57bbd3363c62e616538fa622417670b0e083d80d Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Fri, 2 Feb 2024 10:25:37 -0700 Subject: [PATCH] Revert "Populate partitioned-rewards PDA during calculation (#34624)" This reverts commit 4385ed11b1a955642944a6b11353c09b1fba9187. --- runtime/src/bank.rs | 52 +------------------ runtime/src/epoch_rewards_hasher.rs | 6 +-- .../src/epoch_rewards_partition_data.rs | 34 ------------ sdk/program/src/lib.rs | 1 - sdk/src/lib.rs | 4 +- 5 files changed, 6 insertions(+), 91 deletions(-) delete mode 100644 sdk/program/src/epoch_rewards_partition_data.rs diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 6301b306f..9c97632f5 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -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, - /// blockhash of parent, used to create EpochRewardsHasher - parent_blockhash: Hash, } pub(crate) type StakeRewards = Vec; @@ -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| { diff --git a/runtime/src/epoch_rewards_hasher.rs b/runtime/src/epoch_rewards_hasher.rs index 120bb0c2c..b594b05a5 100644 --- a/runtime/src/epoch_rewards_hasher.rs +++ b/runtime/src/epoch_rewards_hasher.rs @@ -9,7 +9,7 @@ pub(crate) fn hash_rewards_into_partitions( num_partitions: usize, ) -> Vec { 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)] diff --git a/sdk/program/src/epoch_rewards_partition_data.rs b/sdk/program/src/epoch_rewards_partition_data.rs deleted file mode 100644 index 62e75ca51..000000000 --- a/sdk/program/src/epoch_rewards_partition_data.rs +++ /dev/null @@ -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 -} diff --git a/sdk/program/src/lib.rs b/sdk/program/src/lib.rs index 016585d40..54de9d817 100644 --- a/sdk/program/src/lib.rs +++ b/sdk/program/src/lib.rs @@ -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; diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index e64d6ddc5..4bf36a5d2 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -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,