Skip to content

Commit fb97bc3

Browse files
joncinqueHaoranYi
authored and
HaoranYi
committed
stake-pool: Make activating / deactivating check stricter (solana-labs#4002)
1 parent e8d8780 commit fb97bc3

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

stake-pool/program/src/processor.rs

+22-13
Original file line numberDiff line numberDiff line change
@@ -222,35 +222,41 @@ fn stake_is_inactive_without_history(stake: &stake::state::Stake, epoch: Epoch)
222222
&& stake.delegation.deactivation_epoch == epoch)
223223
}
224224

225-
/// Roughly checks if a stake account is deactivating or inactive
226-
fn check_if_stake_is_deactivating_or_inactive(
225+
/// Roughly checks if a stake account is deactivating
226+
fn check_if_stake_deactivating(
227227
account_info: &AccountInfo,
228228
vote_account_address: &Pubkey,
229+
epoch: Epoch,
229230
) -> Result<(), ProgramError> {
230231
let (_, stake) = get_stake_state(account_info)?;
231-
if stake.delegation.deactivation_epoch == Epoch::MAX {
232+
if stake.delegation.deactivation_epoch != epoch {
232233
msg!(
233-
"Existing stake {} delegated to {} is activating or active",
234+
"Existing stake {} delegated to {} not deactivated in epoch {}",
234235
account_info.key,
235-
vote_account_address
236+
vote_account_address,
237+
epoch,
236238
);
237239
Err(StakePoolError::WrongStakeState.into())
238240
} else {
239241
Ok(())
240242
}
241243
}
242244

243-
/// Roughly checks if a stake account is activating or active
244-
fn check_if_stake_is_activating_or_active(
245+
/// Roughly checks if a stake account is activating
246+
fn check_if_stake_activating(
245247
account_info: &AccountInfo,
246248
vote_account_address: &Pubkey,
249+
epoch: Epoch,
247250
) -> Result<(), ProgramError> {
248251
let (_, stake) = get_stake_state(account_info)?;
249-
if stake.delegation.deactivation_epoch != Epoch::MAX {
252+
if stake.delegation.deactivation_epoch != Epoch::MAX
253+
|| stake.delegation.activation_epoch != epoch
254+
{
250255
msg!(
251-
"Existing stake {} delegated to {} is deactivating or inactive",
256+
"Existing stake {} delegated to {} not activated in epoch {}",
252257
account_info.key,
253-
vote_account_address
258+
vote_account_address,
259+
epoch,
254260
);
255261
Err(StakePoolError::WrongStakeState.into())
256262
} else {
@@ -1349,9 +1355,10 @@ impl Processor {
13491355
);
13501356
return Err(ProgramError::InvalidSeeds);
13511357
}
1352-
check_if_stake_is_deactivating_or_inactive(
1358+
check_if_stake_deactivating(
13531359
transient_stake_account_info,
13541360
&vote_account_address,
1361+
clock.epoch,
13551362
)?;
13561363
}
13571364

@@ -1600,9 +1607,10 @@ impl Processor {
16001607
);
16011608
return Err(ProgramError::InvalidSeeds);
16021609
}
1603-
check_if_stake_is_activating_or_active(
1610+
check_if_stake_activating(
16041611
transient_stake_account_info,
16051612
vote_account_address,
1613+
clock.epoch,
16061614
)?;
16071615
}
16081616

@@ -2053,9 +2061,10 @@ impl Processor {
20532061
destination_transient_stake_seed,
20542062
&stake_pool.lockup,
20552063
)?;
2056-
check_if_stake_is_activating_or_active(
2064+
check_if_stake_activating(
20572065
destination_transient_stake_account_info,
20582066
vote_account_address,
2067+
clock.epoch,
20592068
)?;
20602069
Self::stake_merge(
20612070
stake_pool_info.key,

0 commit comments

Comments
 (0)