From d749d8ab1ffe4a1125d632619e97e882ee4b6a6a Mon Sep 17 00:00:00 2001 From: vuong Date: Thu, 5 May 2022 10:13:18 +0700 Subject: [PATCH 1/8] check fee module locked and enable fee before refunding all fees --- modules/apps/29-fee/ibc_middleware.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/apps/29-fee/ibc_middleware.go b/modules/apps/29-fee/ibc_middleware.go index 96bb8be4030..06264d210bb 100644 --- a/modules/apps/29-fee/ibc_middleware.go +++ b/modules/apps/29-fee/ibc_middleware.go @@ -168,6 +168,14 @@ func (im IBCMiddleware) OnChanCloseConfirm( return err } + if im.keeper.IsLocked(ctx) { + return types.ErrFeeModuleLocked + } + + if !im.keeper.IsFeeEnabled(ctx, portID, channelID) { + return types.ErrFeeNotEnabled + } + if err := im.keeper.RefundFeesOnChannelClosure(ctx, portID, channelID); err != nil { return err } From 18266004b8e566c8d3bb61e4dde09d666ad81999 Mon Sep 17 00:00:00 2001 From: vuong Date: Mon, 9 May 2022 03:17:55 +0700 Subject: [PATCH 2/8] add test in TestOnChanCloseConfirm --- modules/apps/29-fee/ibc_middleware_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/apps/29-fee/ibc_middleware_test.go b/modules/apps/29-fee/ibc_middleware_test.go index 8c76720ad3e..d3934a0330f 100644 --- a/modules/apps/29-fee/ibc_middleware_test.go +++ b/modules/apps/29-fee/ibc_middleware_test.go @@ -404,6 +404,18 @@ func (suite *FeeTestSuite) TestOnChanCloseConfirm() { }, false, }, + { + "Fee module locked", func() { + lockFeeModule(suite.chainA) + }, + false, + }, + { + "Fee module not enable", func() { + suite.chainA.GetSimApp().IBCFeeKeeper.DeleteFeeEnabled(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID) + }, + false, + }, } for _, tc := range testCases { From acbdf88d46dc473a01d49c6514239520255629cf Mon Sep 17 00:00:00 2001 From: vuong <56973102+vuong177@users.noreply.github.com> Date: Mon, 9 May 2022 22:47:37 +0700 Subject: [PATCH 3/8] Update modules/apps/29-fee/ibc_middleware_test.go Co-authored-by: Sean King --- modules/apps/29-fee/ibc_middleware_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/29-fee/ibc_middleware_test.go b/modules/apps/29-fee/ibc_middleware_test.go index d3934a0330f..784b9afdd58 100644 --- a/modules/apps/29-fee/ibc_middleware_test.go +++ b/modules/apps/29-fee/ibc_middleware_test.go @@ -411,7 +411,7 @@ func (suite *FeeTestSuite) TestOnChanCloseConfirm() { false, }, { - "Fee module not enable", func() { + "fee module is not enabled", func() { suite.chainA.GetSimApp().IBCFeeKeeper.DeleteFeeEnabled(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID) }, false, From 312f309ef101aca32b2c24ab415636179addceb6 Mon Sep 17 00:00:00 2001 From: vuong Date: Mon, 9 May 2022 22:52:56 +0700 Subject: [PATCH 4/8] update CHANGELOG.MD && nits --- CHANGELOG.md | 1 + modules/apps/29-fee/ibc_middleware_test.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65274b8fa95..c7a14529744 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ### Features diff --git a/modules/apps/29-fee/ibc_middleware_test.go b/modules/apps/29-fee/ibc_middleware_test.go index 784b9afdd58..2d2766216d8 100644 --- a/modules/apps/29-fee/ibc_middleware_test.go +++ b/modules/apps/29-fee/ibc_middleware_test.go @@ -405,7 +405,7 @@ func (suite *FeeTestSuite) TestOnChanCloseConfirm() { false, }, { - "Fee module locked", func() { + "fee module locked", func() { lockFeeModule(suite.chainA) }, false, From ad24d6de86e3257a778ffc6ea322af65a6cc7922 Mon Sep 17 00:00:00 2001 From: vuong <56973102+vuong177@users.noreply.github.com> Date: Tue, 10 May 2022 15:35:41 +0700 Subject: [PATCH 5/8] Update CHANGELOG.md Co-authored-by: Sean King --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7a14529744..38246cec716 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,7 +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 +* (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 From e8431dfe120a03f5315b63a9eb00b3bf24898c33 Mon Sep 17 00:00:00 2001 From: vuong Date: Thu, 12 May 2022 12:53:23 +0700 Subject: [PATCH 6/8] update OnChanCloseConfirm --- modules/apps/29-fee/ibc_middleware.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/apps/29-fee/ibc_middleware.go b/modules/apps/29-fee/ibc_middleware.go index 06264d210bb..bc5827f5e62 100644 --- a/modules/apps/29-fee/ibc_middleware.go +++ b/modules/apps/29-fee/ibc_middleware.go @@ -168,12 +168,12 @@ func (im IBCMiddleware) OnChanCloseConfirm( return err } - if im.keeper.IsLocked(ctx) { - return types.ErrFeeModuleLocked + if !im.keeper.IsFeeEnabled(ctx, portID, channelID) { + return nil } - if !im.keeper.IsFeeEnabled(ctx, portID, channelID) { - return types.ErrFeeNotEnabled + if im.keeper.IsLocked(ctx) { + return types.ErrFeeModuleLocked } if err := im.keeper.RefundFeesOnChannelClosure(ctx, portID, channelID); err != nil { From 3e612257a869071dbb6b8f4f287ba7e5be1c336e Mon Sep 17 00:00:00 2001 From: vuong Date: Sun, 15 May 2022 16:19:33 +0700 Subject: [PATCH 7/8] minor test in TestOnChanCloseConfirm --- modules/apps/29-fee/ibc_middleware_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/29-fee/ibc_middleware_test.go b/modules/apps/29-fee/ibc_middleware_test.go index 2d2766216d8..5ca79656863 100644 --- a/modules/apps/29-fee/ibc_middleware_test.go +++ b/modules/apps/29-fee/ibc_middleware_test.go @@ -414,7 +414,7 @@ func (suite *FeeTestSuite) TestOnChanCloseConfirm() { "fee module is not enabled", func() { suite.chainA.GetSimApp().IBCFeeKeeper.DeleteFeeEnabled(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID) }, - false, + true, }, } From 7e5550491604612c97d8a886fe8ca04ddbe92a0d Mon Sep 17 00:00:00 2001 From: vuong Date: Sun, 15 May 2022 17:32:44 +0700 Subject: [PATCH 8/8] OnChanCloseInit --- modules/apps/29-fee/ibc_middleware.go | 8 ++++++++ modules/apps/29-fee/ibc_middleware_test.go | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/modules/apps/29-fee/ibc_middleware.go b/modules/apps/29-fee/ibc_middleware.go index bc5827f5e62..e801fa77bb1 100644 --- a/modules/apps/29-fee/ibc_middleware.go +++ b/modules/apps/29-fee/ibc_middleware.go @@ -151,6 +151,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 } diff --git a/modules/apps/29-fee/ibc_middleware_test.go b/modules/apps/29-fee/ibc_middleware_test.go index 5ca79656863..6af19f22830 100644 --- a/modules/apps/29-fee/ibc_middleware_test.go +++ b/modules/apps/29-fee/ibc_middleware_test.go @@ -327,6 +327,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 {