refactor: optional `stake_history` arg is never `None` (#34556)

refactor: optional stake_history arg is never none
This commit is contained in:
Justin Starry 2023-12-22 10:44:28 +08:00 committed by GitHub
parent 8a8466cd86
commit 88af74d1d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 130 additions and 147 deletions

View File

@ -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) {

View File

@ -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),
);
}

View File

@ -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
)
);

View File

@ -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<impl Fn(&InflationPointCalculationEvent)>,
new_rate_activation_epoch: Option<Epoch>,
) -> 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<impl Fn(&InflationPointCalculationEvent)>,
new_rate_activation_epoch: Option<Epoch>,
) -> 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<impl Fn(&InflationPointCalculationEvent)>,
new_rate_activation_epoch: Option<Epoch>,
) -> 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<impl Fn(&InflationPointCalculationEvent)>,
new_rate_activation_epoch: Option<Epoch>,
) -> Option<CalculatedStakeRewards> {
@ -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<impl Fn(&InflationPointCalculationEvent)>,
new_rate_activation_epoch: Option<Epoch>,
) -> 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<Epoch>,
) -> Result<u128, InstructionError> {
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<Epoch>,
) -> 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::<Vec<_>>()
@ -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::<Vec<_>>()
};
@ -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::<u64>();
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::<u64>();
// 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::<u64>();
@ -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,
)

View File

@ -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 {

View File

@ -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,
);

View File

@ -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()

View File

@ -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<StakeAccount> {
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<StakeAccount> {
.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<StakeAccount> {
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<StakeAccount> {
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<StakeAccount> {
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)
);
}
}

View File

@ -105,12 +105,10 @@ fn warmed_up(bank: &Bank, stake_pubkey: &Pubkey) -> bool {
stake.delegation.stake
== stake.stake(
bank.epoch(),
Some(
&from_account::<StakeHistory, _>(
&bank.get_account(&sysvar::stake_history::id()).unwrap(),
)
.unwrap(),
),
&from_account::<StakeHistory, _>(
&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::<StakeHistory, _>(
&bank.get_account(&sysvar::stake_history::id()).unwrap(),
)
.unwrap(),
),
&from_account::<StakeHistory, _>(
&bank.get_account(&sysvar::stake_history::id()).unwrap(),
)
.unwrap(),
bank.new_warmup_cooldown_rate_epoch(),
)
}

View File

@ -641,7 +641,7 @@ impl Delegation {
pub fn stake(
&self,
epoch: Epoch,
history: Option<&StakeHistory>,
history: &StakeHistory,
new_rate_activation_epoch: Option<Epoch>,
) -> 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<Epoch>,
) -> 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<Epoch>,
) -> (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<Epoch>,
) -> u64 {
self.delegation