Skip to content

Commit

Permalink
stake-pool: Reduce wait for active stake merges (solana-labs#2553)
Browse files Browse the repository at this point in the history
* stake-pool: Reduce wait to one epoch for active merges

* Remove stake_program references

* Remove credits observed point from docs
  • Loading branch information
joncinque authored Nov 1, 2021
1 parent 287c3be commit 01765b9
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 100 deletions.
6 changes: 0 additions & 6 deletions docs/src/stake-pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -1097,12 +1097,6 @@ reserve.

In this way, a user's funds are never at risk, and always redeemable.

### Staking Credits Observed on Deposit

A deposited stake account's "credits observed" must match the destination
account's "credits observed". Typically, this means you must wait an additional
epoch after activation for your stake account to match up with the stake pool's account.

### Transaction sizes

The Solana transaction processor has two important limitations:
Expand Down
1 change: 0 additions & 1 deletion stake-pool/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub mod big_vec;
pub mod error;
pub mod instruction;
pub mod processor;
pub mod stake_program;
pub mod state;

#[cfg(not(feature = "no-entrypoint"))]
Expand Down
8 changes: 3 additions & 5 deletions stake-pool/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use {
error::StakePoolError,
find_deposit_authority_program_address,
instruction::{FundingType, PreferredValidatorType, StakePoolInstruction},
minimum_reserve_lamports, minimum_stake_lamports, stake_program,
minimum_reserve_lamports, minimum_stake_lamports,
state::{
AccountType, Fee, FeeType, StakePool, StakeStatus, ValidatorList, ValidatorListHeader,
ValidatorStakeInfo,
Expand Down Expand Up @@ -674,7 +674,7 @@ impl Processor {
stake_pool.total_lamports = total_lamports;
stake_pool.pool_token_supply = 0;
stake_pool.last_update_epoch = Clock::get()?.epoch;
stake_pool.lockup = stake_program::Lockup::default();
stake_pool.lockup = stake::state::Lockup::default();
stake_pool.epoch_fee = epoch_fee;
stake_pool.next_epoch_fee = None;
stake_pool.preferred_deposit_validator_vote_address = None;
Expand Down Expand Up @@ -1530,9 +1530,7 @@ impl Processor {
if let Some(stake::state::StakeState::Stake(_, validator_stake)) =
validator_stake_state
{
if stake_program::active_stakes_can_merge(&stake, &validator_stake)
.is_ok()
{
if validator_stake.delegation.activation_epoch < clock.epoch {
let additional_lamports = transient_stake_info
.lamports()
.saturating_sub(stake.delegation.stake);
Expand Down
77 changes: 0 additions & 77 deletions stake-pool/program/src/stake_program.rs

This file was deleted.

3 changes: 2 additions & 1 deletion stake-pool/program/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use spl_token::state::{Account, AccountState};
use {
crate::{
big_vec::BigVec, error::StakePoolError, stake_program::Lockup, MAX_WITHDRAWAL_FEE_INCREASE,
big_vec::BigVec, error::StakePoolError, MAX_WITHDRAWAL_FEE_INCREASE,
WITHDRAWAL_BASELINE_FEE,
},
borsh::{BorshDeserialize, BorshSchema, BorshSerialize},
Expand All @@ -17,6 +17,7 @@ use {
program_memory::sol_memcmp,
program_pack::{Pack, Sealed},
pubkey::{Pubkey, PUBKEY_BYTES},
stake::state::Lockup,
},
spl_math::checked_ceil_div::CheckedCeilDiv,
std::{convert::TryFrom, fmt, matches},
Expand Down
2 changes: 1 addition & 1 deletion stake-pool/program/tests/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async fn setup() -> (
)
.await;

slot += 2 * slots_per_epoch;
slot += slots_per_epoch;
context.warp_to_slot(slot).unwrap();
stake_pool_accounts
.update_all(
Expand Down
3 changes: 1 addition & 2 deletions stake-pool/program/tests/huge_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use {
find_stake_program_address, find_transient_stake_program_address,
find_withdraw_authority_program_address, id,
instruction::{self, PreferredValidatorType},
stake_program,
state::{AccountType, Fee, StakePool, StakeStatus, ValidatorList, ValidatorStakeInfo},
MAX_VALIDATORS_TO_UPDATE, MINIMUM_ACTIVE_STAKE,
},
Expand Down Expand Up @@ -72,7 +71,7 @@ async fn setup(
total_lamports: 0,
pool_token_supply: 0,
last_update_epoch: 0,
lockup: stake_program::Lockup::default(),
lockup: stake::state::Lockup::default(),
epoch_fee: stake_pool_accounts.epoch_fee,
next_epoch_fee: None,
preferred_deposit_validator_vote_address: None,
Expand Down
6 changes: 5 additions & 1 deletion stake-pool/program/tests/set_epoch_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ async fn fail_not_updated() {
};

// move forward so an update is required
context.warp_to_slot(50_000).unwrap();
let first_normal_slot = context.genesis_config().epoch_schedule.first_normal_slot;
let slots_per_epoch = context.genesis_config().epoch_schedule.slots_per_epoch;
context
.warp_to_slot(first_normal_slot + slots_per_epoch)
.unwrap();

let transaction = Transaction::new_signed_with_payer(
&[instruction::set_fee(
Expand Down
6 changes: 5 additions & 1 deletion stake-pool/program/tests/set_withdrawal_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,11 @@ async fn fail_not_updated() {
};

// move forward so an update is required
context.warp_to_slot(50_000).unwrap();
let first_normal_slot = context.genesis_config().epoch_schedule.first_normal_slot;
let slots_per_epoch = context.genesis_config().epoch_schedule.slots_per_epoch;
context
.warp_to_slot(first_normal_slot + slots_per_epoch)
.unwrap();

let transaction = Transaction::new_signed_with_payer(
&[instruction::set_fee(
Expand Down
12 changes: 10 additions & 2 deletions stake-pool/program/tests/update_stake_pool_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ async fn success() {
}

// Update epoch
context.warp_to_slot(50_000).unwrap();
let first_normal_slot = context.genesis_config().epoch_schedule.first_normal_slot;
let slots_per_epoch = context.genesis_config().epoch_schedule.slots_per_epoch;
context
.warp_to_slot(first_normal_slot + slots_per_epoch)
.unwrap();

// Update list and pool
let error = stake_pool_accounts
Expand Down Expand Up @@ -213,7 +217,11 @@ async fn success_ignoring_extra_lamports() {
}

// Update epoch
context.warp_to_slot(50_000).unwrap();
let first_normal_slot = context.genesis_config().epoch_schedule.first_normal_slot;
let slots_per_epoch = context.genesis_config().epoch_schedule.slots_per_epoch;
context
.warp_to_slot(first_normal_slot + slots_per_epoch)
.unwrap();

// Update list and pool
let error = stake_pool_accounts
Expand Down
2 changes: 1 addition & 1 deletion stake-pool/program/tests/update_validator_list_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async fn setup(
}

// Warp forward so the stakes properly activate, and deposit
slot += 2 * slots_per_epoch;
slot += slots_per_epoch;
context.warp_to_slot(slot).unwrap();

stake_pool_accounts
Expand Down
7 changes: 5 additions & 2 deletions stake-pool/program/tests/vsa_remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,10 @@ async fn success_with_hijacked_transient_account() {
assert!(error.is_none());

// warp forward to merge
let first_normal_slot = context.genesis_config().epoch_schedule.first_normal_slot;
let slots_per_epoch = context.genesis_config().epoch_schedule.slots_per_epoch;
context.warp_to_slot(slots_per_epoch * 2).unwrap();
let mut slot = first_normal_slot + slots_per_epoch;
context.warp_to_slot(slot).unwrap();
stake_pool_accounts
.update_all(
&mut context.banks_client,
Expand All @@ -723,7 +725,8 @@ async fn success_with_hijacked_transient_account() {
assert!(error.is_none());

// warp forward to merge
context.warp_to_slot(slots_per_epoch * 4).unwrap();
slot += slots_per_epoch;
context.warp_to_slot(slot).unwrap();

// hijack
let validator_list = stake_pool_accounts
Expand Down

0 comments on commit 01765b9

Please sign in to comment.