Skip to content

Commit

Permalink
stake-pool: Specify the space used for new stake accounts (OS-SSP-SUG…
Browse files Browse the repository at this point in the history
  • Loading branch information
joncinque authored and HaoranYi committed Jul 19, 2023
1 parent 898691b commit 6570dca
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions stake-pool/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,10 @@ fn create_stake_account<'a>(
stake_account_info: AccountInfo<'a>,
stake_account_signer_seeds: &[&[u8]],
system_program_info: AccountInfo<'a>,
stake_space: usize,
) -> Result<(), ProgramError> {
invoke_signed(
&system_instruction::allocate(
stake_account_info.key,
std::mem::size_of::<stake::state::StakeState>() as u64,
),
&system_instruction::allocate(stake_account_info.key, stake_space as u64),
&[stake_account_info.clone(), system_program_info.clone()],
&[stake_account_signer_seeds],
)?;
Expand Down Expand Up @@ -1036,10 +1034,10 @@ impl Processor {
];

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

// Check that we're not draining the reserve totally
let reserve_stake = try_from_slice_unchecked::<stake::state::StakeState>(
Expand All @@ -1064,6 +1062,7 @@ impl Processor {
stake_info.clone(),
stake_account_signer_seeds,
system_program_info.clone(),
stake_space,
)?;
// split into validator stake account
Self::stake_split(
Expand Down Expand Up @@ -1342,8 +1341,9 @@ impl Processor {
)?;
}

let stake_space = std::mem::size_of::<stake::state::StakeState>();
let stake_minimum_delegation = stake::tools::get_minimum_delegation()?;
let stake_rent = rent.minimum_balance(std::mem::size_of::<stake::state::StakeState>());
let stake_rent = rent.minimum_balance(stake_space);
let current_minimum_lamports =
stake_rent.saturating_add(minimum_delegation(stake_minimum_delegation));
if lamports < current_minimum_lamports {
Expand Down Expand Up @@ -1389,6 +1389,7 @@ impl Processor {
ephemeral_stake_account_info.clone(),
ephemeral_stake_account_signer_seeds,
system_program_info.clone(),
stake_space,
)?;

// split into ephemeral stake account
Expand Down Expand Up @@ -1454,6 +1455,7 @@ impl Processor {
transient_stake_account_info.clone(),
transient_stake_account_signer_seeds,
system_program_info.clone(),
stake_space,
)?;

// split into transient stake account
Expand Down Expand Up @@ -1609,7 +1611,8 @@ impl Processor {
return Err(StakePoolError::ValidatorNotFound.into());
}

let stake_rent = rent.minimum_balance(std::mem::size_of::<stake::state::StakeState>());
let stake_space = std::mem::size_of::<stake::state::StakeState>();
let stake_rent = rent.minimum_balance(stake_space);
let stake_minimum_delegation = stake::tools::get_minimum_delegation()?;
let current_minimum_delegation = minimum_delegation(stake_minimum_delegation);
if lamports < current_minimum_delegation {
Expand Down Expand Up @@ -1664,6 +1667,7 @@ impl Processor {
ephemeral_stake_account_info.clone(),
ephemeral_stake_account_signer_seeds,
system_program_info.clone(),
stake_space,
)?;

// split into ephemeral stake account
Expand Down Expand Up @@ -1732,6 +1736,7 @@ impl Processor {
transient_stake_account_info.clone(),
transient_stake_account_signer_seeds,
system_program_info.clone(),
stake_space,
)?;

// split into transient stake account
Expand Down Expand Up @@ -1839,7 +1844,8 @@ impl Processor {
}

let rent = Rent::get()?;
let stake_rent = rent.minimum_balance(std::mem::size_of::<stake::state::StakeState>());
let stake_space = std::mem::size_of::<stake::state::StakeState>();
let stake_rent = rent.minimum_balance(stake_space);
let stake_minimum_delegation = stake::tools::get_minimum_delegation()?;
let current_minimum_delegation = minimum_delegation(stake_minimum_delegation);

Expand Down Expand Up @@ -1942,6 +1948,7 @@ impl Processor {
source_transient_stake_account_info.clone(),
source_transient_stake_account_signer_seeds,
system_program_info.clone(),
stake_space,
)?;

Self::stake_split(
Expand Down Expand Up @@ -1973,6 +1980,7 @@ impl Processor {
ephemeral_stake_account_info.clone(),
ephemeral_stake_account_signer_seeds,
system_program_info.clone(),
stake_space,
)?;
Self::stake_redelegate(
stake_pool_info.key,
Expand Down Expand Up @@ -2077,6 +2085,7 @@ impl Processor {
destination_transient_stake_account_info.clone(),
destination_transient_stake_account_signer_seeds,
system_program_info.clone(),
stake_space,
)?;
Self::stake_split(
stake_pool_info.key,
Expand Down

0 comments on commit 6570dca

Please sign in to comment.