diff --git a/cli/src/stake.rs b/cli/src/stake.rs index 7f6626e2ea8265..f4bb8329278d94 100644 --- a/cli/src/stake.rs +++ b/cli/src/stake.rs @@ -2320,7 +2320,7 @@ pub fn build_stake_state( deactivating, } = stake.delegation.stake_activating_and_deactivating( current_epoch, - Some(stake_history), + stake_history, new_rate_activation_epoch, ); let lockup = if lockup.is_in_force(clock, None) { diff --git a/program-test/tests/warp.rs b/program-test/tests/warp.rs index da0b632ad66759..26a9228e5cc1b8 100644 --- a/program-test/tests/warp.rs +++ b/program-test/tests/warp.rs @@ -205,7 +205,7 @@ async fn stake_rewards_from_warp() { assert_eq!( stake .delegation - .stake_activating_and_deactivating(clock.epoch, Some(&stake_history), None), + .stake_activating_and_deactivating(clock.epoch, &stake_history, None), StakeActivationStatus::with_effective(stake.delegation.stake), ); } @@ -321,7 +321,7 @@ async fn stake_rewards_filter_bench_core(num_stake_accounts: u64) { assert_eq!( stake .delegation - .stake_activating_and_deactivating(clock.epoch, Some(&stake_history), None), + .stake_activating_and_deactivating(clock.epoch, &stake_history, None), StakeActivationStatus::with_effective(stake.delegation.stake), ); } diff --git a/programs/stake/src/stake_instruction.rs b/programs/stake/src/stake_instruction.rs index 1e364fe7c7d2b5..e0f20d601437b1 100644 --- a/programs/stake/src/stake_instruction.rs +++ b/programs/stake/src/stake_instruction.rs @@ -595,7 +595,7 @@ mod tests { if let StakeStateV2::Stake(_meta, stake, _stake_flags) = account.state().unwrap() { let stake_status = stake.delegation.stake_activating_and_deactivating( clock.epoch, - Some(stake_history), + stake_history, None, ); active_stake += stake_status.effective; @@ -6846,15 +6846,11 @@ mod tests { create_account_shared_data_for_test(&stake_history), ); if stake_amount - == stake.stake( - clock.epoch, - Some(&stake_history), - new_warmup_cooldown_rate_epoch, - ) + == stake.stake(clock.epoch, &stake_history, new_warmup_cooldown_rate_epoch) && merge_from_amount == merge_from_stake.stake( clock.epoch, - Some(&stake_history), + &stake_history, new_warmup_cooldown_rate_epoch, ) { @@ -6935,14 +6931,10 @@ mod tests { stake_history::id(), create_account_shared_data_for_test(&stake_history), ); - if 0 == stake.stake( - clock.epoch, - Some(&stake_history), - new_warmup_cooldown_rate_epoch, - ) && 0 - == merge_from_stake.stake( + if 0 == stake.stake(clock.epoch, &stake_history, new_warmup_cooldown_rate_epoch) + && 0 == merge_from_stake.stake( clock.epoch, - Some(&stake_history), + &stake_history, new_warmup_cooldown_rate_epoch, ) { @@ -7388,11 +7380,7 @@ mod tests { initial_stake_state .delegation() .unwrap() - .stake_activating_and_deactivating( - current_epoch, - Some(&stake_history), - None - ) + .stake_activating_and_deactivating(current_epoch, &stake_history, None) ); } @@ -7888,7 +7876,7 @@ mod tests { }, stake.delegation.stake_activating_and_deactivating( current_epoch, - Some(&stake_history), + &stake_history, None ) ); diff --git a/programs/stake/src/stake_state.rs b/programs/stake/src/stake_state.rs index 8aa4754d90d4b8..17232d083f06ec 100644 --- a/programs/stake/src/stake_state.rs +++ b/programs/stake/src/stake_state.rs @@ -111,7 +111,7 @@ fn get_stake_status( let stake_history = invoke_context.get_sysvar_cache().get_stake_history()?; Ok(stake.delegation.stake_activating_and_deactivating( clock.epoch, - Some(&stake_history), + &stake_history, new_warmup_cooldown_rate_epoch(invoke_context), )) } @@ -127,7 +127,7 @@ fn redelegate_stake( ) -> Result<(), StakeError> { let new_rate_activation_epoch = new_warmup_cooldown_rate_epoch(invoke_context); // If stake is currently active: - if stake.stake(clock.epoch, Some(stake_history), new_rate_activation_epoch) != 0 { + if stake.stake(clock.epoch, stake_history, new_rate_activation_epoch) != 0 { let stake_lamports_ok = if invoke_context .feature_set .is_active(&feature_set::stake_redelegate_instruction::id()) @@ -194,7 +194,7 @@ fn redeem_stake_rewards( stake: &mut Stake, point_value: &PointValue, vote_state: &VoteState, - stake_history: Option<&StakeHistory>, + stake_history: &StakeHistory, inflation_point_calc_tracer: Option, new_rate_activation_epoch: Option, ) -> Option<(u64, u64)> { @@ -232,7 +232,7 @@ fn redeem_stake_rewards( fn calculate_stake_points( stake: &Stake, vote_state: &VoteState, - stake_history: Option<&StakeHistory>, + stake_history: &StakeHistory, inflation_point_calc_tracer: Option, new_rate_activation_epoch: Option, ) -> u128 { @@ -259,7 +259,7 @@ struct CalculatedStakePoints { fn calculate_stake_points_and_credits( stake: &Stake, new_vote_state: &VoteState, - stake_history: Option<&StakeHistory>, + stake_history: &StakeHistory, inflation_point_calc_tracer: Option, new_rate_activation_epoch: Option, ) -> CalculatedStakePoints { @@ -378,7 +378,7 @@ fn calculate_stake_rewards( stake: &Stake, point_value: &PointValue, vote_state: &VoteState, - stake_history: Option<&StakeHistory>, + stake_history: &StakeHistory, inflation_point_calc_tracer: Option, new_rate_activation_epoch: Option, ) -> Option { @@ -649,7 +649,7 @@ fn deactivate_stake( // deactivation is only permitted when the stake delegation activating amount is zero. let status = stake.delegation.stake_activating_and_deactivating( epoch, - Some(stake_history.as_ref()), + &stake_history, new_warmup_cooldown_rate_epoch(invoke_context), ); if status.activating != 0 { @@ -1099,7 +1099,7 @@ pub fn withdraw( let staked = if clock.epoch >= stake.delegation.deactivation_epoch { stake .delegation - .stake(clock.epoch, Some(stake_history), new_rate_activation_epoch) + .stake(clock.epoch, stake_history, new_rate_activation_epoch) } else { // Assume full stake if the stake account hasn't been // de-activated, because in the future the exposed stake @@ -1388,7 +1388,7 @@ impl MergeKind { // activating or deactivating with non-zero effective stake. let status = stake.delegation.stake_activating_and_deactivating( clock.epoch, - Some(stake_history), + stake_history, new_warmup_cooldown_rate_epoch(invoke_context), ); @@ -1586,7 +1586,7 @@ pub fn redeem_rewards( stake_account: &mut AccountSharedData, vote_state: &VoteState, point_value: &PointValue, - stake_history: Option<&StakeHistory>, + stake_history: &StakeHistory, inflation_point_calc_tracer: Option, new_rate_activation_epoch: Option, ) -> Result<(u64, u64), InstructionError> { @@ -1633,7 +1633,7 @@ pub fn redeem_rewards( pub fn calculate_points( stake_state: &StakeStateV2, vote_state: &VoteState, - stake_history: Option<&StakeHistory>, + stake_history: &StakeHistory, new_rate_activation_epoch: Option, ) -> Result { if let StakeStateV2::Stake(_meta, stake, _stake_flags) = stake_state { @@ -1655,7 +1655,7 @@ pub type RewriteStakeStatus = (&'static str, (u64, u64), (u64, u64)); pub fn new_stake_history_entry<'a, I>( epoch: Epoch, stakes: I, - history: Option<&StakeHistory>, + history: &StakeHistory, new_rate_activation_epoch: Option, ) -> StakeHistoryEntry where @@ -1689,7 +1689,7 @@ pub fn create_stake_history_from_delegations( let entry = new_stake_history_entry( epoch, delegations.iter().chain(bootstrap_delegation.iter()), - Some(&stake_history), + &stake_history, new_rate_activation_epoch, ); stake_history.add(epoch, entry); @@ -1983,33 +1983,25 @@ mod tests { let mut stake_history = StakeHistory::default(); // assert that this stake follows step function if there's no history assert_eq!( - stake.stake_activating_and_deactivating( - stake.activation_epoch, - Some(&stake_history), - None - ), + stake.stake_activating_and_deactivating(stake.activation_epoch, &stake_history, None), StakeActivationStatus::with_effective_and_activating(0, stake.stake), ); for epoch in stake.activation_epoch + 1..stake.deactivation_epoch { assert_eq!( - stake.stake_activating_and_deactivating(epoch, Some(&stake_history), None), + stake.stake_activating_and_deactivating(epoch, &stake_history, None), StakeActivationStatus::with_effective(stake.stake), ); } // assert that this stake is full deactivating assert_eq!( - stake.stake_activating_and_deactivating( - stake.deactivation_epoch, - Some(&stake_history), - None - ), + stake.stake_activating_and_deactivating(stake.deactivation_epoch, &stake_history, None), StakeActivationStatus::with_deactivating(stake.stake), ); // assert that this stake is fully deactivated if there's no history assert_eq!( stake.stake_activating_and_deactivating( stake.deactivation_epoch + 1, - Some(&stake_history), + &stake_history, None ), StakeActivationStatus::default(), @@ -2024,7 +2016,7 @@ mod tests { ); // assert that this stake is broken, because above setup is broken assert_eq!( - stake.stake_activating_and_deactivating(1, Some(&stake_history), None), + stake.stake_activating_and_deactivating(1, &stake_history, None), StakeActivationStatus::with_effective_and_activating(0, stake.stake), ); @@ -2039,7 +2031,7 @@ mod tests { ); // assert that this stake is broken, because above setup is broken assert_eq!( - stake.stake_activating_and_deactivating(2, Some(&stake_history), None), + stake.stake_activating_and_deactivating(2, &stake_history, None), StakeActivationStatus::with_effective_and_activating( increment, stake.stake - increment @@ -2060,7 +2052,7 @@ mod tests { assert_eq!( stake.stake_activating_and_deactivating( stake.deactivation_epoch + 1, - Some(&stake_history), + &stake_history, None, ), StakeActivationStatus::with_deactivating(stake.stake), @@ -2079,7 +2071,7 @@ mod tests { assert_eq!( stake.stake_activating_and_deactivating( stake.deactivation_epoch + 2, - Some(&stake_history), + &stake_history, None, ), // hung, should be lower @@ -2149,7 +2141,7 @@ mod tests { (0..expected_stakes.len()) .map(|epoch| stake.stake_activating_and_deactivating( epoch as u64, - Some(&stake_history), + &stake_history, None, )) .collect::>() @@ -2278,11 +2270,7 @@ mod tests { let calculate_each_staking_status = |stake: &Delegation, epoch_count: usize| -> Vec<_> { (0..epoch_count) .map(|epoch| { - stake.stake_activating_and_deactivating( - epoch as u64, - Some(&stake_history), - None, - ) + stake.stake_activating_and_deactivating(epoch as u64, &stake_history, None) }) .collect::>() }; @@ -2402,7 +2390,7 @@ mod tests { (0, history.deactivating) }; assert_eq!( - stake.stake_activating_and_deactivating(epoch, Some(&stake_history), None), + stake.stake_activating_and_deactivating(epoch, &stake_history, None), StakeActivationStatus { effective: expected_stake, activating: expected_activating, @@ -2433,7 +2421,7 @@ mod tests { for epoch in 0..epochs { let stake = delegations .iter() - .map(|delegation| delegation.stake(epoch, Some(&stake_history), None)) + .map(|delegation| delegation.stake(epoch, &stake_history, None)) .sum::(); max_stake = max_stake.max(stake); min_stake = min_stake.min(stake); @@ -2502,7 +2490,7 @@ mod tests { let mut prev_total_effective_stake = delegations .iter() - .map(|delegation| delegation.stake(0, Some(&stake_history), new_rate_activation_epoch)) + .map(|delegation| delegation.stake(0, &stake_history, new_rate_activation_epoch)) .sum::(); // uncomment and add ! for fun with graphing @@ -2511,7 +2499,7 @@ mod tests { let total_effective_stake = delegations .iter() .map(|delegation| { - delegation.stake(epoch, Some(&stake_history), new_rate_activation_epoch) + delegation.stake(epoch, &stake_history, new_rate_activation_epoch) }) .sum::(); @@ -2562,7 +2550,7 @@ mod tests { points: 1 }, &vote_state, - None, + &StakeHistory::default(), null_tracer(), None, ) @@ -2583,7 +2571,7 @@ mod tests { points: 1 }, &vote_state, - None, + &StakeHistory::default(), null_tracer(), None, ) @@ -2620,7 +2608,7 @@ mod tests { points: 1 }, &vote_state, - None, + &StakeHistory::default(), null_tracer(), None, ) @@ -2636,7 +2624,13 @@ mod tests { // no overflow on points assert_eq!( u128::from(stake.delegation.stake) * epoch_slots, - calculate_stake_points(&stake, &vote_state, None, null_tracer(), None) + calculate_stake_points( + &stake, + &vote_state, + &StakeHistory::default(), + null_tracer(), + None + ) ); } @@ -2658,7 +2652,7 @@ mod tests { points: 1 }, &vote_state, - None, + &StakeHistory::default(), null_tracer(), None, ) @@ -2683,7 +2677,7 @@ mod tests { points: 2 // all his }, &vote_state, - None, + &StakeHistory::default(), null_tracer(), None, ) @@ -2705,7 +2699,7 @@ mod tests { points: 1 }, &vote_state, - None, + &StakeHistory::default(), null_tracer(), None, ) @@ -2730,7 +2724,7 @@ mod tests { points: 2 }, &vote_state, - None, + &StakeHistory::default(), null_tracer(), None, ) @@ -2753,7 +2747,7 @@ mod tests { points: 2 }, &vote_state, - None, + &StakeHistory::default(), null_tracer(), None, ) @@ -2778,7 +2772,7 @@ mod tests { points: 4 }, &vote_state, - None, + &StakeHistory::default(), null_tracer(), None, ) @@ -2797,7 +2791,7 @@ mod tests { points: 4 }, &vote_state, - None, + &StakeHistory::default(), null_tracer(), None, ) @@ -2813,7 +2807,7 @@ mod tests { points: 4 }, &vote_state, - None, + &StakeHistory::default(), null_tracer(), None, ) @@ -2836,7 +2830,7 @@ mod tests { points: 4 }, &vote_state, - None, + &StakeHistory::default(), null_tracer(), None, ) @@ -2859,7 +2853,7 @@ mod tests { points: 4 }, &vote_state, - None, + &StakeHistory::default(), null_tracer(), None, ) @@ -2871,7 +2865,13 @@ mod tests { new_credits_observed: 4, force_credits_update_with_skipped_reward: false, }, - calculate_stake_points_and_credits(&stake, &vote_state, None, null_tracer(), None) + calculate_stake_points_and_credits( + &stake, + &vote_state, + &StakeHistory::default(), + null_tracer(), + None + ) ); // credits_observed is auto-rewinded when vote_state credits are assumed to have been @@ -2884,7 +2884,13 @@ mod tests { new_credits_observed: 4, force_credits_update_with_skipped_reward: true, }, - calculate_stake_points_and_credits(&stake, &vote_state, None, null_tracer(), None) + calculate_stake_points_and_credits( + &stake, + &vote_state, + &StakeHistory::default(), + null_tracer(), + None + ) ); // this is new behavior 2; don't hint when credits both from stake and vote are identical stake.credits_observed = 4; @@ -2894,7 +2900,13 @@ mod tests { new_credits_observed: 4, force_credits_update_with_skipped_reward: false, }, - calculate_stake_points_and_credits(&stake, &vote_state, None, null_tracer(), None) + calculate_stake_points_and_credits( + &stake, + &vote_state, + &StakeHistory::default(), + null_tracer(), + None + ) ); // get rewards and credits observed when not the activation epoch @@ -2915,7 +2927,7 @@ mod tests { points: 1 }, &vote_state, - None, + &StakeHistory::default(), null_tracer(), None, ) @@ -2939,7 +2951,7 @@ mod tests { points: 1 }, &vote_state, - None, + &StakeHistory::default(), null_tracer(), None, ) diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index c5b1bc3a9edba3..cf73a224589dec 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -1770,7 +1770,7 @@ impl JsonRpcRequestProcessor { deactivating, } = delegation.stake_activating_and_deactivating( epoch, - Some(&stake_history), + &stake_history, new_rate_activation_epoch, ); let stake_activation_state = if deactivating > 0 { diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index cf72333f69d666..0329ca81b7ec6c 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -2984,7 +2984,7 @@ impl Bank { stake_state::calculate_points( stake_account.stake_state(), vote_state, - Some(stake_history), + stake_history, new_warmup_cooldown_rate_epoch, ) .unwrap_or(0) @@ -3021,7 +3021,7 @@ impl Bank { stake_state::calculate_points( stake_account.stake_state(), vote_state, - Some(stake_history), + stake_history, new_warmup_cooldown_rate_epoch, ) .unwrap_or(0) @@ -3108,7 +3108,7 @@ impl Bank { &mut stake_account, &vote_state, &point_value, - Some(stake_history), + stake_history, reward_calc_tracer.as_ref(), new_warmup_cooldown_rate_epoch, ); @@ -3227,7 +3227,7 @@ impl Bank { &mut stake_account, &vote_state, &point_value, - Some(stake_history), + stake_history, reward_calc_tracer.as_ref(), new_warmup_cooldown_rate_epoch, ); diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index 39036aa1dc0a0f..713ce9545cfc84 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -3970,7 +3970,7 @@ fn test_bank_epoch_vote_accounts() { // epoch_stakes are a snapshot at the leader_schedule_slot_offset boundary // in the prior epoch (0 in this case) assert_eq!( - leader_stake.stake(0, None, None), + leader_stake.stake(0, &StakeHistory::default(), None), vote_accounts.unwrap().get(&leader_vote_account).unwrap().0 ); @@ -3986,7 +3986,7 @@ fn test_bank_epoch_vote_accounts() { assert!(child.epoch_vote_accounts(epoch).is_some()); assert_eq!( - leader_stake.stake(child.epoch(), None, None), + leader_stake.stake(child.epoch(), &StakeHistory::default(), None), child .epoch_vote_accounts(epoch) .unwrap() @@ -4004,7 +4004,7 @@ fn test_bank_epoch_vote_accounts() { ); assert!(child.epoch_vote_accounts(epoch).is_some()); assert_eq!( - leader_stake.stake(child.epoch(), None, None), + leader_stake.stake(child.epoch(), &StakeHistory::default(), None), child .epoch_vote_accounts(epoch) .unwrap() diff --git a/runtime/src/stakes.rs b/runtime/src/stakes.rs index 977c25b180564f..45192e919d2495 100644 --- a/runtime/src/stakes.rs +++ b/runtime/src/stakes.rs @@ -19,7 +19,7 @@ use { solana_vote::vote_account::{VoteAccount, VoteAccounts}, std::{ collections::{HashMap, HashSet}, - ops::{Add, Deref}, + ops::Add, sync::{Arc, RwLock, RwLockReadGuard}, }, thiserror::Error, @@ -301,7 +301,7 @@ impl Stakes { let delegation = stake_account.delegation(); acc + delegation.stake_activating_and_deactivating( self.epoch, - Some(&self.stake_history), + &self.stake_history, new_rate_activation_epoch, ) }) @@ -333,9 +333,7 @@ impl Stakes { .values() .map(StakeAccount::delegation) .filter(|delegation| &delegation.voter_pubkey == voter_pubkey) - .map(|delegation| { - delegation.stake(epoch, Some(stake_history), new_rate_activation_epoch) - }) + .map(|delegation| delegation.stake(epoch, stake_history, new_rate_activation_epoch)) .sum() } @@ -361,7 +359,7 @@ impl Stakes { let removed_delegation = stake_account.delegation(); let removed_stake = removed_delegation.stake( self.epoch, - Some(&self.stake_history), + &self.stake_history, new_rate_activation_epoch, ); self.vote_accounts @@ -402,11 +400,7 @@ impl Stakes { debug_assert_ne!(stake_account.lamports(), 0u64); let delegation = stake_account.delegation(); let voter_pubkey = delegation.voter_pubkey; - let stake = delegation.stake( - self.epoch, - Some(&self.stake_history), - new_rate_activation_epoch, - ); + let stake = delegation.stake(self.epoch, &self.stake_history, new_rate_activation_epoch); match self.stake_delegations.insert(stake_pubkey, stake_account) { None => self.vote_accounts.add_stake(&voter_pubkey, stake), Some(old_stake_account) => { @@ -414,7 +408,7 @@ impl Stakes { let old_voter_pubkey = old_delegation.voter_pubkey; let old_stake = old_delegation.stake( self.epoch, - Some(&self.stake_history), + &self.stake_history, new_rate_activation_epoch, ); if voter_pubkey != old_voter_pubkey || stake != old_stake { @@ -583,7 +577,6 @@ fn refresh_vote_accounts( } stakes } - let stake_history = Some(stake_history.deref()); let delegated_stakes = thread_pool.install(|| { stake_delegations .par_iter() @@ -703,7 +696,7 @@ pub(crate) mod tests { assert!(vote_accounts.get(&vote_pubkey).is_some()); assert_eq!( vote_accounts.get_delegated_stake(&vote_pubkey), - stake.stake(i, None, None) + stake.stake(i, &StakeHistory::default(), None) ); } @@ -715,7 +708,7 @@ pub(crate) mod tests { assert!(vote_accounts.get(&vote_pubkey).is_some()); assert_eq!( vote_accounts.get_delegated_stake(&vote_pubkey), - stake.stake(i, None, None) + stake.stake(i, &StakeHistory::default(), None) ); // stays old stake, because only 10 is activated } @@ -730,7 +723,7 @@ pub(crate) mod tests { assert!(vote_accounts.get(&vote_pubkey).is_some()); assert_eq!( vote_accounts.get_delegated_stake(&vote_pubkey), - stake.stake(i, None, None) + stake.stake(i, &StakeHistory::default(), None) ); // now stake of 42 is activated } @@ -874,7 +867,7 @@ pub(crate) mod tests { assert!(vote_accounts.get(&vote_pubkey).is_some()); assert_eq!( vote_accounts.get_delegated_stake(&vote_pubkey), - stake.stake(stakes.epoch, Some(&stakes.stake_history), None) + stake.stake(stakes.epoch, &stakes.stake_history, None) ); assert!(vote_accounts.get(&vote_pubkey2).is_some()); assert_eq!(vote_accounts.get_delegated_stake(&vote_pubkey2), 0); @@ -891,7 +884,7 @@ pub(crate) mod tests { assert!(vote_accounts.get(&vote_pubkey2).is_some()); assert_eq!( vote_accounts.get_delegated_stake(&vote_pubkey2), - stake.stake(stakes.epoch, Some(&stakes.stake_history), None) + stake.stake(stakes.epoch, &stakes.stake_history, None) ); } } @@ -938,7 +931,7 @@ pub(crate) mod tests { let vote_accounts = stakes.vote_accounts(); assert_eq!( vote_accounts.get_delegated_stake(&vote_pubkey), - stake.stake(stakes.epoch, Some(&stakes.stake_history), None) + stake.stake(stakes.epoch, &stakes.stake_history, None) ); } let thread_pool = ThreadPoolBuilder::new().num_threads(1).build().unwrap(); @@ -948,7 +941,7 @@ pub(crate) mod tests { let vote_accounts = stakes.vote_accounts(); assert_eq!( vote_accounts.get_delegated_stake(&vote_pubkey), - stake.stake(stakes.epoch, Some(&stakes.stake_history), None) + stake.stake(stakes.epoch, &stakes.stake_history, None) ); } } diff --git a/runtime/tests/stake.rs b/runtime/tests/stake.rs index 2ae9127cef1013..7c53e1e44a3af3 100755 --- a/runtime/tests/stake.rs +++ b/runtime/tests/stake.rs @@ -105,12 +105,10 @@ fn warmed_up(bank: &Bank, stake_pubkey: &Pubkey) -> bool { stake.delegation.stake == stake.stake( bank.epoch(), - Some( - &from_account::( - &bank.get_account(&sysvar::stake_history::id()).unwrap(), - ) - .unwrap(), - ), + &from_account::( + &bank.get_account(&sysvar::stake_history::id()).unwrap(), + ) + .unwrap(), bank.new_warmup_cooldown_rate_epoch(), ) } @@ -120,12 +118,10 @@ fn get_staked(bank: &Bank, stake_pubkey: &Pubkey) -> u64 { .unwrap() .stake( bank.epoch(), - Some( - &from_account::( - &bank.get_account(&sysvar::stake_history::id()).unwrap(), - ) - .unwrap(), - ), + &from_account::( + &bank.get_account(&sysvar::stake_history::id()).unwrap(), + ) + .unwrap(), bank.new_warmup_cooldown_rate_epoch(), ) } diff --git a/sdk/program/src/stake/state.rs b/sdk/program/src/stake/state.rs index 11652446bbd2ee..7bf9ea696c91cb 100644 --- a/sdk/program/src/stake/state.rs +++ b/sdk/program/src/stake/state.rs @@ -641,7 +641,7 @@ impl Delegation { pub fn stake( &self, epoch: Epoch, - history: Option<&StakeHistory>, + history: &StakeHistory, new_rate_activation_epoch: Option, ) -> u64 { self.stake_activating_and_deactivating(epoch, history, new_rate_activation_epoch) @@ -652,7 +652,7 @@ impl Delegation { pub fn stake_activating_and_deactivating( &self, target_epoch: Epoch, - history: Option<&StakeHistory>, + history: &StakeHistory, new_rate_activation_epoch: Option, ) -> StakeActivationStatus { // first, calculate an effective and activating stake @@ -673,17 +673,14 @@ impl Delegation { } else if target_epoch == self.deactivation_epoch { // can only deactivate what's activated StakeActivationStatus::with_deactivating(effective_stake) - } else if let Some((history, mut prev_epoch, mut prev_cluster_stake)) = - history.and_then(|history| { - history - .get(self.deactivation_epoch) - .map(|cluster_stake_at_deactivation_epoch| { - ( - history, - self.deactivation_epoch, - cluster_stake_at_deactivation_epoch, - ) - }) + } else if let Some((history, mut prev_epoch, mut prev_cluster_stake)) = history + .get(self.deactivation_epoch) + .map(|cluster_stake_at_deactivation_epoch| { + ( + history, + self.deactivation_epoch, + cluster_stake_at_deactivation_epoch, + ) }) { // target_epoch > self.deactivation_epoch @@ -742,7 +739,7 @@ impl Delegation { fn stake_and_activating( &self, target_epoch: Epoch, - history: Option<&StakeHistory>, + history: &StakeHistory, new_rate_activation_epoch: Option, ) -> (u64, u64) { let delegated_stake = self.stake; @@ -760,17 +757,14 @@ impl Delegation { } else if target_epoch < self.activation_epoch { // not yet enabled (0, 0) - } else if let Some((history, mut prev_epoch, mut prev_cluster_stake)) = - history.and_then(|history| { - history - .get(self.activation_epoch) - .map(|cluster_stake_at_activation_epoch| { - ( - history, - self.activation_epoch, - cluster_stake_at_activation_epoch, - ) - }) + } else if let Some((history, mut prev_epoch, mut prev_cluster_stake)) = history + .get(self.activation_epoch) + .map(|cluster_stake_at_activation_epoch| { + ( + history, + self.activation_epoch, + cluster_stake_at_activation_epoch, + ) }) { // target_epoch > self.activation_epoch @@ -926,7 +920,7 @@ impl Stake { pub fn stake( &self, epoch: Epoch, - history: Option<&StakeHistory>, + history: &StakeHistory, new_rate_activation_epoch: Option, ) -> u64 { self.delegation