Skip to content

Commit

Permalink
check fee module locked and enable fee before refunding all fees (cos…
Browse files Browse the repository at this point in the history
…mos#1341)

## Description


- Add check locked fee module and fee is enabled before refunding all fees

closes: cosmos#1321

---
  • Loading branch information
vuong177 authored May 16, 2022
1 parent 9f70a07 commit 5d83421
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (modules/core/04-channel) [\#1232](https://github.com/cosmos/ibc-go/pull/1232) Updating params on `NewPacketId` and moving to bottom of file.
* (modules/core/04-channel) [\#1279](https://github.com/cosmos/ibc-go/pull/1279) Add selected channel version to MsgChanOpenInitResponse and MsgChanOpenTryResponse. Emit channel version during OpenInit/OpenTry
* (app/29-fee) [\#1305](https://github.com/cosmos/ibc-go/pull/1305) Change version string for fee module to `ics29-1`
* (app/29-fee) [\#1341](https://github.com/cosmos/ibc-go/pull/1341) Check if the fee module is locked and if the fee module is enabled before refunding all fees

### Features

Expand Down
16 changes: 16 additions & 0 deletions modules/apps/29-fee/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ func (im IBCMiddleware) OnChanCloseInit(
return err
}

if !im.keeper.IsFeeEnabled(ctx, portID, channelID) {
return nil
}

if im.keeper.IsLocked(ctx) {
return types.ErrFeeModuleLocked
}

if err := im.keeper.RefundFeesOnChannelClosure(ctx, portID, channelID); err != nil {
return err
}
Expand All @@ -188,6 +196,14 @@ func (im IBCMiddleware) OnChanCloseConfirm(
return err
}

if !im.keeper.IsFeeEnabled(ctx, portID, channelID) {
return nil
}

if im.keeper.IsLocked(ctx) {
return types.ErrFeeModuleLocked
}

if err := im.keeper.RefundFeesOnChannelClosure(ctx, portID, channelID); err != nil {
return err
}
Expand Down
24 changes: 24 additions & 0 deletions modules/apps/29-fee/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,18 @@ func (suite *FeeTestSuite) TestOnChanCloseInit() {
},
false,
},
{
"fee module locked", func() {
lockFeeModule(suite.chainA)
},
false,
},
{
"fee module is not enabled", func() {
suite.chainA.GetSimApp().IBCFeeKeeper.DeleteFeeEnabled(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID)
},
true,
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -432,6 +444,18 @@ func (suite *FeeTestSuite) TestOnChanCloseConfirm() {
},
false,
},
{
"fee module locked", func() {
lockFeeModule(suite.chainA)
},
false,
},
{
"fee module is not enabled", func() {
suite.chainA.GetSimApp().IBCFeeKeeper.DeleteFeeEnabled(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID)
},
true,
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 5d83421

Please sign in to comment.