-
Notifications
You must be signed in to change notification settings - Fork 557
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
feat: unbond with rebalanced val set weights #6685
feat: unbond with rebalanced val set weights #6685
Conversation
// ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
// err := server.keeper.UndelegateFromValidatorSet(ctx, msg.Delegator, msg.Coin) | ||
// if err != nil { | ||
// return nil, err | ||
// } | ||
|
||
return &types.MsgUndelegateFromValidatorSetResponse{}, fmt.Errorf("not implemented, utilize UndelegateFromRebalancedValidatorSet instead") | ||
} |
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.
Disables UndelegateFromValidatorSet
in the msg server
// } | ||
// } | ||
|
||
func (s *KeeperTestSuite) TestUnDelegateFromRebalancedValidatorSet() { |
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.
TestUnDelegateFromRebalancedValidatorSet
is identical to the commented out TestUnDelegateFromValidatorSet
, because the behavior of UnDelegateFromValidatorSet
is technically UnDelegateFromRebalancedValidatorSet
.
// func NewUnDelValSetCmd() (*osmocli.TxCliDesc, *types.MsgUndelegateFromValidatorSet) { | ||
// return &osmocli.TxCliDesc{ | ||
// Use: "undelegate-valset", | ||
// Short: "UnDelegate tokens from existing valset using delegatorAddress and tokenAmount.", | ||
// Example: "osmosisd tx valset-pref undelegate-valset osmo1... 100stake", | ||
// NumArgs: 2, | ||
// }, &types.MsgUndelegateFromValidatorSet{} | ||
// } |
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.
Disable the CLI for undelegate-valset
cmd.
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.
Discussed having a separate function offline and I agree this gets us to a preferable place in the tradeoff space (where minimizing last-minute implementation overhead is a high priority).
I left two comments covering what I believe are blocking issues that should be quick to address. The rest looks good to me.
} | ||
|
||
// System Under Test | ||
err := s.App.ValidatorSetPreferenceKeeper.UndelegateFromRebalancedValidatorSet(s.Ctx, defaultDelegator.String(), sdk.NewCoin(bondDenom, test.undelegateAmt)) |
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.
Don't want to block this PR, but I think we're actually not testing the main important thing here which is that directly delegating/undelegating from a validator changes the weights when the new message is called.
E.g. if it starts at 0.1/0.9 with 10 tokens in validator A and 90 in validator B, then when you delegate 100 tokens to validator A, then withdrawing rebalanced should yield a distribution of 0.55/0.45 (since now validator A has 110 tokens out of 200 and validator B has 90 out of 200)
Would it be possible for us to add tests covering these? I think this could potentially be done with an additional test field and putting system under test into a loop so it runs multiple times with different conditions.
x/valset-pref/validator_set.go
Outdated
// in the last valset iteration we don't calculate it from shares using decimals and trucation, | ||
// we use whats remaining to get more accurate value | ||
if len(existingSet.Preferences)-1 == index { | ||
amountToUnDelegate = undelegation.Amount.Sub(totalUnDelAmt).ToLegacyDec().TruncateInt() | ||
} else { |
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.
Lets make amountToUndelegate = Min(amountToUndelegate, amount_staked_to_this_val)
just in case some rounding issue increases it.
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.
Added the logic you described cc584e7
Although I am not quite sure how to force this in a gotest, seems like just a guard rail.
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.
Logic Lgtm; have not reviewed tests
* Add helper to get existing delegations along with valset pref * Lay out more of the logic nuance * Add pseudo-code needed * algorithm v1 * added algorithm docs * fixed all test * removed unwanted files * remove more code * added more tests * update changelog * added test and addressed feedback * Update x/valset-pref/validator_set.go * Update x/valset-pref/validator_set.go * Update x/valset-pref/README.md * Minor cleanup * re-use validator gets * Refactor * Highlight bug * fixed the issue * added comments * update changelog * fixed the issue * fixed go test * fixed test * lint * Finish ValSet Pref Unbonding (#6630) * Add Test cases and fix * Update x/valset-pref/keeper.go * Adams comment * add error types and tidy test --------- Co-authored-by: Adam Tucker <adam@osmosis.team> Co-authored-by: Adam Tucker <adamleetucker@outlook.com> * feat: unbond with rebalanced val set weights (#6685) * initial push * add todo * msg server test * add godoc * custom error * update godoc * update proto and remove duplication * add more TODOs * use min when calculating amt to withdraw from last val * Update x/valset-pref/validator_set.go --------- Co-authored-by: stackman27 <sis1001@berkeley.edu> Co-authored-by: devbot-wizard <141283918+devbot-wizard@users.noreply.github.com> Co-authored-by: Adam Tucker <adam@osmosis.team> Co-authored-by: roman <roman@osmosis.team> Co-authored-by: Matt, Park <45252226+mattverse@users.noreply.github.com> Co-authored-by: Adam Tucker <adamleetucker@outlook.com>
* Add helper to get existing delegations along with valset pref * Lay out more of the logic nuance * Add pseudo-code needed * algorithm v1 * added algorithm docs * fixed all test * removed unwanted files * remove more code * added more tests * update changelog * added test and addressed feedback * Update x/valset-pref/validator_set.go * Update x/valset-pref/validator_set.go * Update x/valset-pref/README.md * Minor cleanup * re-use validator gets * Refactor * Highlight bug * fixed the issue * added comments * update changelog * fixed the issue * fixed go test * fixed test * lint * Finish ValSet Pref Unbonding (#6630) * Add Test cases and fix * Update x/valset-pref/keeper.go * Adams comment * add error types and tidy test --------- Co-authored-by: Adam Tucker <adam@osmosis.team> Co-authored-by: Adam Tucker <adamleetucker@outlook.com> * feat: unbond with rebalanced val set weights (#6685) * initial push * add todo * msg server test * add godoc * custom error * update godoc * update proto and remove duplication * add more TODOs * use min when calculating amt to withdraw from last val * Update x/valset-pref/validator_set.go --------- Co-authored-by: stackman27 <sis1001@berkeley.edu> Co-authored-by: devbot-wizard <141283918+devbot-wizard@users.noreply.github.com> Co-authored-by: Adam Tucker <adam@osmosis.team> Co-authored-by: roman <roman@osmosis.team> Co-authored-by: Matt, Park <45252226+mattverse@users.noreply.github.com> Co-authored-by: Adam Tucker <adamleetucker@outlook.com> (cherry picked from commit e12011b)
* Add helper to get existing delegations along with valset pref * Lay out more of the logic nuance * Add pseudo-code needed * algorithm v1 * added algorithm docs * fixed all test * removed unwanted files * remove more code * added more tests * update changelog * added test and addressed feedback * Update x/valset-pref/validator_set.go * Update x/valset-pref/validator_set.go * Update x/valset-pref/README.md * Minor cleanup * re-use validator gets * Refactor * Highlight bug * fixed the issue * added comments * update changelog * fixed the issue * fixed go test * fixed test * lint * Finish ValSet Pref Unbonding (#6630) * Add Test cases and fix * Update x/valset-pref/keeper.go * Adams comment * add error types and tidy test --------- Co-authored-by: Adam Tucker <adam@osmosis.team> Co-authored-by: Adam Tucker <adamleetucker@outlook.com> * feat: unbond with rebalanced val set weights (#6685) * initial push * add todo * msg server test * add godoc * custom error * update godoc * update proto and remove duplication * add more TODOs * use min when calculating amt to withdraw from last val * Update x/valset-pref/validator_set.go --------- Co-authored-by: stackman27 <sis1001@berkeley.edu> Co-authored-by: devbot-wizard <141283918+devbot-wizard@users.noreply.github.com> Co-authored-by: Adam Tucker <adam@osmosis.team> Co-authored-by: roman <roman@osmosis.team> Co-authored-by: Matt, Park <45252226+mattverse@users.noreply.github.com> Co-authored-by: Adam Tucker <adamleetucker@outlook.com> (cherry picked from commit e12011b) Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
* Add helper to get existing delegations along with valset pref * Lay out more of the logic nuance * Add pseudo-code needed * algorithm v1 * added algorithm docs * fixed all test * removed unwanted files * remove more code * added more tests * update changelog * added test and addressed feedback * Update x/valset-pref/validator_set.go * Update x/valset-pref/validator_set.go * Update x/valset-pref/README.md * Minor cleanup * re-use validator gets * Refactor * Highlight bug * fixed the issue * added comments * update changelog * fixed the issue * fixed go test * fixed test * lint * Finish ValSet Pref Unbonding (#6630) * Add Test cases and fix * Update x/valset-pref/keeper.go * Adams comment * add error types and tidy test --------- Co-authored-by: Adam Tucker <adam@osmosis.team> Co-authored-by: Adam Tucker <adamleetucker@outlook.com> * feat: unbond with rebalanced val set weights (#6685) * initial push * add todo * msg server test * add godoc * custom error * update godoc * update proto and remove duplication * add more TODOs * use min when calculating amt to withdraw from last val * Update x/valset-pref/validator_set.go --------- Co-authored-by: stackman27 <sis1001@berkeley.edu> Co-authored-by: devbot-wizard <141283918+devbot-wizard@users.noreply.github.com> Co-authored-by: Adam Tucker <adam@osmosis.team> Co-authored-by: roman <roman@osmosis.team> Co-authored-by: Matt, Park <45252226+mattverse@users.noreply.github.com> Co-authored-by: Adam Tucker <adamleetucker@outlook.com>
Closes: #XXX
What is the purpose of the change
The current implementation of unbonding from validator set is broken. It is really close to being fixed, but we decided to go with a method that simply determines the new weights of the val set based on the user's current delegations to that val set.
For ex: if my valset is 30/60 to valA and valB, but I have 10 OSMO delgated to valA and 90 to valB, if I call the new undelegate rebalanced method here for 50 OSMO, it undelegates 5 OSMO from valA and 45 OSMO from valB.
I know we have opinions on dead code existing in prod, but I really think it makes sense to just disable the original undelegate message, and post v20 we can make the small tweak needed to fix this and test it, rather than completely removing it and having to rewire it.
Testing and Verifying
Added a gotest to show the above behavior is what actually happens.