|
18 | 18 | state::{Authorized, Lockup, Meta, StakeAuthorize, StakeStateV2},
|
19 | 19 | tools::{acceptable_reference_epoch_credits, eligible_for_deactivate_delinquent},
|
20 | 20 | },
|
| 21 | + system_program, |
21 | 22 | sysvar::{epoch_rewards::EpochRewards, stake_history::StakeHistorySysvar, Sysvar},
|
22 | 23 | vote::{program as solana_vote_program, state::VoteState},
|
23 | 24 | },
|
@@ -58,6 +59,11 @@ fn set_stake_state(stake_account_info: &AccountInfo, new_state: &StakeStateV2) -
|
58 | 59 | .map_err(|_| ProgramError::InvalidAccountData)
|
59 | 60 | }
|
60 | 61 |
|
| 62 | +fn deallocate_stake_account(stake_account_info: &AccountInfo) -> ProgramResult { |
| 63 | + stake_account_info.assign(&system_program::id()); |
| 64 | + stake_account_info.realloc(0, false) |
| 65 | +} |
| 66 | + |
61 | 67 | // dont call this "move" because we have an instruction MoveLamports
|
62 | 68 | fn relocate_lamports(
|
63 | 69 | source_account_info: &AccountInfo,
|
@@ -582,7 +588,7 @@ impl Processor {
|
582 | 588 |
|
583 | 589 | // Deinitialize state upon zero balance
|
584 | 590 | if split_lamports == source_lamport_balance {
|
585 |
| - set_stake_state(source_stake_account_info, &StakeStateV2::Uninitialized)?; |
| 591 | + deallocate_stake_account(source_stake_account_info)?; |
586 | 592 | }
|
587 | 593 |
|
588 | 594 | relocate_lamports(
|
@@ -667,7 +673,7 @@ impl Processor {
|
667 | 673 | }
|
668 | 674 |
|
669 | 675 | // Deinitialize state upon zero balance
|
670 |
| - set_stake_state(source_stake_account_info, &StakeStateV2::Uninitialized)?; |
| 676 | + deallocate_stake_account(source_stake_account_info)?; |
671 | 677 | } else {
|
672 | 678 | // a partial withdrawal must not deplete the reserve
|
673 | 679 | let withdraw_lamports_and_reserve = checked_add(withdraw_lamports, reserve)?;
|
@@ -784,7 +790,7 @@ impl Processor {
|
784 | 790 | }
|
785 | 791 |
|
786 | 792 | // Source is about to be drained, deinitialize its state
|
787 |
| - set_stake_state(source_stake_account_info, &StakeStateV2::Uninitialized)?; |
| 793 | + deallocate_stake_account(source_stake_account_info)?; |
788 | 794 |
|
789 | 795 | // Drain the source stake account
|
790 | 796 | relocate_lamports(
|
|
0 commit comments