Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

stake-pool: Make activating / deactivating check stricter #4002

Merged
merged 1 commit into from
Jan 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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