From a3367c3fa63e471a3b0629d6c4c3b37cc78e61ea Mon Sep 17 00:00:00 2001 From: Cosmic Vagabond <121588426+cosmic-vagabond@users.noreply.github.com> Date: Thu, 5 Dec 2024 23:46:14 +0100 Subject: [PATCH 1/3] fix(estaking): prevent reward to invalid delegations --- x/estaking/keeper/query.go | 8 ++++++++ x/estaking/types/expected_keepers.go | 3 +++ 2 files changed, 11 insertions(+) diff --git a/x/estaking/keeper/query.go b/x/estaking/keeper/query.go index a84e5d78b..1f2cde66d 100644 --- a/x/estaking/keeper/query.go +++ b/x/estaking/keeper/query.go @@ -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.Height == 0 { + return false + } delReward, err := k.distrKeeper.CalculateDelegationRewards(ctx, val, del, endingPeriod) if err != nil { return false diff --git a/x/estaking/types/expected_keepers.go b/x/estaking/types/expected_keepers.go index b84e84685..464ff5b29 100644 --- a/x/estaking/types/expected_keepers.go +++ b/x/estaking/types/expected_keepers.go @@ -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" @@ -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) From 2bfdb8fd5fba637e958f69d6168c75e7fe31d339 Mon Sep 17 00:00:00 2001 From: Cosmic Vagabond <121588426+cosmic-vagabond@users.noreply.github.com> Date: Fri, 6 Dec 2024 11:06:59 +0100 Subject: [PATCH 2/3] test(estaking): fix --- x/estaking/keeper/query.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/estaking/keeper/query.go b/x/estaking/keeper/query.go index 1f2cde66d..0a8775734 100644 --- a/x/estaking/keeper/query.go +++ b/x/estaking/keeper/query.go @@ -52,7 +52,7 @@ func (k Keeper) Rewards(goCtx context.Context, req *types.QueryRewardsRequest) ( if err != nil { return false } - if startingInfo.Height == 0 { + if startingInfo.Stake.IsNil() { return false } delReward, err := k.distrKeeper.CalculateDelegationRewards(ctx, val, del, endingPeriod) From bb0a03e9e4c467d12f794e03cb49a6a6f363de43 Mon Sep 17 00:00:00 2001 From: Cosmic Vagabond <121588426+cosmic-vagabond@users.noreply.github.com> Date: Fri, 6 Dec 2024 11:12:08 +0100 Subject: [PATCH 3/3] ci: minor --- .github/workflows/software-upgrade-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/software-upgrade-test.yml b/.github/workflows/software-upgrade-test.yml index be16de527..2fc51b76e 100644 --- a/.github/workflows/software-upgrade-test.yml +++ b/.github/workflows/software-upgrade-test.yml @@ -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."