-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix!: x/staking - remove delegation with amount is zero #10254
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #10254 +/- ##
=======================================
Coverage 64.15% 64.15%
=======================================
Files 572 572
Lines 53983 53989 +6
=======================================
+ Hits 34632 34636 +4
- Misses 17375 17377 +2
Partials 1976 1976
|
looks good. This needs an in-place store migration (and possible a json dump migration too) imo. @alexanderbez I'll let you decide if you want to do it here or in a follow-up PR |
Do we have a policy about when we should do a JSON migration? I think in-place migration should be present for each cleanup / state change. |
Imo it's not that much a human policy, but just to make sure that one version's |
I don't think this needs to change anything in the export JSON format / merits a migration there. I'd recommend just making the import logic ignore / not initialize things with zero amounts, but non-zero shares. In place state migration would be a nice state cleanup though! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for fixing this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! the module's ConsensusVersion needs to be bumped, and I think an in-place migration would be useful to purge the state (both can be done in a follow-up though)
I'll do it in this PR along with fixing tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
2 sims related to import/exports are failing though |
Yeah I've been trying to debug them @AmauryM. The issue lies in the import genesis changes. It doesn't like the fact that I manually remove delegations. |
@ValarDragon so turns out there are cases, at least in the simulation with seed 1, where in
|
hrmm, I guess you can have 0 tokens and shares if you had I don't see why the validator has to have shares tho |
@ValarDragon I'm going to undo the LMK if this is OK with you and we can merge this PR. |
That sounds good to me! Then this is fixing things going forward, which is already a significant improvement =) |
// Remove the delegation if the resulting shares yield a truncated zero amount | ||
// of tokens in the delegation. Note, in this this case, the shares themselves | ||
// may not be zero, but rather a small fractional amount. Otherwise, we update | ||
// the delegation object. | ||
if validator.TokensFromShares(delegation.Shares).TruncateInt().IsZero() || delegation.Shares.IsZero() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexanderbez do you think this could break delegator shares invariant, causing #10750 ?
@aleem1314 did some debugging on this, here's some logs:
++++++++++++++++++++++++++++++++++++
TOKENS-FROM-SHARES = 0.937500000000000000 validator.TokensFromShares(delegation.Shares).TruncateInt() = 0
DELEGATIONS SHARES = 0.937500000000000000
VALIDATOR = cosmosvaloper14rmvn8ymw7mdjwyjhmkzestgkcdskvkx6ke9e5
DELEGATOR = cosmos15rxvlc2xaf6sjq5fjq45gfapdjsjr97jy6wmjc
BLOCKHEIGHT = 32
BLOCKTIME = 2103-10-01 17:18:06 +0000 UTC
++++++++++++++++++++++++++++++++++++
just reverting this line and simulations pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm could be! But what invariant is broken exactly? The delegation should be deleted here. Is there some invariant that expects this not to be deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DelegatorSharesInvariant
one. Maybe it should be updated to take TruncateInt
into account? The error message is:
broken delegator shares invariance:
validator.DelegatorShares: 34148342106.937500000000000000
sum of Delegator.Shares: 34148342106.000000000000000000
which soulds like some truncating error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, let's keep the discussion in the new issue created 👍
## Description Revert #10254 Closes: #10750 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
Description
Closes: #10216
Instead of using the shares to determine if a delegation should be removed, use the truncated (token) amount.
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change