Skip to content

Commit

Permalink
fix(estaking): prevent reward to invalid delegations (#1034)
Browse files Browse the repository at this point in the history
* fix(estaking): prevent reward to invalid delegations

* test(estaking): fix

* ci: minor
  • Loading branch information
cosmic-vagabond authored Dec 6, 2024
1 parent 908aaac commit 13c05fc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/software-upgrade-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
echo "SNAPSHOT_BLOCK_HEIGHT=$SNAPSHOT_BLOCK_HEIGHT" >> $GITHUB_ENV
echo "Snapshot block height: $SNAPSHOT_BLOCK_HEIGHT"
APPLIED_URL=https://api.testnet.elys.network/cosmos/upgrade/v1beta1/applied_plan/${LAST_TAG}
APPLIED_URL=https://api.testnet.elys.network/cosmos/upgrade/v1beta1/applied_plan/${LATEST_TAG}
curl -L $APPLIED_URL -o /tmp/applied.json
echo "Applied.json downloaded to check snapshot version."
Expand Down
8 changes: 8 additions & 0 deletions x/estaking/keeper/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ func (k Keeper) Rewards(goCtx context.Context, req *types.QueryRewardsRequest) (
if err != nil {
return false
}
// check if the delegation is valid
startingInfo, err := k.distrKeeper.GetDelegatorStartingInfo(ctx, sdk.ValAddress(valAddr), sdk.AccAddress(delAddr))
if err != nil {
return false
}
if startingInfo.Stake.IsNil() {
return false
}
delReward, err := k.distrKeeper.CalculateDelegationRewards(ctx, val, del, endingPeriod)
if err != nil {
return false
Expand Down
3 changes: 3 additions & 0 deletions x/estaking/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package types

import (
"context"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
assetprofiletypes "github.com/elys-network/elys/x/assetprofile/types"
commitmenttypes "github.com/elys-network/elys/x/commitment/types"
Expand Down Expand Up @@ -39,6 +41,7 @@ type DistrKeeper interface {
WithdrawDelegationRewards(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (sdk.Coins, error)
IncrementValidatorPeriod(ctx context.Context, val stakingtypes.ValidatorI) (uint64, error)
CalculateDelegationRewards(ctx context.Context, val stakingtypes.ValidatorI, del stakingtypes.DelegationI, endingPeriod uint64) (rewards sdk.DecCoins, err error)
GetDelegatorStartingInfo(ctx context.Context, val sdk.ValAddress, del sdk.AccAddress) (period disttypes.DelegatorStartingInfo, err error)
}

// TokenomicsKeeper defines the expected tokenomics keeper used for simulations (noalias)
Expand Down

0 comments on commit 13c05fc

Please sign in to comment.