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

Commit 702f147

Browse files
authored
stake-pool: Split transient stake account creation (#1950)
1 parent de693dc commit 702f147

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

stake-pool/program/src/processor.rs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,30 @@ fn check_account_owner(
132132
}
133133
}
134134

135+
/// Create a transient stake account without transferring lamports
136+
fn create_transient_stake_account<'a>(
137+
transient_stake_account_info: AccountInfo<'a>,
138+
transient_stake_account_signer_seeds: &[&[u8]],
139+
system_program_info: AccountInfo<'a>,
140+
) -> Result<(), ProgramError> {
141+
invoke_signed(
142+
&system_instruction::allocate(
143+
transient_stake_account_info.key,
144+
std::mem::size_of::<stake_program::StakeState>() as u64,
145+
),
146+
&[
147+
transient_stake_account_info.clone(),
148+
system_program_info.clone(),
149+
],
150+
&[&transient_stake_account_signer_seeds],
151+
)?;
152+
invoke_signed(
153+
&system_instruction::assign(transient_stake_account_info.key, &stake_program::id()),
154+
&[transient_stake_account_info, system_program_info],
155+
&[&transient_stake_account_signer_seeds],
156+
)
157+
}
158+
135159
/// Program state handler.
136160
pub struct Processor {}
137161
impl Processor {
@@ -970,17 +994,10 @@ impl Processor {
970994
return Err(ProgramError::AccountNotRentExempt);
971995
}
972996

973-
// create transient stake account
974-
invoke_signed(
975-
&system_instruction::create_account(
976-
&transient_stake_account_info.key, // doesn't matter since no lamports are transferred
977-
&transient_stake_account_info.key,
978-
0,
979-
std::mem::size_of::<stake_program::StakeState>() as u64,
980-
&stake_program::id(),
981-
),
982-
&[transient_stake_account_info.clone()],
983-
&[&transient_stake_account_signer_seeds],
997+
create_transient_stake_account(
998+
transient_stake_account_info.clone(),
999+
&transient_stake_account_signer_seeds,
1000+
system_program_info.clone(),
9841001
)?;
9851002

9861003
// split into transient stake account
@@ -1124,17 +1141,10 @@ impl Processor {
11241141
return Err(ProgramError::InsufficientFunds);
11251142
}
11261143

1127-
// create transient stake account
1128-
invoke_signed(
1129-
&system_instruction::create_account(
1130-
&transient_stake_account_info.key, // doesn't matter since no lamports are transferred
1131-
&transient_stake_account_info.key,
1132-
0,
1133-
std::mem::size_of::<stake_program::StakeState>() as u64,
1134-
&stake_program::id(),
1135-
),
1136-
&[transient_stake_account_info.clone()],
1137-
&[&transient_stake_account_signer_seeds],
1144+
create_transient_stake_account(
1145+
transient_stake_account_info.clone(),
1146+
&transient_stake_account_signer_seeds,
1147+
system_program_info.clone(),
11381148
)?;
11391149

11401150
// split into transient stake account

0 commit comments

Comments
 (0)