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(estaking): prevent reward to invalid delegations #1034

Merged
merged 3 commits into from
Dec 6, 2024
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: 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 @@
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
}

Check warning on line 54 in x/estaking/keeper/query.go

View check run for this annotation

Codecov / codecov/patch

x/estaking/keeper/query.go#L53-L54

Added lines #L53 - L54 were not covered by tests
if startingInfo.Stake.IsNil() {
return false
}

Check warning on line 57 in x/estaking/keeper/query.go

View check run for this annotation

Codecov / codecov/patch

x/estaking/keeper/query.go#L56-L57

Added lines #L56 - L57 were not covered by tests
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
Loading