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

Allow host_connection_id in version metadata to be empty on ChanOpenInit #5533

Merged
merged 63 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
2f33154
remove host connection ID in default metadata
GNaD13 Jan 7, 2024
e535ddb
allow empty host connection id in validateConnectionParams
GNaD13 Jan 7, 2024
670ff0d
add host connection id to the metadata on host open try
GNaD13 Jan 7, 2024
bc119a7
nit
GNaD13 Jan 7, 2024
d0f0831
add test init with empty host connection ID
GNaD13 Jan 7, 2024
a37e7f1
add test host
GNaD13 Jan 7, 2024
0e377ef
correct test
GNaD13 Jan 7, 2024
b9f280b
nit
GNaD13 Jan 7, 2024
c92c59b
lint
Jan 8, 2024
677865d
Merge branch 'main' into dang/host-connection-id
Jan 8, 2024
fc05c68
remove assert
GNaD13 Jan 8, 2024
4280d46
Merge remote-tracking branch 'decent/dang/host-connection-id' into da…
GNaD13 Jan 8, 2024
1162019
TestOnChanOpenInit
GNaD13 Jan 9, 2024
237ade9
OnChanOpenTry
GNaD13 Jan 9, 2024
b53a2ff
TestOnChanUpgradeInit
GNaD13 Jan 9, 2024
0324206
TestOnChanUpgradeTry
GNaD13 Jan 9, 2024
b8e8fe2
TestOnChanUpgradeTry
GNaD13 Jan 9, 2024
a1a5e0f
remove check
GNaD13 Jan 9, 2024
e1d2f77
test
GNaD13 Jan 9, 2024
cbb39da
test
GNaD13 Jan 9, 2024
6d86f85
nit
GNaD13 Jan 9, 2024
840953f
Merge remote-tracking branch 'origin/main' into dang/host-connection-id
GNaD13 Jan 9, 2024
61f3fb5
nit
GNaD13 Jan 10, 2024
e222c4b
add check version
GNaD13 Jan 10, 2024
0b0b7d0
NewDefaultMetadataString
GNaD13 Jan 10, 2024
858954b
e2e
GNaD13 Jan 10, 2024
3b092a6
change func name and var place
GNaD13 Jan 17, 2024
ad3e344
callbacks
GNaD13 Jan 17, 2024
27d488f
revert icatypes.NewDefaultMetadataString
GNaD13 Jan 17, 2024
fd23ea2
add back NewDefaultMetadataString with hostConnectionID
GNaD13 Jan 17, 2024
ef00a21
nit
GNaD13 Jan 17, 2024
9abb309
nit
GNaD13 Jan 17, 2024
e7cce12
Merge remote-tracking branch 'origin/main' into dang/host-connection-id
GNaD13 Jan 18, 2024
5a6a68a
nit
GNaD13 Jan 18, 2024
cebec2b
remove unused code
GNaD13 Jan 18, 2024
56bbbc8
Merge branch 'main' into dang/host-connection-id
GNaD13 Jan 18, 2024
530ecd9
revert
GNaD13 Jan 19, 2024
553dd63
Merge remote-tracking branch 'decent/dang/host-connection-id' into da…
GNaD13 Jan 19, 2024
9ed3d4e
Merge branch 'main' into dang/host-connection-id
GNaD13 Jan 19, 2024
f2e58d9
Merge branch 'main' into dang/host-connection-id
DimitrisJim Jan 25, 2024
fca1943
Merge branch 'main' into dang/host-connection-id
Feb 1, 2024
de2ef57
address self-review comments
Feb 1, 2024
ef661c0
Merge branch 'cosmos:dang/host-connection-id' into dang/host-connecti…
Feb 1, 2024
6af728f
add import back
Feb 1, 2024
2903797
Merge branch 'cosmos:dang/host-connection-id' into dang/host-connecti…
Feb 1, 2024
cfd440a
some more refactoring
Feb 1, 2024
ceb0205
Merge branch 'cosmos:dang/host-connection-id' into dang/host-connecti…
Feb 1, 2024
61b3505
more cleanup
Feb 1, 2024
7cbf91e
Merge branch 'cosmos:dang/host-connection-id' into dang/host-connecti…
Feb 1, 2024
8f381a5
remove unused test
GNaD13 Feb 2, 2024
f9a8e4c
change set version func
GNaD13 Feb 2, 2024
2287133
lint
GNaD13 Feb 2, 2024
fbfbb0f
Merge branch 'main' into dang/host-connection-id
GNaD13 Feb 3, 2024
99b4443
Merge branch 'main' into dang/host-connection-id
GNaD13 Feb 9, 2024
e8501ec
Merge branch 'main' into dang/host-connection-id
GNaD13 Mar 5, 2024
e23cf85
still set host connection ID in our controller implementation
Mar 7, 2024
abcff64
remove empty lines
Mar 7, 2024
5b5b609
remove unnecessary line
Mar 8, 2024
883d795
add changelog
Mar 8, 2024
c2b7850
Merge branch 'main' into dang/host-connection-id
Mar 8, 2024
3606daa
Merge branch 'main' into dang/host-connection-id
Mar 8, 2024
59fdf13
Merge branch 'main' into dang/host-connection-id
Mar 12, 2024
d7cfafd
Merge branch 'main' into dang/host-connection-id
Mar 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() {
func() {},
true,
},
{
"success: empty host connection ID",
func() {
path.EndpointB.ConnectionID = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this test case actually testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is for my old code. I removed it. Thank you sir

},
true,
},
{
"success: previous active channel closed",
func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func (k Keeper) OnChanOpenTry(
return "", err
}

if metadata.HostConnectionId == "" {
metadata.HostConnectionId = connectionHops[0]
}

activeChannelID, found := k.GetActiveChannelID(ctx, connectionHops[0], counterparty.PortId)
if found {
channel, found := k.channelKeeper.GetChannel(ctx, portID, activeChannelID)
Expand Down
GNaD13 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,19 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {
path *ibctesting.Path
chanCap *capabilitytypes.Capability
metadata icatypes.Metadata
version string
)

testCases := []struct {
name string
malleate func()
assert func()
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't add an assert function since you can just check the host_connection_id after every successful handshake anyway.

Copy link
Member

Choose a reason for hiding this comment

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

I see that you removed assert but I don't think you are testing that the output version inside the expPass case. Could you please check that the host_connection_id is correct?

expPass bool
}{
{
"success",
func() {},
func() {},
true,
},
{
Expand All @@ -69,7 +72,9 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {
suite.Require().NoError(err)

suite.openAndCloseChannel(path)
}, true,
},
func() {},
true,
},
{
"success - reopening account with new address",
Expand All @@ -89,7 +94,28 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {
// assert interchain account address mapping was deleted
_, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID)
suite.Require().False(found)
}, true,
},
func() {},
true,
},
{
"success - metadata empty host connection id",
func() {
metadata.HostConnectionId = ""

versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata)
suite.Require().NoError(err)

path.EndpointA.ChannelConfig.Version = string(versionBytes)
},
func() {
var metadataResponse icatypes.Metadata
err := icatypes.ModuleCdc.UnmarshalJSON([]byte(version), &metadataResponse)
suite.Require().NoError(err)

suite.Require().Equal(ibctesting.FirstConnectionID, metadataResponse.HostConnectionId)
},
true,
},
{
"reopening account fails - no existing account",
Expand All @@ -108,7 +134,9 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {

acc := suite.chainB.GetSimApp().AccountKeeper.GetAccount(suite.chainB.GetContext(), sdk.MustAccAddressFromBech32(addr))
suite.chainB.GetSimApp().AccountKeeper.RemoveAccount(suite.chainB.GetContext(), acc)
}, false,
},
func() {},
false,
},
{
"reopening account fails - existing account is not interchain account type",
Expand All @@ -132,7 +160,9 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {

// overwrite existing account with only base account type, not intercahin account type
suite.chainB.GetSimApp().AccountKeeper.SetAccount(suite.chainB.GetContext(), icaAcc.BaseAccount)
}, false,
},
func() {},
false,
},
{
"account already exists",
Expand All @@ -142,6 +172,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {
suite.Require().NoError(err)
suite.Require().True(suite.chainB.GetSimApp().AccountKeeper.HasAccount(suite.chainB.GetContext(), interchainAccAddr))
},
func() {},
false,
},
{
Expand All @@ -163,20 +194,24 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {
channel.Version = string(versionBytes)

path.EndpointB.SetChannel(*channel)
}, false,
},
func() {},
false,
},
{
"invalid order - UNORDERED",
func() {
channel.Ordering = channeltypes.UNORDERED
},
func() {},
false,
},
{
"invalid port ID",
func() {
path.EndpointB.ChannelConfig.PortID = "invalid-port-id" //nolint:goconst
},
func() {},
false,
},
{
Expand All @@ -185,13 +220,15 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {
channel.ConnectionHops = []string{"invalid-connnection-id"}
path.EndpointB.SetChannel(*channel)
},
func() {},
false,
},
{
"invalid metadata bytestring",
func() {
path.EndpointA.ChannelConfig.Version = "invalid-metadata-bytestring"
},
func() {},
false,
},
{
Expand All @@ -204,6 +241,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {

path.EndpointA.ChannelConfig.Version = string(versionBytes)
},
func() {},
false,
},
{
Expand All @@ -216,6 +254,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {

path.EndpointA.ChannelConfig.Version = string(versionBytes)
},
func() {},
false,
},
{
Expand All @@ -228,6 +267,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {

path.EndpointA.ChannelConfig.Version = string(versionBytes)
},
func() {},
false,
},
{
Expand All @@ -240,6 +280,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {

path.EndpointA.ChannelConfig.Version = string(versionBytes)
},
func() {},
false,
},
{
Expand All @@ -252,6 +293,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {

path.EndpointA.ChannelConfig.Version = string(versionBytes)
},
func() {},
false,
},
{
Expand All @@ -261,6 +303,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {
err := suite.chainB.GetSimApp().ScopedICAHostKeeper.ClaimCapability(suite.chainB.GetContext(), chanCap, host.ChannelCapabilityPath(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID))
suite.Require().NoError(err)
},
func() {},
false,
},
{
Expand All @@ -272,7 +315,9 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {

// set the active channelID in state
suite.chainB.GetSimApp().ICAHostKeeper.SetActiveChannelID(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointB.ChannelID)
}, false,
},
func() {},
false,
},
}

Expand Down Expand Up @@ -311,7 +356,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {

tc.malleate() // malleate mutates test data

version, err := suite.chainB.GetSimApp().ICAHostKeeper.OnChanOpenTry(suite.chainB.GetContext(), channel.Ordering, channel.GetConnectionHops(),
version, err = suite.chainB.GetSimApp().ICAHostKeeper.OnChanOpenTry(suite.chainB.GetContext(), channel.Ordering, channel.GetConnectionHops(),
path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, chanCap, channel.Counterparty, path.EndpointA.ChannelConfig.Version,
)

Expand All @@ -327,6 +372,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {
// Check if account is created
interchainAccount := suite.chainB.GetSimApp().AccountKeeper.GetAccount(suite.chainB.GetContext(), interchainAccAddr)
suite.Require().Equal(interchainAccount.GetAddress().String(), storedAddr)
tc.assert()
} else {
suite.Require().Error(err)
suite.Require().Equal("", version)
Expand Down
3 changes: 3 additions & 0 deletions modules/apps/27-interchain-accounts/types/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ func validateConnectionParams(metadata Metadata, controllerConnectionID, hostCon
}

if metadata.HostConnectionId != hostConnectionID {
if metadata.HostConnectionId == "" {
return nil
Copy link
Member

@srdtrk srdtrk Jan 8, 2024

Choose a reason for hiding this comment

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

This is not how we should do it imo. It is possible that we want to add other checks after this in the future. So, the only nil returned should be at the end of the function, not inside this if statement

Copy link
Contributor Author

@GNaD13 GNaD13 Jan 8, 2024

Choose a reason for hiding this comment

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

The reason I added an if statement here to check whether metadata.HostConnectionId is empty or not because I think we still need to keep check and return an error if
metadata.HostConnectionId != hostConnectionID and metadata.HostConnectionId not empty when the controller chain received an OnChanOpenAck package. So that it could check for the handshake. Should we remove this check?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to be a bit carefully with the validation of metadata.HostConnectionId because it will be valid to be empty in ChanOpenInit but it should not be empty anymore in ChanOpenAck, right?

Copy link
Member

Choose a reason for hiding this comment

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

I'd make the following suggestion @GNaD13 :

  1. Revert your changes to validateConnectionParams.
  2. In ChanOpenTry, before sending the metadata to validation, override metadata.HostConnectionId to be connectionHops[0] regardless of whether or not it is filled.
  3. Send to validation after step 2.

Note that this is okay because the host is allowed to propose a new version string in ChanOpenTry. Does this sound good @crodriguezvega?

Copy link
Contributor Author

@GNaD13 GNaD13 Jan 9, 2024

Choose a reason for hiding this comment

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

If so, I think we will also remove the validation in ChanOpenInit and leave the controller chain validation for ChanOpenAck

Copy link
Member

Choose a reason for hiding this comment

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

We can perform the validation if the user provided the version string, but not if we are using the default

}
return errorsmod.Wrapf(connectiontypes.ErrInvalidConnection, "expected %s, got %s", hostConnectionID, metadata.HostConnectionId)
}

Expand Down
Loading