From 3361871198512ca40ccd9f479313a748e0a40874 Mon Sep 17 00:00:00 2001 From: Alexander Bezobchuk Date: Thu, 4 Apr 2019 13:53:22 -0400 Subject: [PATCH] Merge PR #4047: Fix queryDelegationRewards --- CHANGELOG.md | 2 ++ x/distribution/keeper/querier.go | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 113597cb7..0d01901e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/x/distribution/keeper/querier.go b/x/distribution/keeper/querier.go index ac40700c5..984bb7448 100644 --- a/x/distribution/keeper/querier.go +++ b/x/distribution/keeper/querier.go @@ -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 + 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)