From d29cd8ef849f7a340dfa130658fdc5f3868c8db2 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Wed, 18 Dec 2024 17:51:25 -0700 Subject: [PATCH] Remove remaining old rewards logic: type aliases and helper structs --- runtime/src/bank.rs | 19 +--------------- runtime/src/bank/tests.rs | 47 +++++++++++++++++---------------------- 2 files changed, 21 insertions(+), 45 deletions(-) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index a71d17cd267f2c..ae0b3286ab06c0 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -52,7 +52,7 @@ use { calculate_stake_weighted_timestamp, MaxAllowableDrift, MAX_ALLOWABLE_DRIFT_PERCENTAGE_FAST, MAX_ALLOWABLE_DRIFT_PERCENTAGE_SLOW_V2, }, - stakes::{InvalidCacheEntryReason, Stakes, StakesCache, StakesEnum}, + stakes::{Stakes, StakesCache, StakesEnum}, status_cache::{SlotDelta, StatusCache}, transaction_batch::{OwnedOrBorrowed, TransactionBatch}, verify_precompiles::verify_precompiles, @@ -176,7 +176,6 @@ use { solana_svm_transaction::svm_message::SVMMessage, solana_timings::{ExecuteTimingType, ExecuteTimings}, solana_vote::vote_account::{VoteAccount, VoteAccountsHashMap}, - solana_vote_program::vote_state::VoteState, std::{ collections::{HashMap, HashSet}, convert::TryFrom, @@ -948,22 +947,6 @@ pub struct Bank { bank_hash_stats: AtomicBankHashStats, } -struct VoteWithStakeDelegations { - vote_state: Arc, - vote_account: AccountSharedData, - delegations: Vec<(Pubkey, StakeAccount)>, -} - -type VoteWithStakeDelegationsMap = DashMap; - -type InvalidCacheKeyMap = DashMap; - -struct LoadVoteAndStakeAccountsResult { - vote_with_stake_delegations_map: VoteWithStakeDelegationsMap, - invalid_vote_keys: InvalidCacheKeyMap, - vote_accounts_cache_miss_count: usize, -} - #[derive(Debug)] struct VoteReward { vote_account: AccountSharedData, diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index edc9203edbd5c8..6e403d6ec34970 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -15,6 +15,7 @@ use { }, snapshot_bank_utils, snapshot_utils, stake_history::StakeHistory, + stakes::InvalidCacheEntryReason, status_cache::MAX_CACHE_ENTRIES, }, agave_transaction_view::static_account_keys_frame::MAX_STATIC_ACCOUNTS_PER_PACKET, @@ -1911,7 +1912,7 @@ impl Bank { &self, thread_pool: &ThreadPool, reward_calc_tracer: Option, - ) -> LoadVoteAndStakeAccountsResult { + ) -> StakeDelegationsMap { let stakes = self.stakes_cache.stakes(); let stake_delegations = self.filter_stake_delegations(&stakes); // Obtain all unique voter pubkeys from stake delegations. @@ -1964,25 +1965,20 @@ impl Bank { invalid_vote_keys.insert(vote_pubkey, InvalidCacheEntryReason::WrongOwner); return None; } - let vote_with_stake_delegations = VoteWithStakeDelegations { - vote_state: Arc::new(vote_account.vote_state().clone()), - vote_account: AccountSharedData::from(vote_account), - delegations: Vec::default(), - }; - Some((vote_pubkey, vote_with_stake_delegations)) + let stake_delegations = Vec::default(); + Some((vote_pubkey, stake_delegations)) }; - let vote_with_stake_delegations_map: DashMap = - thread_pool.install(|| { - voter_pubkeys - .into_par_iter() - .filter_map(make_vote_delegations_entry) - .collect() - }); + let stake_delegations_map: DashMap = thread_pool.install(|| { + voter_pubkeys + .into_par_iter() + .filter_map(make_vote_delegations_entry) + .collect() + }); // Join stake accounts with vote-accounts. let push_stake_delegation = |(stake_pubkey, stake_account): (&Pubkey, &StakeAccount<_>)| { let delegation = stake_account.delegation(); let Some(mut vote_delegations) = - vote_with_stake_delegations_map.get_mut(&delegation.voter_pubkey) + stake_delegations_map.get_mut(&delegation.voter_pubkey) else { return; }; @@ -1993,25 +1989,24 @@ impl Bank { reward_calc_tracer(&event); } let stake_delegation = (*stake_pubkey, stake_account.clone()); - vote_delegations.delegations.push(stake_delegation); + vote_delegations.push(stake_delegation); }; thread_pool.install(|| { stake_delegations .into_par_iter() .for_each(push_stake_delegation); }); - LoadVoteAndStakeAccountsResult { - vote_with_stake_delegations_map, - invalid_vote_keys, - vote_accounts_cache_miss_count: vote_accounts_cache_miss_count.into_inner(), - } + stake_delegations_map } } +type StakeDelegations = Vec<(Pubkey, StakeAccount)>; +type StakeDelegationsMap = DashMap; + #[cfg(test)] fn check_bank_update_vote_stake_rewards(load_vote_and_stake_accounts: F) where - F: Fn(&Bank) -> LoadVoteAndStakeAccountsResult, + F: Fn(&Bank) -> StakeDelegationsMap, { solana_logger::setup(); @@ -9329,7 +9324,7 @@ fn test_epoch_schedule_from_genesis_config() { fn check_stake_vote_account_validity(check_owner_change: bool, load_vote_and_stake_accounts: F) where - F: Fn(&Bank) -> LoadVoteAndStakeAccountsResult, + F: Fn(&Bank) -> StakeDelegationsMap, { let validator_vote_keypairs0 = ValidatorVoteKeypairs::new_rand(); let validator_vote_keypairs1 = ValidatorVoteKeypairs::new_rand(); @@ -9353,8 +9348,7 @@ where None, None, )); - let vote_and_stake_accounts = - load_vote_and_stake_accounts(&bank).vote_with_stake_delegations_map; + let vote_and_stake_accounts = load_vote_and_stake_accounts(&bank); assert_eq!(vote_and_stake_accounts.len(), 2); let mut vote_account = bank @@ -9393,8 +9387,7 @@ where ); // Accounts must be valid stake and vote accounts - let vote_and_stake_accounts = - load_vote_and_stake_accounts(&bank).vote_with_stake_delegations_map; + let vote_and_stake_accounts = load_vote_and_stake_accounts(&bank); assert_eq!( vote_and_stake_accounts.len(), usize::from(!check_owner_change)