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

Fix queryDelegationRewards #4047

Merged
merged 4 commits into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
either the truncated coins or the change coins.
* [\#3915](https://github.com/cosmos/cosmos-sdk/issues/3915) Remove ';' delimiting support from ParseDecCoins
* [\#3977](https://github.com/cosmos/cosmos-sdk/issues/3977) Fix docker image build
* [\#4020](https://github.com/cosmos/cosmos-sdk/issues/4020) Fix queryDelegationRewards by returning an error
when the validator or delegation do not exist.

## 0.33.2

Expand Down
10 changes: 10 additions & 0 deletions x/distribution/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,17 @@ func queryDelegationRewards(ctx sdk.Context, _ []string, req abci.RequestQuery,
ctx, _ = ctx.CacheContext()

val := k.stakingKeeper.Validator(ctx, params.ValidatorAddress)
if val == nil {
// TODO: Should use ErrNoValidatorFound from staking/types
Copy link
Contributor Author

@alexanderbez alexanderbez Apr 4, 2019

Choose a reason for hiding this comment

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

We should be using those error types defined in staking. I see a few options:

  1. Simply import and use staking/types
  2. Add alias functions in distribution which are set at runtime by the staking module
  3. Have methods in the staking keeper actually return an appropriate error instead of nil or a bool (i.e. GetValidator should return (Validator, sdk.Error/error) instead of bool)

I'm biased towards (3) as that is the cleanest approach.

/cc @rigelrozanski @cwgoes

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1 to option (3)

return nil, sdk.ErrInternal(fmt.Sprintf("validator %s does not exist", params.ValidatorAddress))
}

del := k.stakingKeeper.Delegation(ctx, params.DelegatorAddress, params.ValidatorAddress)
if del == nil {
// TODO: Should use ErrNoDelegation from staking/types
return nil, sdk.ErrInternal("delegation does not exist")
}

endingPeriod := k.incrementValidatorPeriod(ctx, val)
rewards := k.calculateDelegationRewards(ctx, val, del, endingPeriod)

Expand Down