Skip to content

Commit 5ec49cc

Browse files
authored
port change from agave #3468 (#14)
1 parent 4099c2c commit 5ec49cc

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

program/src/processor.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -659,25 +659,21 @@ impl Processor {
659659
return Err(StakeError::LockupInForce.into());
660660
}
661661

662-
let withdraw_lamports_and_reserve = checked_add(withdraw_lamports, reserve)?;
663662
let stake_account_lamports = source_stake_account_info.lamports();
664-
665-
// if the stake is active, we mustn't allow the account to go away
666-
if is_staked && withdraw_lamports_and_reserve > stake_account_lamports {
667-
return Err(ProgramError::InsufficientFunds);
668-
}
669-
670-
// a partial withdrawal must not deplete the reserve
671-
if withdraw_lamports != stake_account_lamports
672-
&& withdraw_lamports_and_reserve > stake_account_lamports
673-
{
674-
assert!(!is_staked);
675-
return Err(ProgramError::InsufficientFunds);
676-
}
677-
678-
// Deinitialize state upon zero balance
679663
if withdraw_lamports == stake_account_lamports {
664+
// if the stake is active, we mustn't allow the account to go away
665+
if is_staked {
666+
return Err(ProgramError::InsufficientFunds);
667+
}
668+
669+
// Deinitialize state upon zero balance
680670
set_stake_state(source_stake_account_info, &StakeStateV2::Uninitialized)?;
671+
} else {
672+
// a partial withdrawal must not deplete the reserve
673+
let withdraw_lamports_and_reserve = checked_add(withdraw_lamports, reserve)?;
674+
if withdraw_lamports_and_reserve > stake_account_lamports {
675+
return Err(ProgramError::InsufficientFunds);
676+
}
681677
}
682678

683679
relocate_lamports(

0 commit comments

Comments
 (0)