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

[ValSet-Pref] Make Redelegate to valset read all your current stake positions #3833

Merged
merged 10 commits into from
Jan 20, 2023

Conversation

stackman27
Copy link
Contributor

Closes: #3761
Part of : #2579

What is the purpose of the change

In #3599 the redelegate to (new valset pref list) message redelegates from your current valset.

Instead, we should change this to redelegate from all of your current staked positions. So that way the UX can be "Set new valset preference", "Redelegate everything to this new preference list", and it gracefully handles that you used to stake without a preference list.

Brief Changelog

n/a

Testing and Verifying

testing redelegation with existing non-valset delegation

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? (yes / no)
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md? (yes / no)
  • How is the feature or change documented? (not applicable / specification (x/<module>/spec/) / Osmosis docs repo / not documented)

@stackman27 stackman27 added the V:state/breaking State machine breaking PR label Dec 23, 2022
@stackman27 stackman27 marked this pull request as ready for review December 23, 2022 03:11
coinToStake: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(20_000_000)),
expectedShares: []sdk.Dec{sdk.NewDec(10_000_000), sdk.NewDec(6_000_000), sdk.NewDec(4_000_000)},
valSetDelegationExist: true,
expectPass: false, // cannot redelegate to same validator set
Copy link
Member

Choose a reason for hiding this comment

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

Why is this the design? If I delegate to A (0.2) B (0.5) C (0.3) and want to redelegate to balance to A (0.3) B (0.5) C (0.2), why doesn't this do a single redelegate message from C to A?

Copy link
Contributor Author

@stackman27 stackman27 Dec 23, 2022

Choose a reason for hiding this comment

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

So in the sdk it checks if sourceAddr == destAddr (code)

But the test failure is happening because of our redelegation algorithm, for ex:

Existing Set {A: 0.2, B: 0.5, C: 0.3}, NewSet {A: 0.3, B: 0.5, C: 0.2} 
Delegate 20osmo 
ExistingSet{A: 4, B: 10, C: 6}, NewSet{A: 6, B: 10, C: 4}, DiffSet: {A:4, B:10, C:6, A: -6, B: -10, C: -4} 

Perform Redelegation
A --redelegate--> B (4osmo) 
B --redelegate--> B (6osmo) (ERROR: Self delegation) 

** Suppose we force the source and destination address to be different** 
Perform Redelegation
A --redelegate--> B (4osmo) 
B --redelegate--> A (6osmo) (ERROR: Redelegation to ValB is already in progress) 

To fix this the algorithm should be aware of the val addresses it's using and also if redelegation is possible from that address which could make things a lil complicated, i can make an issue on this and explore it over holidays

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 thought about this a lot and there's still issues even if we make sourceValAddr != targetValAddr

something like this for instance;

"If I delegate to A (0.2) B (0.5) C (0.3) and want to redelegate to balance to A (0.3) B (0.5) C (0.2), why doesn't this do a single redelegate message from C to A?"

Redelegation has to be done from C --> A, and then A --> C. But A --> C isn't possible because "Redelegation to ValidatorA is in progress and must complete before we perform another redelegation"

@stackman27 stackman27 marked this pull request as draft December 28, 2022 02:33
@stackman27 stackman27 marked this pull request as ready for review December 28, 2022 02:41
@stackman27
Copy link
Contributor Author

@ValarDragon this PR is R4R

@stackman27 stackman27 requested a review from mattverse January 9, 2023 18:24
@stackman27
Copy link
Contributor Author

converting this to draft because, I think its better if we merge this after #3857

@stackman27 stackman27 marked this pull request as draft January 9, 2023 18:33
@stackman27 stackman27 force-pushed the sis/curr-stake-pos branch 2 times, most recently from 238a121 to 7c0ebd6 Compare January 14, 2023 23:31
@stackman27 stackman27 marked this pull request as ready for review January 14, 2023 23:34
x/valset-pref/validator_set.go Outdated Show resolved Hide resolved
}

// reDelegationAmt to is the amount to redelegate, which is the min of diffAmount and target_validator
reDelegationAmt := sdk.MinDec(target_val.amount.Abs(), diff_val.amount)
reDelegationAmt := sdk.MinDec(target_val.amount.Abs(), diff_val.amount).TruncateDec()
Copy link
Member

Choose a reason for hiding this comment

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

If we truncateDec here, would it not be possible to go into a infinite for loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hrmm i haven't seen any cases for infinite loop yet. I will be simulator testing this feature so, if i find anything i will address it

@@ -554,11 +529,9 @@ func (suite *KeeperTestSuite) TestRedelegateValidatorSet() {
del, _ := suite.App.StakingKeeper.GetDelegation(suite.Ctx, test.delegator, valAddr)
suite.Require().Equal(del.Shares, test.expectedShares[i])
}

} else {
suite.Require().Error(err)
Copy link
Member

Choose a reason for hiding this comment

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

Can we add checks that exisitng delegations pertain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm so like check if the existing validators amount decreased? I'm a lil confused with what exactly to test

Copy link
Member

Choose a reason for hiding this comment

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

no the opposite, if redelegation has failed due to an error, we should not have changed positions for delegations, but the delegation for the account should remain the same. Thus we want to check here if this is the case. Would this make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh yea, to check if the state reverts right. I have confirmed through CLI testing that it reverts!

@stackman27 stackman27 requested a review from mattverse January 18, 2023 08:04
@sunnya97
Copy link
Collaborator

@github-actions github-actions bot added the C:docs Improvements or additions to documentation label Jan 20, 2023
Copy link
Member

@mattverse mattverse left a comment

Choose a reason for hiding this comment

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

LGTM

x/valset-pref/README.md Outdated Show resolved Hide resolved
x/valset-pref/README.md Outdated Show resolved Hide resolved
@czarcas7ic czarcas7ic merged commit d95e3b7 into main Jan 20, 2023
@czarcas7ic czarcas7ic deleted the sis/curr-stake-pos branch January 20, 2023 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:docs Improvements or additions to documentation V:state/breaking State machine breaking PR
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Validator set preferences: Make Redelegate to valset read all your current stake positions
4 participants