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

Commit e71ea00

Browse files
authored
stake-pool: Specify the space used for new stake accounts (OS-SSP-SUG-00) (#4000)
1 parent 209f612 commit e71ea00

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

stake-pool/program/src/processor.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,10 @@ fn create_stake_account<'a>(
340340
stake_account_info: AccountInfo<'a>,
341341
stake_account_signer_seeds: &[&[u8]],
342342
system_program_info: AccountInfo<'a>,
343+
stake_space: usize,
343344
) -> Result<(), ProgramError> {
344345
invoke_signed(
345-
&system_instruction::allocate(
346-
stake_account_info.key,
347-
std::mem::size_of::<stake::state::StakeState>() as u64,
348-
),
346+
&system_instruction::allocate(stake_account_info.key, stake_space as u64),
349347
&[stake_account_info.clone(), system_program_info.clone()],
350348
&[stake_account_signer_seeds],
351349
)?;
@@ -1036,10 +1034,10 @@ impl Processor {
10361034
];
10371035

10381036
// Fund the stake account with the minimum + rent-exempt balance
1039-
let space = std::mem::size_of::<stake::state::StakeState>();
1037+
let stake_space = std::mem::size_of::<stake::state::StakeState>();
10401038
let stake_minimum_delegation = stake::tools::get_minimum_delegation()?;
10411039
let required_lamports = minimum_delegation(stake_minimum_delegation)
1042-
.saturating_add(rent.minimum_balance(space));
1040+
.saturating_add(rent.minimum_balance(stake_space));
10431041

10441042
// Check that we're not draining the reserve totally
10451043
let reserve_stake = try_from_slice_unchecked::<stake::state::StakeState>(
@@ -1064,6 +1062,7 @@ impl Processor {
10641062
stake_info.clone(),
10651063
stake_account_signer_seeds,
10661064
system_program_info.clone(),
1065+
stake_space,
10671066
)?;
10681067
// split into validator stake account
10691068
Self::stake_split(
@@ -1342,8 +1341,9 @@ impl Processor {
13421341
)?;
13431342
}
13441343

1344+
let stake_space = std::mem::size_of::<stake::state::StakeState>();
13451345
let stake_minimum_delegation = stake::tools::get_minimum_delegation()?;
1346-
let stake_rent = rent.minimum_balance(std::mem::size_of::<stake::state::StakeState>());
1346+
let stake_rent = rent.minimum_balance(stake_space);
13471347
let current_minimum_lamports =
13481348
stake_rent.saturating_add(minimum_delegation(stake_minimum_delegation));
13491349
if lamports < current_minimum_lamports {
@@ -1389,6 +1389,7 @@ impl Processor {
13891389
ephemeral_stake_account_info.clone(),
13901390
ephemeral_stake_account_signer_seeds,
13911391
system_program_info.clone(),
1392+
stake_space,
13921393
)?;
13931394

13941395
// split into ephemeral stake account
@@ -1454,6 +1455,7 @@ impl Processor {
14541455
transient_stake_account_info.clone(),
14551456
transient_stake_account_signer_seeds,
14561457
system_program_info.clone(),
1458+
stake_space,
14571459
)?;
14581460

14591461
// split into transient stake account
@@ -1609,7 +1611,8 @@ impl Processor {
16091611
return Err(StakePoolError::ValidatorNotFound.into());
16101612
}
16111613

1612-
let stake_rent = rent.minimum_balance(std::mem::size_of::<stake::state::StakeState>());
1614+
let stake_space = std::mem::size_of::<stake::state::StakeState>();
1615+
let stake_rent = rent.minimum_balance(stake_space);
16131616
let stake_minimum_delegation = stake::tools::get_minimum_delegation()?;
16141617
let current_minimum_delegation = minimum_delegation(stake_minimum_delegation);
16151618
if lamports < current_minimum_delegation {
@@ -1664,6 +1667,7 @@ impl Processor {
16641667
ephemeral_stake_account_info.clone(),
16651668
ephemeral_stake_account_signer_seeds,
16661669
system_program_info.clone(),
1670+
stake_space,
16671671
)?;
16681672

16691673
// split into ephemeral stake account
@@ -1732,6 +1736,7 @@ impl Processor {
17321736
transient_stake_account_info.clone(),
17331737
transient_stake_account_signer_seeds,
17341738
system_program_info.clone(),
1739+
stake_space,
17351740
)?;
17361741

17371742
// split into transient stake account
@@ -1839,7 +1844,8 @@ impl Processor {
18391844
}
18401845

18411846
let rent = Rent::get()?;
1842-
let stake_rent = rent.minimum_balance(std::mem::size_of::<stake::state::StakeState>());
1847+
let stake_space = std::mem::size_of::<stake::state::StakeState>();
1848+
let stake_rent = rent.minimum_balance(stake_space);
18431849
let stake_minimum_delegation = stake::tools::get_minimum_delegation()?;
18441850
let current_minimum_delegation = minimum_delegation(stake_minimum_delegation);
18451851

@@ -1942,6 +1948,7 @@ impl Processor {
19421948
source_transient_stake_account_info.clone(),
19431949
source_transient_stake_account_signer_seeds,
19441950
system_program_info.clone(),
1951+
stake_space,
19451952
)?;
19461953

19471954
Self::stake_split(
@@ -1973,6 +1980,7 @@ impl Processor {
19731980
ephemeral_stake_account_info.clone(),
19741981
ephemeral_stake_account_signer_seeds,
19751982
system_program_info.clone(),
1983+
stake_space,
19761984
)?;
19771985
Self::stake_redelegate(
19781986
stake_pool_info.key,
@@ -2077,6 +2085,7 @@ impl Processor {
20772085
destination_transient_stake_account_info.clone(),
20782086
destination_transient_stake_account_signer_seeds,
20792087
system_program_info.clone(),
2088+
stake_space,
20802089
)?;
20812090
Self::stake_split(
20822091
stake_pool_info.key,

0 commit comments

Comments
 (0)