From 082f1ed03d2dc06a15de88eeffe3ffb2ce9b4f78 Mon Sep 17 00:00:00 2001 From: Brooks Prumo Date: Tue, 19 Apr 2022 14:25:26 -0500 Subject: [PATCH] Use raise_minimum_stake_delegation feature in the stake program impl --- programs/stake/src/stake_instruction.rs | 1 + programs/stake/src/stake_state.rs | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/programs/stake/src/stake_instruction.rs b/programs/stake/src/stake_instruction.rs index 1c157803884be6..8702c1a2b8c628 100644 --- a/programs/stake/src/stake_instruction.rs +++ b/programs/stake/src/stake_instruction.rs @@ -187,6 +187,7 @@ pub fn process_instruction( &stake_history, &config, &signers, + &invoke_context.feature_set, ) } Ok(StakeInstruction::Split(lamports)) => { diff --git a/programs/stake/src/stake_state.rs b/programs/stake/src/stake_state.rs index e1bb45385c1834..03dc06435e5313 100644 --- a/programs/stake/src/stake_state.rs +++ b/programs/stake/src/stake_state.rs @@ -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, @@ -558,6 +559,7 @@ pub fn delegate( stake_history: &StakeHistory, config: &Config, signers: &HashSet, + feature_set: &FeatureSet, ) -> Result<(), InstructionError> { let vote_account = instruction_context.try_borrow_account(transaction_context, vote_account_index)?; @@ -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, @@ -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, @@ -1000,10 +1002,17 @@ struct ValidatedDelegatedInfo { fn validate_delegated_amount( account: &BorrowedAccount, meta: &Meta, + feature_set: &FeatureSet, ) -> Result { 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 }) }