Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Stake: Support merging fully-activated stake accounts#13712

Merged
t-nelson merged 5 commits intosolana-labs:masterfrom
t-nelson:stake-merge-active
Nov 23, 2020
Merged

Stake: Support merging fully-activated stake accounts#13712
t-nelson merged 5 commits intosolana-labs:masterfrom
t-nelson:stake-merge-active

Conversation

@t-nelson
Copy link
Copy Markdown
Contributor

Problem

Only deactivated stake accounts can be merged. This poses a dilemma for automated staking tools in that they can only adjust a delegation downward without managing an ever-growing pool of accounts. It also exposes an unexpected asymmetry with stake-split, which can be performed on delegated stake accounts

Summary of Changes

  • Minor refactor and cosmetics
  • Support merging two stake account if they are fully-active and their delegations are compatible

@t-nelson t-nelson added the noCI Suppress CI on this Pull Request label Nov 19, 2020
@t-nelson
Copy link
Copy Markdown
Contributor Author

t-nelson commented Nov 19, 2020

WIP while I write tests. Works as expected on a local-cluster though!

In the mean time, it'd be great to get a gut-check from @rwalker-com that this isn't utterly stupid for some obscure reason 🙏

Comment thread programs/stake/src/stake_state.rs Outdated
Comment thread programs/stake/src/stake_state.rs Outdated

fn can_merge_with(&self, source: &Self) -> bool {
self.voter_pubkey == source.voter_pubkey
&& (self.warmup_cooldown_rate - source.warmup_cooldown_rate).abs() < f64::EPSILON
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

you also want to verify that they were activated at the same time or are fully activated?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hey! Thanks for taking a peek! 🙂

I wasn't planning on handling the transient states. The fully-activated check is down here https://github.com/solana-labs/solana/pull/13712/files#diff-ab7997cf6770a6fae7b258e433b5dd8c33afa30431eab212552bc7f2b7b38db1R1164

Comment thread programs/stake/src/stake_state.rs Outdated
Comment thread programs/stake/src/stake_state.rs Outdated
Comment thread programs/stake/src/stake_state.rs Outdated
@t-nelson t-nelson marked this pull request as ready for review November 21, 2020 05:37
@t-nelson t-nelson added CI Pull Request is ready to enter CI and removed noCI Suppress CI on this Pull Request labels Nov 21, 2020
@solana-grimes solana-grimes removed the CI Pull Request is ready to enter CI label Nov 21, 2020
@t-nelson
Copy link
Copy Markdown
Contributor Author

I think this one's ready for final review now

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 21, 2020

Codecov Report

Merging #13712 (4b9413d) into master (f0f99ff) will increase coverage by 0.0%.
The diff coverage is 99.4%.

@@           Coverage Diff            @@
##           master   #13712    +/-   ##
========================================
  Coverage    82.1%    82.2%            
========================================
  Files         381      381            
  Lines       91992    92340   +348     
========================================
+ Hits        75613    75951   +338     
- Misses      16379    16389    +10     

Comment thread programs/stake/src/stake_state.rs Outdated
Comment thread programs/stake/src/stake_state.rs Outdated
Comment thread programs/stake/src/stake_state.rs Outdated
Comment thread programs/stake/src/stake_state.rs Outdated
Comment thread programs/stake/src/stake_state.rs Outdated
@t-nelson
Copy link
Copy Markdown
Contributor Author

I'll try to rethink the organization of the helper functions in light of the rest of the comments 🤔

Copy link
Copy Markdown
Contributor

@CriesofCarrots CriesofCarrots left a comment

Choose a reason for hiding this comment

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

Thanks for the extensive tests. I agree with @ryoqun that some expanded comments would help. Otherwise, looking good to me!
I'll take another pass when you make whatever helper fn changes you land on.

Comment thread programs/stake/src/stake_state.rs Outdated
Comment thread programs/stake/src/stake_state.rs Outdated
Comment thread programs/stake/src/stake_state.rs Outdated
Comment thread programs/stake/src/stake_state.rs Outdated
@t-nelson t-nelson force-pushed the stake-merge-active branch 3 times, most recently from 078513a to bdabd0a Compare November 22, 2020 08:11
Comment thread programs/stake/src/stake_state.rs
Comment thread programs/stake/src/stake_state.rs Outdated
Comment thread programs/stake/src/stake_state.rs Outdated
Comment thread programs/stake/src/stake_state.rs
Comment thread programs/stake/src/stake_state.rs
Comment thread programs/stake/src/stake_state.rs
@t-nelson t-nelson force-pushed the stake-merge-active branch 2 times, most recently from 5754317 to 9c9f2b5 Compare November 23, 2020 04:58
Copy link
Copy Markdown
Contributor Author

@t-nelson t-nelson left a comment

Choose a reason for hiding this comment

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

Ok, last round I think 😅

Comment thread programs/stake/src/stake_state.rs
Comment thread programs/stake/src/stake_state.rs Outdated
Comment thread programs/stake/src/stake_state.rs
Comment thread programs/stake/src/stake_state.rs
Comment thread programs/stake/src/stake_state.rs
Comment thread programs/stake/src/stake_state.rs
Comment thread programs/stake/src/stake_state.rs Outdated
@ryoqun
Copy link
Copy Markdown
Contributor

ryoqun commented Nov 23, 2020

Codecov Report

Merging #13712 (9c9f2b5) into master (1c7dd0a) will increase coverage by 0.0%.
The diff coverage is 100.0%.

Cool, '100.0%'. I sense you have a good stamina to attain very strong test coverage.

ryoqun
ryoqun previously approved these changes Nov 23, 2020
Copy link
Copy Markdown
Contributor

@ryoqun ryoqun left a comment

Choose a reason for hiding this comment

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

LGTM with nits.

Happily, I don't have anything anymore other than small renaming. What a solid work done from you. Also thank for enduring my persistent and long review window :)

CriesofCarrots
CriesofCarrots previously approved these changes Nov 23, 2020
Copy link
Copy Markdown
Contributor

@CriesofCarrots CriesofCarrots left a comment

Choose a reason for hiding this comment

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

lgtm w/ a couple nits as well!

Comment thread programs/stake/src/stake_state.rs Outdated
Comment thread programs/stake/src/stake_state.rs Outdated
Comment thread programs/stake/src/stake_state.rs
@t-nelson
Copy link
Copy Markdown
Contributor Author

Codecov Report

Merging #13712 (9c9f2b5) into master (1c7dd0a) will increase coverage by 0.0%.
The diff coverage is 100.0%.

Cool, '100.0%'. I sense you have a good stamina to attain very strong test coverage.

Screenshot from 2020-11-23 11-15-56
☝️ strong motivation 😆

@mergify mergify Bot dismissed stale reviews from ryoqun and CriesofCarrots November 23, 2020 18:49

Pull request has been modified.

Copy link
Copy Markdown
Contributor Author

@t-nelson t-nelson left a comment

Choose a reason for hiding this comment

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

Nits

#[error("stake account with activated stake cannot be merged")]
MergeActivatedStake,
#[error("stake account with transient stake cannot be merged")]
MergeTransientStake,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

More accurate error name/message

.0
}

// returned tuple is (effective, activating, deactivating) stake
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Commented stake_activating_and_deactivating() return tuple comment

true,
) {
/*
(e, a, d): e - effective, a - activating, d - deactivating */
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Heading comment for tuple patterns in get_if_mergeable() match.

Wonky use of multi-line comment to trick cargo fmt

}
}

fn active_stake(&self) -> Option<&Stake> {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

More descriptive name for active stake accessor

@t-nelson t-nelson added the v1.4 label Nov 23, 2020
@t-nelson t-nelson merged commit 488ce98 into solana-labs:master Nov 23, 2020
@t-nelson t-nelson deleted the stake-merge-active branch November 23, 2020 21:32
mergify Bot added a commit that referenced this pull request Nov 23, 2020
…3770)

* stake: De-replicode mergable info extraction

(cherry picked from commit dc7f897)

* stake: Cosmetic - rename variable

(cherry picked from commit bb2772d)

* stake: Allow compatible, fully-active stake accounts to be merged

(cherry picked from commit 8e73187)

* stake: Remove disused test helper function

(cherry picked from commit 6b9a019)

* stake: Disallow stakes merging with themselves

(cherry picked from commit 488ce98)

Co-authored-by: Trent Nelson <trent@solana.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants