Skip to content

Commit

Permalink
fix: add feeder delegation consent case on ante (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
uhyunpark authored Sep 4, 2024
1 parent 9013285 commit 2ffc67e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
19 changes: 8 additions & 11 deletions app/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
6 changes: 3 additions & 3 deletions x/oracle/keeper/feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions x/oracle/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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())
}

Expand Down

0 comments on commit 2ffc67e

Please sign in to comment.