Skip to content

Commit

Permalink
stake-pool: Make activating / deactivating check stricter
Browse files Browse the repository at this point in the history
  • Loading branch information
joncinque committed Jan 27, 2023
1 parent c7a1e98 commit b341022
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions stake-pool/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,35 +222,41 @@ fn stake_is_inactive_without_history(stake: &stake::state::Stake, epoch: Epoch)
&& stake.delegation.deactivation_epoch == epoch)
}

/// Roughly checks if a stake account is deactivating or inactive
fn check_if_stake_is_deactivating_or_inactive(
/// Roughly checks if a stake account is deactivating
fn check_if_stake_deactivating(
account_info: &AccountInfo,
vote_account_address: &Pubkey,
epoch: Epoch,
) -> Result<(), ProgramError> {
let (_, stake) = get_stake_state(account_info)?;
if stake.delegation.deactivation_epoch == Epoch::MAX {
if stake.delegation.deactivation_epoch != epoch {
msg!(
"Existing stake {} delegated to {} is activating or active",
"Existing stake {} delegated to {} not deactivated in epoch {}",
account_info.key,
vote_account_address
vote_account_address,
epoch,
);
Err(StakePoolError::WrongStakeState.into())
} else {
Ok(())
}
}

/// Roughly checks if a stake account is activating or active
fn check_if_stake_is_activating_or_active(
/// Roughly checks if a stake account is activating
fn check_if_stake_activating(
account_info: &AccountInfo,
vote_account_address: &Pubkey,
epoch: Epoch,
) -> Result<(), ProgramError> {
let (_, stake) = get_stake_state(account_info)?;
if stake.delegation.deactivation_epoch != Epoch::MAX {
if stake.delegation.deactivation_epoch != Epoch::MAX
|| stake.delegation.activation_epoch != epoch
{
msg!(
"Existing stake {} delegated to {} is deactivating or inactive",
"Existing stake {} delegated to {} not activated in epoch {}",
account_info.key,
vote_account_address
vote_account_address,
epoch,
);
Err(StakePoolError::WrongStakeState.into())
} else {
Expand Down Expand Up @@ -1373,9 +1379,10 @@ impl Processor {
);
return Err(ProgramError::InvalidSeeds);
}
check_if_stake_is_deactivating_or_inactive(
check_if_stake_deactivating(
transient_stake_account_info,
&vote_account_address,
clock.epoch,
)?;
}

Expand Down Expand Up @@ -1624,9 +1631,10 @@ impl Processor {
);
return Err(ProgramError::InvalidSeeds);
}
check_if_stake_is_activating_or_active(
check_if_stake_activating(
transient_stake_account_info,
vote_account_address,
clock.epoch,
)?;
}

Expand Down Expand Up @@ -2077,9 +2085,10 @@ impl Processor {
destination_transient_stake_seed,
&stake_pool.lockup,
)?;
check_if_stake_is_activating_or_active(
check_if_stake_activating(
destination_transient_stake_account_info,
vote_account_address,
clock.epoch,
)?;
Self::stake_merge(
stake_pool_info.key,
Expand Down

0 comments on commit b341022

Please sign in to comment.