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

Commit 3b48fa0

Browse files
authored
stake-pool: Cleanup documentation in code (#2525)
1 parent 4658815 commit 3b48fa0

File tree

2 files changed

+45
-28
lines changed

2 files changed

+45
-28
lines changed

stake-pool/program/src/instruction.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ pub enum StakePoolInstruction {
8080
/// (Staker only) Adds stake account delegated to validator to the pool's
8181
/// list of managed validators.
8282
///
83-
/// The stake account will have the rent-exempt amount plus 1 SOL.
83+
/// The stake account will have the rent-exempt amount plus
84+
/// `crate::MINIMUM_ACTIVE_STAKE` (currently 0.001 SOL).
8485
///
8586
/// 0. `[w]` Stake pool
8687
/// 1. `[s]` Staker
@@ -99,8 +100,9 @@ pub enum StakePoolInstruction {
99100

100101
/// (Staker only) Removes validator from the pool
101102
///
102-
/// Only succeeds if the validator stake account has the minimum of 1 SOL
103-
/// plus the rent-exempt amount.
103+
/// Only succeeds if the validator stake account has the minimum of
104+
/// `crate::MINIMUM_ACTIVE_STAKE` (currently 0.001 SOL) plus the rent-exempt
105+
/// amount.
104106
///
105107
/// 0. `[w]` Stake pool
106108
/// 1. `[s]` Staker
@@ -109,7 +111,7 @@ pub enum StakePoolInstruction {
109111
/// 4. `[w]` Validator stake list storage account
110112
/// 5. `[w]` Stake account to remove from the pool
111113
/// 6. `[]` Transient stake account, to check that that we're not trying to activate
112-
/// 7. `[w]` Destination stake account, to receive the minimum SOL from the validator stake account. Must be
114+
/// 7. `[w]` Destination stake account, to receive the minimum SOL from the validator stake account
113115
/// 8. `[]` Sysvar clock
114116
/// 9. `[]` Stake program id,
115117
RemoveValidatorFromPool,
@@ -154,8 +156,9 @@ pub enum StakePoolInstruction {
154156
/// will do the work of merging once it's ready.
155157
///
156158
/// This instruction only succeeds if the transient stake account does not exist.
157-
/// The minimum amount to move is rent-exemption plus 1 SOL in order to avoid
158-
/// issues on credits observed when merging active stakes later.
159+
/// The minimum amount to move is rent-exemption plus `crate::MINIMUM_ACTIVE_STAKE`
160+
/// (currently 0.001 SOL) in order to avoid issues on credits observed when
161+
/// merging active stakes later.
159162
///
160163
/// 0. `[]` Stake pool
161164
/// 1. `[s]` Stake pool staker
@@ -275,11 +278,19 @@ pub enum StakePoolInstruction {
275278
///
276279
/// Succeeds if the stake account has enough SOL to cover the desired amount
277280
/// of pool tokens, and if the withdrawal keeps the total staked amount
278-
/// above the minimum of rent-exempt amount + 1 SOL.
281+
/// above the minimum of rent-exempt amount + 0.001 SOL.
279282
///
280-
/// A validator stake account can be withdrawn from freely, and the reserve
281-
/// can only be drawn from if there is no active stake left, where all
282-
/// validator accounts are left with 1 lamport.
283+
/// When allowing withdrawals, the order of priority goes:
284+
///
285+
/// * preferred withdraw validator stake account (if set)
286+
/// * validator stake accounts
287+
/// * transient stake accounts
288+
/// * reserve stake account
289+
///
290+
/// A user can freely withdraw from a validator stake account, and if they
291+
/// are all at the minimum, then they can withdraw from transient stake
292+
/// accounts, and if they are all at minimum, then they can withdraw from
293+
/// the reserve.
283294
///
284295
/// 0. `[w]` Stake pool
285296
/// 1. `[w]` Validator stake list storage account
@@ -301,8 +312,8 @@ pub enum StakePoolInstruction {
301312
///
302313
/// 0. `[w]` StakePool
303314
/// 1. `[s]` Manager
304-
/// 2. '[]` New manager pubkey
305-
/// 3. '[]` New manager fee account
315+
/// 2. `[s]` New manager
316+
/// 3. `[]` New manager fee account
306317
SetManager,
307318

308319
/// (Manager only) Update fee

stake-pool/program/src/processor.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ fn create_transient_stake_account<'a>(
163163
/// Program state handler.
164164
pub struct Processor {}
165165
impl Processor {
166-
/// Issue a stake_deactivate instruction.
166+
/// Issue a delegate_stake instruction.
167167
#[allow(clippy::too_many_arguments)]
168168
fn stake_delegate<'a>(
169169
stake_info: AccountInfo<'a>,
@@ -1389,6 +1389,16 @@ impl Processor {
13891389
stake_pool.check_reserve_stake(reserve_stake_info)?;
13901390
check_stake_program(stake_program_info.key)?;
13911391

1392+
if validator_stake_accounts
1393+
.len()
1394+
.checked_rem(2)
1395+
.ok_or(StakePoolError::CalculationFailure)?
1396+
!= 0
1397+
{
1398+
msg!("Odd number of validator stake accounts passed in, should be pairs of validator stake and transient stake accounts");
1399+
return Err(StakePoolError::UnexpectedValidatorListAccountSize.into());
1400+
}
1401+
13921402
check_account_owner(validator_list_info, program_id)?;
13931403
let mut validator_list_data = validator_list_info.data.borrow_mut();
13941404
let (validator_list_header, mut validator_slice) =
@@ -1766,9 +1776,7 @@ impl Processor {
17661776
let token_program_info = next_account_info(account_info_iter)?;
17671777
let stake_program_info = next_account_info(account_info_iter)?;
17681778

1769-
if *stake_program_info.key != stake_program::id() {
1770-
return Err(ProgramError::IncorrectProgramId);
1771-
}
1779+
check_stake_program(stake_program_info.key)?;
17721780

17731781
check_account_owner(stake_pool_info, program_id)?;
17741782
let mut stake_pool = try_from_slice_unchecked::<StakePool>(&stake_pool_info.data.borrow())?;
@@ -2102,18 +2110,16 @@ impl Processor {
21022110
deposit_lamports,
21032111
)?;
21042112

2105-
if pool_tokens_user > 0 {
2106-
Self::token_mint_to(
2107-
stake_pool_info.key,
2108-
token_program_info.clone(),
2109-
pool_mint_info.clone(),
2110-
dest_user_pool_info.clone(),
2111-
withdraw_authority_info.clone(),
2112-
AUTHORITY_WITHDRAW,
2113-
stake_pool.stake_withdraw_bump_seed,
2114-
pool_tokens_user,
2115-
)?;
2116-
}
2113+
Self::token_mint_to(
2114+
stake_pool_info.key,
2115+
token_program_info.clone(),
2116+
pool_mint_info.clone(),
2117+
dest_user_pool_info.clone(),
2118+
withdraw_authority_info.clone(),
2119+
AUTHORITY_WITHDRAW,
2120+
stake_pool.stake_withdraw_bump_seed,
2121+
pool_tokens_user,
2122+
)?;
21172123

21182124
if pool_tokens_manager_deposit_fee > 0 {
21192125
Self::token_mint_to(

0 commit comments

Comments
 (0)