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 @@ -55,6 +55,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 fee module locked and enable fee before refunding all fees
seantking marked this conversation as resolved.
Show resolved Hide resolved

### Features

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

if im.keeper.IsLocked(ctx) {
return types.ErrFeeModuleLocked
}
colin-axner marked this conversation as resolved.
Show resolved Hide resolved

if !im.keeper.IsFeeEnabled(ctx, portID, channelID) {
seantking marked this conversation as resolved.
Show resolved Hide resolved
return types.ErrFeeNotEnabled
}
Copy link
Contributor

@colin-axner colin-axner May 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is good for us to think about why we even have "fee enabled channels". This is because non fee enabled channels still use the same middleware stack as fee enabled channels. Thus this check prevents closing of a non fee enabled channel. A key requirement of the middleware design is that middleware not enabled for a specific channel must not affect the behaviour of that channel (this requirement is broken by returning an error).

We should:

  • return nil if the fee is not enabled (exit early)
  • move this check above IsLocked

The reasoning for the second point is that we don't want non fee enabled channels to get affected by the fee module getting locked. A locked fee module should not affect non fee enabled channels

btw, thanks for the contribution! :)

Copy link
Contributor Author

@vuong177 vuong177 May 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks you. It helped me understand. I'll make the changes.


if err := im.keeper.RefundFeesOnChannelClosure(ctx, portID, channelID); err != nil {
return err
}
Expand Down
12 changes: 12 additions & 0 deletions modules/apps/29-fee/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,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)
},
false,
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
},
}

for _, tc := range testCases {
Expand Down