From 36e664b814ba3da3c5dc53734f3ac08f8bb5aade Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 16 Jan 2024 13:49:24 +0300 Subject: [PATCH 1/4] imp: removed validation check --- .../apps/27-interchain-accounts/host/keeper/handshake.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake.go b/modules/apps/27-interchain-accounts/host/keeper/handshake.go index d687cb61f4f..4274d53c25c 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake.go @@ -53,15 +53,6 @@ func (k Keeper) OnChanOpenTry( if channel.IsOpen() { return "", errorsmod.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID) } - - appVersion, found := k.GetAppVersion(ctx, portID, activeChannelID) - if !found { - panic(fmt.Errorf("active channel mapping set for %s, but channel does not exist in channel store", activeChannelID)) - } - - if !icatypes.IsPreviousMetadataEqual(appVersion, metadata) { - return "", errorsmod.Wrap(icatypes.ErrInvalidVersion, "previous active channel metadata does not match provided version") - } } // On the host chain the capability may only be claimed during the OnChanOpenTry From 67074b3ffb04d9fbee797ac35d18427be0bc4373 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 16 Jan 2024 14:06:45 +0300 Subject: [PATCH 2/4] test: updated icahost test --- .../host/keeper/handshake_test.go | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go b/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go index 4095fd41986..04db2a2b36d 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go @@ -95,6 +95,27 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { suite.Require().False(found) }, true, }, + { + "success - previous metadata is different", + func() { + // create a new channel and set it in state + ch := channeltypes.NewChannel(channeltypes.CLOSED, channeltypes.ORDERED, channeltypes.NewCounterparty(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID), []string{path.EndpointA.ConnectionID}, TestVersion) + suite.chainB.GetSimApp().GetIBCKeeper().ChannelKeeper.SetChannel(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, ch) + + // set the active channelID in state + suite.chainB.GetSimApp().ICAHostKeeper.SetActiveChannelID(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointB.ChannelID) + + // set the previous encoding to be proto3json. And then set the new encoding to be protobuf. + metadata.Encoding = icatypes.EncodingProto3JSON + + versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata) + suite.Require().NoError(err) + + channel.Version = string(versionBytes) + + path.EndpointB.SetChannel(*channel) + }, true, + }, { "reopening account fails - no existing account", func() { @@ -148,27 +169,6 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { }, false, }, - { - "invalid metadata - previous metadata is different", - func() { - // create a new channel and set it in state - ch := channeltypes.NewChannel(channeltypes.CLOSED, channeltypes.ORDERED, channeltypes.NewCounterparty(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID), []string{path.EndpointA.ConnectionID}, TestVersion) - suite.chainB.GetSimApp().GetIBCKeeper().ChannelKeeper.SetChannel(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, ch) - - // set the active channelID in state - suite.chainB.GetSimApp().ICAHostKeeper.SetActiveChannelID(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointB.ChannelID) - - // attempt to downgrade version by reinitializing channel with version 1, but setting channel to version 2 - metadata.Version = "ics27-2" - - versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata) - suite.Require().NoError(err) - - channel.Version = string(versionBytes) - - path.EndpointB.SetChannel(*channel) - }, false, - }, { "invalid port ID", func() { From ef55c7e5421f30d42d0bebf781d8f8ce7e0f3f5a Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 16 Jan 2024 19:08:22 +0300 Subject: [PATCH 3/4] docs: added godocs --- modules/apps/27-interchain-accounts/host/keeper/handshake.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake.go b/modules/apps/27-interchain-accounts/host/keeper/handshake.go index 4274d53c25c..ff38a599937 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake.go @@ -53,6 +53,10 @@ func (k Keeper) OnChanOpenTry( if channel.IsOpen() { return "", errorsmod.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID) } + + // if a channel is being reopened, we allow the controller to propose new fields + // which are not exactly the same as the previous. The provided address will + // be overwritten with the correct one before the metadata is returned. } // On the host chain the capability may only be claimed during the OnChanOpenTry From 198b525a0b870df2c3198e56151266bd334daf3e Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 16 Jan 2024 19:22:29 +0300 Subject: [PATCH 4/4] docs: added godocs --- .../apps/27-interchain-accounts/host/keeper/handshake_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go b/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go index 04db2a2b36d..431e91554f9 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go @@ -105,7 +105,8 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { // set the active channelID in state suite.chainB.GetSimApp().ICAHostKeeper.SetActiveChannelID(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointB.ChannelID) - // set the previous encoding to be proto3json. And then set the new encoding to be protobuf. + // set the previous encoding to be proto3json. + // the new encoding is set to be protobuf in the test below. metadata.Encoding = icatypes.EncodingProto3JSON versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata)