Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise stake minimum delegation to 1 SOL #24603

Conversation

brooksprumo
Copy link
Contributor

@brooksprumo brooksprumo commented Apr 22, 2022

Problem

The minimum stake delegation is too low. For more information, see the main issue: #22559

Summary of Changes

  • Add feature gate to raise minimum stake delegation to 1.0 SOL
  • Actually set minimum delegation to 1 SOL
  • Use stake_raise_minimum_delegation feature in the stake program impl
  • Refactor tests to run for both old and new behavior

Feature Gate Issue: #24357

@brooksprumo brooksprumo added the feature-gate Pull Request adds or modifies a runtime feature gate label Apr 22, 2022
@brooksprumo brooksprumo force-pushed the minimum-stake/feature-gate/raise-minimum-delegation-to-1-sol branch 4 times, most recently from 51cc796 to d38b4f8 Compare April 25, 2022 19:34
@brooksprumo brooksprumo force-pushed the minimum-stake/feature-gate/raise-minimum-delegation-to-1-sol branch from d38b4f8 to 6bbdb7e Compare April 27, 2022 17:25
@brooksprumo brooksprumo force-pushed the minimum-stake/feature-gate/raise-minimum-delegation-to-1-sol branch from 6bbdb7e to b55196c Compare April 27, 2022 21:24
@brooksprumo brooksprumo force-pushed the minimum-stake/feature-gate/raise-minimum-delegation-to-1-sol branch from b55196c to 05c2981 Compare April 28, 2022 23:23
@brooksprumo brooksprumo force-pushed the minimum-stake/feature-gate/raise-minimum-delegation-to-1-sol branch from 05c2981 to 9002f63 Compare April 29, 2022 15:27
@brooksprumo brooksprumo force-pushed the minimum-stake/feature-gate/raise-minimum-delegation-to-1-sol branch from 9002f63 to 320dbb7 Compare May 3, 2022 17:59
@brooksprumo brooksprumo marked this pull request as ready for review May 3, 2022 21:04
@brooksprumo
Copy link
Contributor Author

I still need to figure out local-cluster tests timing out, but I think this PR is in a good enough state to begin the review process. Thanks in advance, reviewers!

cli/tests/stake.rs Outdated Show resolved Hide resolved
Comment on lines 6761 to 6731
mod old_behavior {
use super::*;

fn new_feature_set() -> FeatureSet {
let mut feature_set = FeatureSet::all_enabled();
feature_set.deactivate(&feature_set::raise_minimum_stake_delegation_to_1_sol::id());
feature_set
}

#[test]
fn test_stake_process_instruction() {
do_test_stake_process_instruction(new_feature_set());
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll see that I now run basically all the tests twice—once for the old minimum delegation, and once for the new minimum delegation. I wanted to be extra sure I didn't break any existing behavior and also had the correct new behavior as well, so this was the best way I found to do that. It would've been nice to change the test's process_instruction() to just always do both, but since it returns accounts now, that wasn't feasible[^1].

[^1] I could've, by returning a tuple of accounts for old and new behavior, but then tests with multiple calls to process_instruction() wouldn't really be fixed.

programs/stake/src/stake_state.rs Outdated Show resolved Hide resolved
runtime/src/bank.rs Outdated Show resolved Hide resolved
Comment on lines 26 to 33
pub fn get_minimum_delegation(feature_set: &FeatureSet) -> u64 {
if feature_set.is_active(&feature_set::raise_minimum_stake_delegation_to_1_sol::id()) {
const MINIMUM_DELEGATION_SOL: u64 = 1;
MINIMUM_DELEGATION_SOL * LAMPORTS_PER_SOL
} else {
#[allow(deprecated)]
solana_sdk::stake::MINIMUM_STAKE_DELEGATION
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here's basically the whole change.

@brooksprumo brooksprumo force-pushed the minimum-stake/feature-gate/raise-minimum-delegation-to-1-sol branch from 320dbb7 to 1f8d1aa Compare May 4, 2022 15:58
Comment on lines +1036 to 1037
if (feature_set.is_active(&stake_allow_zero_undelegated_amount::id())
|| feature_set.is_active(&feature_set::stake_raise_minimum_delegation_to_1_sol::id()))
&& stake_amount < crate::get_minimum_delegation(feature_set)
{
return Err(StakeError::InsufficientStake.into());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could've not added || feature_set.is_active(&feature_set::stake_raise_minimum_delegation_to_1_sol::id() to this if, but then I would require that the stake_allow_zero_undelegated_amount feature got activated first.

Granted, it likely will get activated first, but I didn't want to require it here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me

@brooksprumo brooksprumo force-pushed the minimum-stake/feature-gate/raise-minimum-delegation-to-1-sol branch from 1f8d1aa to a4e5394 Compare May 4, 2022 16:05
Comment on lines -1428 to -1429
let minimum_delegation = crate::get_minimum_delegation(&FeatureSet::all_enabled());
let stake_lamports = rent_exempt_reserve + minimum_delegation;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the stake_allow_zero_undelegated_amount feature, the minimum balance needed to initialize a stake account is just the rent exempt amount. With a higher minimum delegation, the test below that says // not enough balance for rent incorrectly passes since it contained extra lamports to still meet the minimum balance requirements.

@brooksprumo brooksprumo force-pushed the minimum-stake/feature-gate/raise-minimum-delegation-to-1-sol branch from a4e5394 to 3fa55d8 Compare May 4, 2022 16:13
@brooksprumo brooksprumo force-pushed the minimum-stake/feature-gate/raise-minimum-delegation-to-1-sol branch from 3fa55d8 to 2b52884 Compare May 6, 2022 03:01
@brooksprumo
Copy link
Contributor Author

CI has finally passed! This PR is now ready to merge, in addition to being ready to review.

jstarry
jstarry previously approved these changes May 6, 2022
programs/stake/src/stake_instruction.rs Outdated Show resolved Hide resolved
Comment on lines +1036 to 1037
if (feature_set.is_active(&stake_allow_zero_undelegated_amount::id())
|| feature_set.is_active(&feature_set::stake_raise_minimum_delegation_to_1_sol::id()))
&& stake_amount < crate::get_minimum_delegation(feature_set)
{
return Err(StakeError::InsufficientStake.into());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me

programs/stake/src/stake_state.rs Outdated Show resolved Hide resolved
CriesofCarrots
CriesofCarrots previously approved these changes May 6, 2022
sdk/src/feature_set.rs Show resolved Hide resolved
@mergify mergify bot dismissed stale reviews from jstarry and CriesofCarrots May 6, 2022 17:58

Pull request has been modified.

@codecov
Copy link

codecov bot commented May 7, 2022

Codecov Report

Merging #24603 (f4fcd7a) into master (69a0ff9) will increase coverage by 0.0%.
The diff coverage is 87.0%.

❗ Current head f4fcd7a differs from pull request most recent head f0264b8. Consider uploading reports for the commit f0264b8 to get more accurate results

@@           Coverage Diff            @@
##           master   #24603    +/-   ##
========================================
  Coverage    82.0%    82.1%            
========================================
  Files         598      598            
  Lines      165882   166376   +494     
========================================
+ Hits       136125   136635   +510     
+ Misses      29757    29741    -16     

@brooksprumo brooksprumo force-pushed the minimum-stake/feature-gate/raise-minimum-delegation-to-1-sol branch from f4fcd7a to f0264b8 Compare May 7, 2022 18:56
@brooksprumo brooksprumo merged commit e6c02f3 into solana-labs:master May 7, 2022
@brooksprumo brooksprumo deleted the minimum-stake/feature-gate/raise-minimum-delegation-to-1-sol branch May 9, 2022 17:23
@brooksprumo brooksprumo changed the title Raise minimum stake delegation to 1 SOL Raise stake minimum delegation to 1 SOL Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-gate Pull Request adds or modifies a runtime feature gate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants