Skip to content

Commit

Permalink
fix: check x/bank send enabled before escrowing fees (backport #2942)…
Browse files Browse the repository at this point in the history
… (#2954)
  • Loading branch information
mergify[bot] authored Dec 19, 2022
1 parent 501d904 commit bf2ad5d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### State Machine Breaking

* (apps/29-fee) [\#2942](https://github.com/cosmos/ibc-go/pull/2942) Check `x/bank` send enabled before escrowing fees.

### Improvements

### Features
Expand Down
8 changes: 8 additions & 0 deletions modules/apps/29-fee/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func (k Keeper) PayPacketFee(goCtx context.Context, msg *types.MsgPayPacketFee)
return nil, err
}

if err := k.bankKeeper.IsSendEnabledCoins(ctx, msg.Fee.Total()...); err != nil {
return nil, err
}

if k.bankKeeper.BlockedAddr(refundAcc) {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to escrow fees", refundAcc)
}
Expand Down Expand Up @@ -133,6 +137,10 @@ func (k Keeper) PayPacketFeeAsync(goCtx context.Context, msg *types.MsgPayPacket
return nil, err
}

if err := k.bankKeeper.IsSendEnabledCoins(ctx, msg.PacketFee.Fee.Total()...); err != nil {
return nil, err
}

if k.bankKeeper.BlockedAddr(refundAcc) {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to escrow fees", refundAcc)
}
Expand Down
45 changes: 45 additions & 0 deletions modules/apps/29-fee/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper_test

import (
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

"github.com/cosmos/ibc-go/v6/modules/apps/29-fee/types"
transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types"
Expand Down Expand Up @@ -197,6 +198,17 @@ func (suite *KeeperTestSuite) TestPayPacketFee() {
},
true,
},
{
"bank send enabled for fee denom",
func() {
suite.chainA.GetSimApp().BankKeeper.SetParams(suite.chainA.GetContext(),
banktypes.Params{
SendEnabled: []*banktypes.SendEnabled{{Denom: sdk.DefaultBondDenom, Enabled: true}},
},
)
},
true,
},
{
"refund account is module account",
func() {
Expand Down Expand Up @@ -244,6 +256,17 @@ func (suite *KeeperTestSuite) TestPayPacketFee() {
},
false,
},
{
"bank send disabled for fee denom",
func() {
suite.chainA.GetSimApp().BankKeeper.SetParams(suite.chainA.GetContext(),
banktypes.Params{
SendEnabled: []*banktypes.SendEnabled{{Denom: sdk.DefaultBondDenom, Enabled: false}},
},
)
},
false,
},
{
"acknowledgement fee balance not found",
func() {
Expand Down Expand Up @@ -347,6 +370,17 @@ func (suite *KeeperTestSuite) TestPayPacketFeeAsync() {
},
true,
},
{
"bank send enabled for fee denom",
func() {
suite.chainA.GetSimApp().BankKeeper.SetParams(suite.chainA.GetContext(),
banktypes.Params{
SendEnabled: []*banktypes.SendEnabled{{Denom: sdk.DefaultBondDenom, Enabled: true}},
},
)
},
true,
},
{
"fee module is locked",
func() {
Expand Down Expand Up @@ -432,6 +466,17 @@ func (suite *KeeperTestSuite) TestPayPacketFeeAsync() {
},
false,
},
{
"bank send disabled for fee denom",
func() {
suite.chainA.GetSimApp().BankKeeper.SetParams(suite.chainA.GetContext(),
banktypes.Params{
SendEnabled: []*banktypes.SendEnabled{{Denom: sdk.DefaultBondDenom, Enabled: false}},
},
)
},
false,
},
{
"acknowledgement fee balance not found",
func() {
Expand Down
1 change: 1 addition & 0 deletions modules/apps/29-fee/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ type BankKeeper interface {
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error
BlockedAddr(sdk.AccAddress) bool
IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) error
}

0 comments on commit bf2ad5d

Please sign in to comment.