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] Add WithdrawDelegationRewards message #3686

Merged
merged 7 commits into from
Dec 23, 2022
Merged

Conversation

stackman27
Copy link
Contributor

Part of : #2579

What is the purpose of the change

Adds new message WithdrawDelegationRewards.

  1. WithdrawDelegationRewards withdraws all the delegation rewards from the validator in the val-set.
  2. Delegation reward is collected by the validator and in doing so, they can charge commission to the delegators.
  3. Rewards are calculated per period, and is updated each time validator delegation changes.

Brief Changelog

n/a

Testing and Verifying

Added msg_server test for to check functionality

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)

@github-actions github-actions bot added the C:app-wiring Changes to the app folder label Dec 10, 2022
@stackman27 stackman27 added the V:state/breaking State machine breaking PR label Dec 10, 2022
x/valset-pref/keeper_test.go Outdated Show resolved Hide resolved
x/valset-pref/msg_server_test.go Outdated Show resolved Hide resolved
@@ -19,3 +19,10 @@ type StakingInterface interface {
type BankKeeper interface {
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
}

type CommunityPoolKeeper interface {
Copy link
Member

@ValarDragon ValarDragon Dec 20, 2022

Choose a reason for hiding this comment

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

Suggested change
type CommunityPoolKeeper interface {
// For testing only
type DistributionKeeper interface {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why for testing only?

Copy link
Member

Choose a reason for hiding this comment

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

Its only used in testing? The main logic shouldn't use it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes 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.

We are using WithdrawDelegationRewards(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (sdk.Coins, error) in code that falls under this interface

Copy link
Member

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

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

logic LGTM, but needs more entries in table test case, at minimum for no valset set, no delegations, no valset explicitly set, one existing delegation

@stackman27
Copy link
Contributor Author

@ValarDragon @czarcas7ic added more tests coverage as you suggested

name: "Withdraw all rewards with existing delegation",
delegator: sdk.AccAddress([]byte("addr1---------------")),
coinToStake: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(20_000_000)), // delegate 20osmo
setValSet: true,
Copy link
Member

Choose a reason for hiding this comment

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

Should be false, right?

Copy link
Member

Choose a reason for hiding this comment

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

or we need a test case with both this set, and it not set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in this context "existing delegation" is "existing valset delegations"

The WithdrawLogic also only check rewards from existing valset delegations

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I would expect it to work s.t. if I have no valset explicitly set, it infers my valset is my existing delegation set, and withdraws from everyone via that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea i can get that to work, the only thing is that GetDelegatorDelegations(ctx sdk.Context, delegator sdk.AccAddress, maxRetrieve uint16) takes in uint16 and we might have to pass math.MaxUint16 that could get a little expensive

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just added withdraw existing delegation reward!

@stackman27
Copy link
Contributor Author

@ValarDragon @czarcas7ic added test cases and logic for existing staking position that's not valset. lmk what you think

delegations := k.stakingKeeper.GetDelegatorDelegations(ctx, delegator, math.MaxUint16)

// get the existing validator set preference
existingSet, found := k.GetValidatorSetPreference(ctx, delegatorAddr)
Copy link
Member

Choose a reason for hiding this comment

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

I guess I'm confused -- I thought the module design was always such that GetValidatorSetPreference returns your existing staking distribution if you haven't set one.

Is that not the case or only in query logic?

Copy link
Contributor Author

@stackman27 stackman27 Dec 22, 2022

Choose a reason for hiding this comment

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

Unfortunately that is not the case, GetValidatorSetPreference only returns val-set staking distributions

Copy link
Member

Choose a reason for hiding this comment

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

ok, imo we need to change that (which I thought was the initial design for valset pref)

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.

for sure, it wont be a massive change tbh. Logic will be something like.

func GetValidatorSetPreference() dels{
valsetDels, vsFound := getvalsetDels(...) 
 if !vsFound {
   existingstakingDels, stFound := getstakingDels(...) 
   if !stFound {
    return err ("No delegations") 
 }
return existingstakingDels 
} 
return valsetDels 
}

Few questions;

  1. What about cases where we need both existing valset and staking position or either or? 2. For instance: In SetValSet, we donot care about existingstakingDels, same with delegateToValSet, but undelegate, withdraw and redelegate will need both
  2. Also non valset positions will not have weights but the current code expects weights for every validator

Copy link
Member

Choose a reason for hiding this comment

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

  1. if a valset is set return that. (ignore staking position, that may diverge)
  2. You can derive the weight on the fly based on ratio of staked amounts

Copy link
Member

Choose a reason for hiding this comment

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

I'm down to merge this PR, but lets do the above as a release blocking feature.

Can you make an issue? Then we can merge this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added issue #3848

Copy link
Member

@czarcas7ic czarcas7ic left a comment

Choose a reason for hiding this comment

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

LGTM, now that issue has been created, I will merge this

@czarcas7ic czarcas7ic merged commit 58dfab3 into main Dec 23, 2022
@czarcas7ic czarcas7ic deleted the sis/MsgDel-reward branch December 23, 2022 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:app-wiring Changes to the app folder V:state/breaking State machine breaking PR
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants