Skip to content

Commit 4d57d16

Browse files
committed
do not reassign to system
1 parent 623a306 commit 4d57d16

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

program/src/processor.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use {
1818
state::{Authorized, Lockup, Meta, StakeAuthorize, StakeStateV2},
1919
tools::{acceptable_reference_epoch_credits, eligible_for_deactivate_delinquent},
2020
},
21-
system_program,
2221
sysvar::{epoch_rewards::EpochRewards, stake_history::StakeHistorySysvar, Sysvar},
2322
vote::{program as solana_vote_program, state::VoteState},
2423
},
@@ -59,11 +58,6 @@ fn set_stake_state(stake_account_info: &AccountInfo, new_state: &StakeStateV2) -
5958
.map_err(|_| ProgramError::InvalidAccountData)
6059
}
6160

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-
6761
// dont call this "move" because we have an instruction MoveLamports
6862
fn relocate_lamports(
6963
source_account_info: &AccountInfo,
@@ -586,9 +580,9 @@ impl Processor {
586580
_ => return Err(ProgramError::InvalidAccountData),
587581
}
588582

589-
// Deinitialize state upon zero balance
583+
// Truncate state upon zero balance
590584
if split_lamports == source_lamport_balance {
591-
deallocate_stake_account(source_stake_account_info)?;
585+
source_stake_account_info.realloc(0, false)?;
592586
}
593587

594588
relocate_lamports(
@@ -672,8 +666,8 @@ impl Processor {
672666
return Err(ProgramError::InsufficientFunds);
673667
}
674668

675-
// Deinitialize state upon zero balance
676-
deallocate_stake_account(source_stake_account_info)?;
669+
// Truncate state upon zero balance
670+
source_stake_account_info.realloc(0, false)?;
677671
} else {
678672
// a partial withdrawal must not deplete the reserve
679673
let withdraw_lamports_and_reserve = checked_add(withdraw_lamports, reserve)?;
@@ -789,8 +783,8 @@ impl Processor {
789783
set_stake_state(destination_stake_account_info, &merged_state)?;
790784
}
791785

792-
// Source is about to be drained, deinitialize its state
793-
deallocate_stake_account(source_stake_account_info)?;
786+
// Source is about to be drained, truncate its state
787+
source_stake_account_info.realloc(0, false)?;
794788

795789
// Drain the source stake account
796790
relocate_lamports(

0 commit comments

Comments
 (0)