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

stake-pool: Remove lamport minimum for validator removal by staker #3999

Merged
merged 2 commits into from
Jan 27, 2023

Conversation

joncinque
Copy link
Contributor

@joncinque joncinque commented Jan 25, 2023

Problem

Deactivating a validator requires reducing its active stake to the minimum delegation first. However, the funds all go back to the reserve anyway, so there's no reason to gate the removal to some lamport amount.

Solution

Remove the lamport check.

Fixes #3994

Comment on lines 1188 to 1191
let required_delegation = minimum_delegation(stake_minimum_delegation)
.saturating_mul(LAMPORT_BUFFER_FACTOR)
.saturating_add(meta.rent_exempt_reserve);
if stake.delegation.stake > required_delegation {
Copy link
Member

@2501babe 2501babe Jan 27, 2023

Choose a reason for hiding this comment

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

the intent of this and the similar calculation at 1172-1174 are very confusing to me

without this pr, required_lamports = MINSTAKE + RENT and required_delegation = MINSTAKE. the two checks essentially confirm (i flip the signs to indicate success conditions) that:

  • stake_lamports <= required_lamports: the stake account has at most the minimum non-stake lamports for rent-exemption (kinda sorta... this assumes we have exactly MINSTAKE stake, but the only case where thats not true is if the variable is increased out from under us)
  • stake.delegation.stake <= required_delegation: the stake account has at most the minimum stake

now required_lamports = 2(MINSTAKE + RENT) and required_delegation = 2MINSTAKE + RENT. multiplying the rent by two in the first calculation seems like a mistake, which makes the constraint looser by RENT than intended, in which case the two variables maybe should be equal

but is this actually what we want to check? i think we actually care that there are no loose lamports in the account, ie stake_lamports == stake.delegation.stake + RENT

for the second calculation, why do we add the rent to compare to the stake? we expect to see at most 2MINSTAKE stake, because the lamps for rent-exemption dont show up in this number. maybe im missing something because the comment indicates this is on purpose tho...

but stepping back a bit... do we even need any of this? does anything bad happen if you remove a validator with extra stake or extra lamports in it? it all just goes back to the reserve either way, doesnt it? or is this to incentivize redelegation? but this code predates the redelegate instruction? i guess when i think about it i dont know what any of its for

Copy link
Contributor Author

Choose a reason for hiding this comment

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

now required_lamports = 2(MINSTAKE + RENT) and required_delegation = 2MINSTAKE + RENT. multiplying the rent by two in the first calculation seems like a mistake, which makes the constraint looser by RENT than intended, in which case the two variables maybe should be equal

I thought so too at first, but in order to decrease a validator's stake, you need to be able to split a minimum stake from it, while maintaining minimum stake in the validator stake account. So that means you need to split minimum_delegation + stake_rent, while maintaining minimum_delegation + stake_rent in the source account, which means it needed 2 * (minimum_delegation + stake_rent)

but stepping back a bit... do we even need any of this? does anything bad happen if you remove a validator with extra stake or extra lamports in it? it all just goes back to the reserve either way, doesnt it?

This is an excellent point. The checks were from the times when the staker would put up the lamports for rent-exemption + minimum_delegation, so that the staker couldn't reclaim more than they put in. Now that everything comes from the reserve, there's no reason to keep this so complicated, and instead simplify the check to "if there's transient stake, make sure it's deactivating"

@joncinque joncinque changed the title stake-pool: Relax lamport minimum for validator removal by staker stake-pool: Remove lamport minimum for validator removal by staker Jan 27, 2023
@joncinque
Copy link
Contributor Author

Completely removed the check, thanks for noticing!

@2501babe 2501babe self-requested a review January 27, 2023 21:36
@joncinque joncinque merged commit ab67891 into solana-labs:master Jan 27, 2023
@joncinque joncinque deleted the sp-relax branch January 27, 2023 22:52
HaoranYi pushed a commit to HaoranYi/solana-program-library that referenced this pull request Jul 19, 2023
…olana-labs#3999)

* stake-pool: Relax lamport minimum for validator removal by staker

* Completely remove the lamport check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

stake-pool: Deactivating Validator With Less Than 2x Min Delegation (OS-SSP-SUG-02)
2 participants