Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check fee module locked and enable fee before refunding all fees #1341

Merged
merged 11 commits into from
May 16, 2022
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