From 2ffc67e60ea2af1e9f77c893eac741a0b8b15ae0 Mon Sep 17 00:00:00 2001 From: Uhyun Park <96884119+uhyunpark@users.noreply.github.com> Date: Wed, 4 Sep 2024 15:06:45 +0900 Subject: [PATCH] fix: add feeder delegation consent case on ante (#213) --- app/ante/fee.go | 19 ++++++++----------- x/oracle/keeper/feeder.go | 6 +++--- x/oracle/keeper/keeper_test.go | 14 +++++++------- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/app/ante/fee.go b/app/ante/fee.go index d54837ae..9228043c 100644 --- a/app/ante/fee.go +++ b/app/ante/fee.go @@ -226,18 +226,15 @@ func (svcd SettlusValidatorCheckDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx func getValidatorFromOracleMsg(msg sdk.Msg) (sdk.ValAddress, error) { switch msg := msg.(type) { - case *oracletypes.MsgVote: - val, err := sdk.ValAddressFromBech32(msg.Validator) - if err != nil { - return nil, err - } - return val, nil - case *oracletypes.MsgPrevote: - val, err := sdk.ValAddressFromBech32(msg.Validator) - if err != nil { - return nil, err + case *oracletypes.MsgVote, *oracletypes.MsgPrevote, *oracletypes.MsgFeederDelegationConsent: + if validatorMsg, ok := msg.(interface{ GetValidator() string }); ok { + val, err := sdk.ValAddressFromBech32(validatorMsg.GetValidator()) + if err != nil { + return nil, err + } + return val, nil } - return val, nil + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "Cannot extract validator from oracle msg") default: return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "Invalid oracle msg type") } diff --git a/x/oracle/keeper/feeder.go b/x/oracle/keeper/feeder.go index a14274fa..84df59b6 100644 --- a/x/oracle/keeper/feeder.go +++ b/x/oracle/keeper/feeder.go @@ -316,10 +316,10 @@ func (k Keeper) RewardBallotWinners(ctx sdk.Context, validatorClaimMap map[strin probonoRate := receiverVal.GetProbonoRate() probonoContribution := sdk.NewDecCoinsFromCoins(rewardCoins...).MulDecTruncate(probonoRate) totalContribution = totalContribution.Add(probonoContribution...) - + finalReward := sdk.NewDecCoinsFromCoins(rewardCoins...).Sub(probonoContribution) finalRewardCoins, _ := finalReward.TruncateDecimal() - + k.DistributionKeeper.AllocateTokensToValidator(ctx, receiverVal, finalReward) distributedReward = distributedReward.Add(finalRewardCoins...) } else { @@ -334,7 +334,7 @@ func (k Keeper) RewardBallotWinners(ctx sdk.Context, validatorClaimMap map[strin feePool := k.DistributionKeeper.GetFeePool(ctx) feePool.CommunityPool = feePool.CommunityPool.Add(totalContribution...) k.DistributionKeeper.SetFeePool(ctx, feePool) - + totalContributionCoins, _ := totalContribution.TruncateDecimal() // Move both distributed reward and contribution reward to distribution module diff --git a/x/oracle/keeper/keeper_test.go b/x/oracle/keeper/keeper_test.go index 7b43ae1b..2da31f50 100644 --- a/x/oracle/keeper/keeper_test.go +++ b/x/oracle/keeper/keeper_test.go @@ -403,11 +403,11 @@ func (suite *OracleTestSuite) TestKeeper_RewardBallotWinners() { func (suite *OracleTestSuite) TestKeeper_RewardBallotWinners_WithProbono() { tests := []struct { - name string - vcm map[string]types.Claim - totalCoin sdk.Coins - rewardMap map[string]sdk.DecCoins - probonoMap map[int]sdk.Dec + name string + vcm map[string]types.Claim + totalCoin sdk.Coins + rewardMap map[string]sdk.DecCoins + probonoMap map[int]sdk.Dec }{ { name: "Probono validators send rewards to community pool with their probono rate, normal validators get rewards", @@ -515,10 +515,10 @@ func (suite *OracleTestSuite) TestKeeper_RewardBallotWinners_WithProbono() { contribution := tt.rewardMap[validator.GetOperator().String()].MulDec(validator.GetProbonoRate()) probonoRewards = probonoRewards.Add(contribution...) - + rewards := s.app.DistrKeeper.GetValidatorCurrentRewards(s.ctx, validator.GetOperator()) s.Equal(tt.rewardMap[validator.GetOperator().String()].Sub(contribution).AmountOf("asetl"), rewards.Rewards.AmountOf("asetl")) - + s.app.DistrKeeper.DeleteValidatorCurrentRewards(s.ctx, validator.GetOperator()) }