Skip to content

Commit

Permalink
stake-pool: Cleanup documentation in code (solana-labs#2525)
Browse files Browse the repository at this point in the history
  • Loading branch information
joncinque authored Oct 18, 2021
1 parent 4658815 commit 3b48fa0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 28 deletions.
35 changes: 23 additions & 12 deletions stake-pool/program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ pub enum StakePoolInstruction {
/// (Staker only) Adds stake account delegated to validator to the pool's
/// list of managed validators.
///
/// The stake account will have the rent-exempt amount plus 1 SOL.
/// The stake account will have the rent-exempt amount plus
/// `crate::MINIMUM_ACTIVE_STAKE` (currently 0.001 SOL).
///
/// 0. `[w]` Stake pool
/// 1. `[s]` Staker
Expand All @@ -99,8 +100,9 @@ pub enum StakePoolInstruction {

/// (Staker only) Removes validator from the pool
///
/// Only succeeds if the validator stake account has the minimum of 1 SOL
/// plus the rent-exempt amount.
/// Only succeeds if the validator stake account has the minimum of
/// `crate::MINIMUM_ACTIVE_STAKE` (currently 0.001 SOL) plus the rent-exempt
/// amount.
///
/// 0. `[w]` Stake pool
/// 1. `[s]` Staker
Expand All @@ -109,7 +111,7 @@ pub enum StakePoolInstruction {
/// 4. `[w]` Validator stake list storage account
/// 5. `[w]` Stake account to remove from the pool
/// 6. `[]` Transient stake account, to check that that we're not trying to activate
/// 7. `[w]` Destination stake account, to receive the minimum SOL from the validator stake account. Must be
/// 7. `[w]` Destination stake account, to receive the minimum SOL from the validator stake account
/// 8. `[]` Sysvar clock
/// 9. `[]` Stake program id,
RemoveValidatorFromPool,
Expand Down Expand Up @@ -154,8 +156,9 @@ pub enum StakePoolInstruction {
/// will do the work of merging once it's ready.
///
/// This instruction only succeeds if the transient stake account does not exist.
/// The minimum amount to move is rent-exemption plus 1 SOL in order to avoid
/// issues on credits observed when merging active stakes later.
/// The minimum amount to move is rent-exemption plus `crate::MINIMUM_ACTIVE_STAKE`
/// (currently 0.001 SOL) in order to avoid issues on credits observed when
/// merging active stakes later.
///
/// 0. `[]` Stake pool
/// 1. `[s]` Stake pool staker
Expand Down Expand Up @@ -275,11 +278,19 @@ pub enum StakePoolInstruction {
///
/// Succeeds if the stake account has enough SOL to cover the desired amount
/// of pool tokens, and if the withdrawal keeps the total staked amount
/// above the minimum of rent-exempt amount + 1 SOL.
/// above the minimum of rent-exempt amount + 0.001 SOL.
///
/// A validator stake account can be withdrawn from freely, and the reserve
/// can only be drawn from if there is no active stake left, where all
/// validator accounts are left with 1 lamport.
/// When allowing withdrawals, the order of priority goes:
///
/// * preferred withdraw validator stake account (if set)
/// * validator stake accounts
/// * transient stake accounts
/// * reserve stake account
///
/// A user can freely withdraw from a validator stake account, and if they
/// are all at the minimum, then they can withdraw from transient stake
/// accounts, and if they are all at minimum, then they can withdraw from
/// the reserve.
///
/// 0. `[w]` Stake pool
/// 1. `[w]` Validator stake list storage account
Expand All @@ -301,8 +312,8 @@ pub enum StakePoolInstruction {
///
/// 0. `[w]` StakePool
/// 1. `[s]` Manager
/// 2. '[]` New manager pubkey
/// 3. '[]` New manager fee account
/// 2. `[s]` New manager
/// 3. `[]` New manager fee account
SetManager,

/// (Manager only) Update fee
Expand Down
38 changes: 22 additions & 16 deletions stake-pool/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ fn create_transient_stake_account<'a>(
/// Program state handler.
pub struct Processor {}
impl Processor {
/// Issue a stake_deactivate instruction.
/// Issue a delegate_stake instruction.
#[allow(clippy::too_many_arguments)]
fn stake_delegate<'a>(
stake_info: AccountInfo<'a>,
Expand Down Expand Up @@ -1389,6 +1389,16 @@ impl Processor {
stake_pool.check_reserve_stake(reserve_stake_info)?;
check_stake_program(stake_program_info.key)?;

if validator_stake_accounts
.len()
.checked_rem(2)
.ok_or(StakePoolError::CalculationFailure)?
!= 0
{
msg!("Odd number of validator stake accounts passed in, should be pairs of validator stake and transient stake accounts");
return Err(StakePoolError::UnexpectedValidatorListAccountSize.into());
}

check_account_owner(validator_list_info, program_id)?;
let mut validator_list_data = validator_list_info.data.borrow_mut();
let (validator_list_header, mut validator_slice) =
Expand Down Expand Up @@ -1766,9 +1776,7 @@ impl Processor {
let token_program_info = next_account_info(account_info_iter)?;
let stake_program_info = next_account_info(account_info_iter)?;

if *stake_program_info.key != stake_program::id() {
return Err(ProgramError::IncorrectProgramId);
}
check_stake_program(stake_program_info.key)?;

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

if pool_tokens_user > 0 {
Self::token_mint_to(
stake_pool_info.key,
token_program_info.clone(),
pool_mint_info.clone(),
dest_user_pool_info.clone(),
withdraw_authority_info.clone(),
AUTHORITY_WITHDRAW,
stake_pool.stake_withdraw_bump_seed,
pool_tokens_user,
)?;
}
Self::token_mint_to(
stake_pool_info.key,
token_program_info.clone(),
pool_mint_info.clone(),
dest_user_pool_info.clone(),
withdraw_authority_info.clone(),
AUTHORITY_WITHDRAW,
stake_pool.stake_withdraw_bump_seed,
pool_tokens_user,
)?;

if pool_tokens_manager_deposit_fee > 0 {
Self::token_mint_to(
Expand Down

0 comments on commit 3b48fa0

Please sign in to comment.