From cea0dc1c41186a442130bfaa9feb90211e179689 Mon Sep 17 00:00:00 2001 From: romelukaku Date: Sat, 5 Mar 2022 01:51:12 +0700 Subject: [PATCH 1/5] add counterpartyChannelID param to IBCModule OnChanOpenAck() --- modules/core/05-port/types/module.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/core/05-port/types/module.go b/modules/core/05-port/types/module.go index dea418b7250..faa55e457bf 100644 --- a/modules/core/05-port/types/module.go +++ b/modules/core/05-port/types/module.go @@ -52,6 +52,7 @@ type IBCModule interface { portID, channelID string, counterpartyVersion string, + counterpartyChannelID string, ) error // OnChanOpenConfirm will perform custom CONFIRM logic and may error to abort the handshake. From df725de1f6fdc634315e59f92f43f1af6fcbbac5 Mon Sep 17 00:00:00 2001 From: romelukaku Date: Sat, 5 Mar 2022 02:35:51 +0700 Subject: [PATCH 2/5] change ica IBCModules ChannelOpenAck --- modules/apps/27-interchain-accounts/controller/ibc_module.go | 3 ++- .../apps/27-interchain-accounts/controller/ibc_module_test.go | 4 ++-- modules/apps/27-interchain-accounts/host/ibc_module.go | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/ibc_module.go b/modules/apps/27-interchain-accounts/controller/ibc_module.go index 1aa362a4247..b60530c849e 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_module.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_module.go @@ -81,6 +81,7 @@ func (im IBCModule) OnChanOpenAck( portID, channelID string, counterpartyVersion string, + counterpartyChannelID string, ) error { if !im.keeper.IsControllerEnabled(ctx) { return types.ErrControllerSubModuleDisabled @@ -91,7 +92,7 @@ func (im IBCModule) OnChanOpenAck( } // call underlying app's OnChanOpenAck callback with the counterparty app version. - return im.app.OnChanOpenAck(ctx, portID, channelID, counterpartyVersion) + return im.app.OnChanOpenAck(ctx, portID, channelID, counterpartyVersion, counterpartyChannelID) } // OnChanOpenAck implements the IBCModule interface diff --git a/modules/apps/27-interchain-accounts/controller/ibc_module_test.go b/modules/apps/27-interchain-accounts/controller/ibc_module_test.go index f2b5d36ac63..9a58c7e4374 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_module_test.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_module_test.go @@ -285,7 +285,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenAck() { { "ICA auth module callback fails", func() { suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanOpenAck = func( - ctx sdk.Context, portID, channelID string, counterpartyVersion string, + ctx sdk.Context, portID, channelID string, counterpartyVersion string, counterpartyChannelID string, ) error { return fmt.Errorf("mock ica auth fails") } @@ -316,7 +316,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenAck() { cbs, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module) suite.Require().True(ok) - err = cbs.OnChanOpenAck(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.Version) + err = cbs.OnChanOpenAck(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.Version, path.EndpointB.ChannelID) if tc.expPass { suite.Require().NoError(err) diff --git a/modules/apps/27-interchain-accounts/host/ibc_module.go b/modules/apps/27-interchain-accounts/host/ibc_module.go index 630c4d44fc1..da875763a23 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module.go @@ -62,6 +62,7 @@ func (im IBCModule) OnChanOpenAck( portID, channelID string, counterpartyVersion string, + counterpartyChannelID string, ) error { return sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain") } From c6bbc842b1c1b958b8cab0a35bcd1a52d8bf9c15 Mon Sep 17 00:00:00 2001 From: romelukaku Date: Sat, 5 Mar 2022 02:36:23 +0700 Subject: [PATCH 3/5] change transfer IBCModules ChannelOpenAck --- modules/apps/transfer/ibc_module.go | 1 + modules/apps/transfer/ibc_module_test.go | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/apps/transfer/ibc_module.go b/modules/apps/transfer/ibc_module.go index c784a91e933..063938a7737 100644 --- a/modules/apps/transfer/ibc_module.go +++ b/modules/apps/transfer/ibc_module.go @@ -126,6 +126,7 @@ func (im IBCModule) OnChanOpenAck( portID, channelID string, counterpartyVersion string, + _ string, ) error { if counterpartyVersion != types.Version { return sdkerrors.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: %s, expected %s", counterpartyVersion, types.Version) diff --git a/modules/apps/transfer/ibc_module_test.go b/modules/apps/transfer/ibc_module_test.go index b5f834a3a8e..58d2b5f98f8 100644 --- a/modules/apps/transfer/ibc_module_test.go +++ b/modules/apps/transfer/ibc_module_test.go @@ -227,8 +227,7 @@ func (suite *TransferTestSuite) TestOnChanOpenAck() { suite.Require().True(ok) tc.malleate() // explicitly change fields in channel and testChannel - - err = cbs.OnChanOpenAck(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, counterpartyVersion) + err = cbs.OnChanOpenAck(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, counterpartyVersion, path.EndpointA.Counterparty.ChannelID) if tc.expPass { suite.Require().NoError(err) From f08fc7489d5de77d498cb47a69a6ea65f23ec67f Mon Sep 17 00:00:00 2001 From: romelukaku Date: Sat, 5 Mar 2022 02:38:15 +0700 Subject: [PATCH 4/5] change core keeper ChannelOpenAck() --- modules/core/keeper/msg_server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index b19041f636d..5a969088ac2 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -261,7 +261,7 @@ func (k Keeper) ChannelOpenAck(goCtx context.Context, msg *channeltypes.MsgChann } // Perform application logic callback - if err = cbs.OnChanOpenAck(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyVersion); err != nil { + if err = cbs.OnChanOpenAck(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyVersion, msg.CounterpartyChannelId); err != nil { return nil, sdkerrors.Wrap(err, "channel open ack callback failed") } From bec3560e9cb212e350fc6861ea939546510b5351 Mon Sep 17 00:00:00 2001 From: romelukaku Date: Sat, 5 Mar 2022 02:40:19 +0700 Subject: [PATCH 5/5] change testing mock --- testing/mock/ibc_app.go | 1 + testing/mock/ibc_module.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/testing/mock/ibc_app.go b/testing/mock/ibc_app.go index 15f77d02d5a..16e25755c46 100644 --- a/testing/mock/ibc_app.go +++ b/testing/mock/ibc_app.go @@ -41,6 +41,7 @@ type MockIBCApp struct { portID, channelID string, counterpartyVersion string, + counterpartyChannelID string, ) error OnChanOpenConfirm func( diff --git a/testing/mock/ibc_module.go b/testing/mock/ibc_module.go index 1ea1d3850ad..bdf6d2ad230 100644 --- a/testing/mock/ibc_module.go +++ b/testing/mock/ibc_module.go @@ -64,9 +64,9 @@ func (im IBCModule) OnChanOpenTry( } // OnChanOpenAck implements the IBCModule interface. -func (im IBCModule) OnChanOpenAck(ctx sdk.Context, portID string, channelID string, counterpartyVersion string) error { +func (im IBCModule) OnChanOpenAck(ctx sdk.Context, portID string, channelID string, counterpartyVersion string, counterpartyChannelID string) error { if im.IBCApp.OnChanOpenAck != nil { - return im.IBCApp.OnChanOpenAck(ctx, portID, channelID, counterpartyVersion) + return im.IBCApp.OnChanOpenAck(ctx, portID, channelID, counterpartyVersion, counterpartyChannelID) } return nil