Skip to content

Commit 0f3d20f

Browse files
committed
update connopeninit
Update ConnOpenInit to reflect changes in cosmos/ibc#482. An additional version field is added to the connection handshake and connection open init message to take in an optional field. If this field is empty, then the default versions are used for connection handshake version negotiation.
1 parent d16fe57 commit 0f3d20f

File tree

9 files changed

+189
-98
lines changed

9 files changed

+189
-98
lines changed

proto/ibc/connection/connection.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ message MsgConnectionOpenInit {
1414
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
1515
string connection_id = 2 [(gogoproto.moretags) = "yaml:\"connection_id\""];
1616
Counterparty counterparty = 3 [(gogoproto.nullable) = false];
17-
bytes signer = 4 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
17+
string version = 4;
18+
bytes signer = 5 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
1819
}
1920

2021
// MsgConnectionOpenTry defines a msg sent by a Relayer to try to open a

x/ibc/03-connection/client/cli/tx.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,22 @@ import (
1616
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
1717
)
1818

19+
const (
20+
flagVersionIdentifier = "version-identifier"
21+
flagVersionFeatures = "version-features"
22+
)
23+
1924
// NewConnectionOpenInitCmd defines the command to initialize a connection on
2025
// chain A with a given counterparty chain B
2126
func NewConnectionOpenInitCmd() *cobra.Command {
2227
cmd := &cobra.Command{
2328
Use: "open-init [connection-id] [client-id] [counterparty-connection-id] [counterparty-client-id] [path/to/counterparty_prefix.json]",
2429
Short: "Initialize connection on chain A",
25-
Long: "Initialize a connection on chain A with a given counterparty chain B",
30+
Long: `Initialize a connection on chain A with a given counterparty chain B.
31+
- 'version-identifier' flag can be a single pre-selected version identifier to be used in the handshake.
32+
- 'version-features' flag can be a list of features separated by commas to accompany the version identifier.`,
2633
Example: fmt.Sprintf(
27-
"%s tx %s %s open-init [connection-id] [client-id] [counterparty-connection-id] [counterparty-client-id] [path/to/counterparty_prefix.json]",
34+
"%s tx %s %s open-init [connection-id] [client-id] [counterparty-connection-id] [counterparty-client-id] [path/to/counterparty_prefix.json] --version-identifier=\"1.0\" --version-features=\"ORDER_UNORDERED\"",
2835
version.AppName, host.ModuleName, types.SubModuleName,
2936
),
3037
Args: cobra.ExactArgs(5),
@@ -45,9 +52,24 @@ func NewConnectionOpenInitCmd() *cobra.Command {
4552
return err
4653
}
4754

55+
var encodedVersion string
56+
versionIdentifier, _ := cmd.Flags().GetString(flagVersionIdentifier)
57+
58+
if versionIdentifier != "" {
59+
var features []string
60+
61+
versionFeatures, _ := cmd.Flags().GetString(flagVersionFeatures)
62+
if versionFeatures != "" {
63+
features = strings.Split(versionFeatures, ",")
64+
}
65+
66+
version := types.NewVersion(versionIdentifier, features)
67+
encodedVersion, err = version.Encode()
68+
}
69+
4870
msg := types.NewMsgConnectionOpenInit(
4971
connectionID, clientID, counterpartyConnectionID, counterpartyClientID,
50-
counterpartyPrefix, clientCtx.GetFromAddress(),
72+
counterpartyPrefix, encodedVersion, clientCtx.GetFromAddress(),
5173
)
5274

5375
if err := msg.ValidateBasic(); err != nil {
@@ -58,6 +80,10 @@ func NewConnectionOpenInitCmd() *cobra.Command {
5880
},
5981
}
6082

83+
// NOTE: we should use empty default values since the user may not want to select a version
84+
// at this step in the handshake.
85+
cmd.Flags().String(flagVersionIdentifier, "", "version identifier to be used in the connection handshake version negotiation")
86+
cmd.Flags().String(flagVersionFeatures, "", "version features list separated by commas without spaces. The features must function with the version identifier.")
6187
flags.AddTxFlagsToCmd(cmd)
6288

6389
return cmd

x/ibc/03-connection/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
// HandleMsgConnectionOpenInit defines the sdk.Handler for MsgConnectionOpenInit
1212
func HandleMsgConnectionOpenInit(ctx sdk.Context, k keeper.Keeper, msg *types.MsgConnectionOpenInit) (*sdk.Result, error) {
1313
if err := k.ConnOpenInit(
14-
ctx, msg.ConnectionId, msg.ClientId, msg.Counterparty,
14+
ctx, msg.ConnectionId, msg.ClientId, msg.Counterparty, msg.Version,
1515
); err != nil {
1616
return nil, sdkerrors.Wrap(err, "connection handshake open init failed")
1717
}

x/ibc/03-connection/keeper/handshake.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@ func (k Keeper) ConnOpenInit(
2121
connectionID, // identifier
2222
clientID string,
2323
counterparty types.Counterparty, // desiredCounterpartyConnectionIdentifier, counterpartyPrefix, counterpartyClientIdentifier
24+
version string,
2425
) error {
2526
_, found := k.GetConnection(ctx, connectionID)
2627
if found {
2728
return types.ErrConnectionExists
2829
}
2930

31+
versions := types.GetCompatibleEncodedVersions()
32+
if version != "" {
33+
versions = []string{version}
34+
}
35+
3036
// connection defines chain A's ConnectionEnd
31-
connection := types.NewConnectionEnd(types.INIT, clientID, counterparty, types.GetCompatibleEncodedVersions())
37+
connection := types.NewConnectionEnd(types.INIT, clientID, counterparty, versions)
3238
k.SetConnection(ctx, connectionID, connection)
3339

3440
if err := k.addConnectionToClient(ctx, clientID, connectionID); err != nil {

x/ibc/03-connection/keeper/handshake_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func (suite *KeeperTestSuite) TestConnOpenInit() {
1717
var (
1818
clientA string
1919
clientB string
20+
version string
2021
)
2122

2223
testCases := []struct {
@@ -27,6 +28,10 @@ func (suite *KeeperTestSuite) TestConnOpenInit() {
2728
{"success", func() {
2829
clientA, clientB = suite.coordinator.SetupClients(suite.chainA, suite.chainB, ibctesting.Tendermint)
2930
}, true},
31+
{"success with non empty version", func() {
32+
clientA, clientB = suite.coordinator.SetupClients(suite.chainA, suite.chainB, ibctesting.Tendermint)
33+
version = types.GetCompatibleEncodedVersions()[0]
34+
}, true},
3035
{"connection already exists", func() {
3136
clientA, clientB, _, _ = suite.coordinator.SetupClientConnections(suite.chainA, suite.chainB, ibctesting.Tendermint)
3237
}, false},
@@ -40,14 +45,15 @@ func (suite *KeeperTestSuite) TestConnOpenInit() {
4045
tc := tc
4146
suite.Run(tc.msg, func() {
4247
suite.SetupTest() // reset
48+
version = "" // must be explicitly changed
4349

4450
tc.malleate()
4551

4652
connA := suite.chainA.GetFirstTestConnection(clientA, clientB)
4753
connB := suite.chainB.GetFirstTestConnection(clientB, clientA)
4854
counterparty := types.NewCounterparty(clientB, connB.ID, suite.chainB.GetPrefix())
4955

50-
err := suite.chainA.App.IBCKeeper.ConnectionKeeper.ConnOpenInit(suite.chainA.GetContext(), connA.ID, clientA, counterparty)
56+
err := suite.chainA.App.IBCKeeper.ConnectionKeeper.ConnOpenInit(suite.chainA.GetContext(), connA.ID, clientA, counterparty, version)
5157

5258
if tc.expPass {
5359
suite.Require().NoError(err)

0 commit comments

Comments
 (0)