Skip to content

Commit

Permalink
Use raise_minimum_stake_delegation feature in the stake program impl
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo committed May 3, 2022
1 parent 4150add commit 082f1ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions programs/stake/src/stake_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ pub fn process_instruction(
&stake_history,
&config,
&signers,
&invoke_context.feature_set,
)
}
Ok(StakeInstruction::Split(lamports)) => {
Expand Down
15 changes: 12 additions & 3 deletions programs/stake/src/stake_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use {
account_utils::StateMut,
clock::{Clock, Epoch},
feature_set::{
stake_merge_with_unmatched_credits_observed, stake_split_uses_rent_sysvar, FeatureSet,
self, stake_merge_with_unmatched_credits_observed, stake_split_uses_rent_sysvar,
FeatureSet,
},
instruction::{checked_add, InstructionError},
pubkey::Pubkey,
Expand Down Expand Up @@ -558,6 +559,7 @@ pub fn delegate(
stake_history: &StakeHistory,
config: &Config,
signers: &HashSet<Pubkey>,
feature_set: &FeatureSet,
) -> Result<(), InstructionError> {
let vote_account =
instruction_context.try_borrow_account(transaction_context, vote_account_index)?;
Expand All @@ -574,7 +576,7 @@ pub fn delegate(
StakeState::Initialized(meta) => {
meta.authorized.check(signers, StakeAuthorize::Staker)?;
let ValidatedDelegatedInfo { stake_amount } =
validate_delegated_amount(&stake_account, &meta)?;
validate_delegated_amount(&stake_account, &meta, feature_set)?;
let stake = new_stake(
stake_amount,
&vote_pubkey,
Expand All @@ -587,7 +589,7 @@ pub fn delegate(
StakeState::Stake(meta, mut stake) => {
meta.authorized.check(signers, StakeAuthorize::Staker)?;
let ValidatedDelegatedInfo { stake_amount } =
validate_delegated_amount(&stake_account, &meta)?;
validate_delegated_amount(&stake_account, &meta, feature_set)?;
redelegate(
&mut stake,
stake_amount,
Expand Down Expand Up @@ -1000,10 +1002,17 @@ struct ValidatedDelegatedInfo {
fn validate_delegated_amount(
account: &BorrowedAccount,
meta: &Meta,
feature_set: &FeatureSet,
) -> Result<ValidatedDelegatedInfo, InstructionError> {
let stake_amount = account
.get_lamports()
.saturating_sub(meta.rent_exempt_reserve); // can't stake the rent
if feature_set.is_active(&feature_set::raise_minimum_stake_delegation_to_1_sol::id())
&& stake_amount < crate::get_minimum_delegation(feature_set)
{
return Err(InstructionError::InsufficientStakeDelegation);
}

Ok(ValidatedDelegatedInfo { stake_amount })
}

Expand Down

0 comments on commit 082f1ed

Please sign in to comment.