diff --git a/proto/ibc/core/connection/v1/connection.proto b/proto/ibc/core/connection/v1/connection.proto index 37c7609c37..0cf4f2092e 100644 --- a/proto/ibc/core/connection/v1/connection.proto +++ b/proto/ibc/core/connection/v1/connection.proto @@ -18,7 +18,7 @@ message ConnectionEnd { string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""]; // IBC version which can be utilised to determine encodings or protocols for // channels or packets utilising this connection - repeated string versions = 2; + repeated Version versions = 2; // current state of the connection end. State state = 3; // counterparty chain associated with this connection. @@ -35,7 +35,7 @@ message IdentifiedConnection { string client_id = 2 [(gogoproto.moretags) = "yaml:\"client_id\""]; // IBC version which can be utilised to determine encodings or protocols for // channels or packets utilising this connection - repeated string versions = 3; + repeated Version versions = 3; // current state of the connection end. State state = 4; // counterparty chain associated with this connection. diff --git a/proto/ibc/core/connection/v1/tx.proto b/proto/ibc/core/connection/v1/tx.proto index 86f87b53e7..8de521886b 100644 --- a/proto/ibc/core/connection/v1/tx.proto +++ b/proto/ibc/core/connection/v1/tx.proto @@ -32,7 +32,7 @@ message MsgConnectionOpenInit { string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""]; string connection_id = 2 [(gogoproto.moretags) = "yaml:\"connection_id\""]; Counterparty counterparty = 3 [(gogoproto.nullable) = false]; - string version = 4; + Version version = 4; string signer = 5; } @@ -50,7 +50,7 @@ message MsgConnectionOpenTry { string counterparty_chosen_connection_id = 3 [(gogoproto.moretags) = "yaml:\"counterparty_chosen_connection_id\""]; google.protobuf.Any client_state = 4 [(gogoproto.moretags) = "yaml:\"client_state\""]; Counterparty counterparty = 5 [(gogoproto.nullable) = false]; - repeated string counterparty_versions = 6 [(gogoproto.moretags) = "yaml:\"counterparty_versions\""]; + repeated Version counterparty_versions = 6 [(gogoproto.moretags) = "yaml:\"counterparty_versions\""]; ibc.core.client.v1.Height proof_height = 7 [(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false]; // proof of the initialization the connection on Chain A: `UNITIALIZED -> @@ -76,7 +76,7 @@ message MsgConnectionOpenAck { string connection_id = 1 [(gogoproto.moretags) = "yaml:\"connection_id\""]; string counterparty_connection_id = 2 [(gogoproto.moretags) = "yaml:\"counterparty_connection_id\""]; - string version = 3; + Version version = 3; google.protobuf.Any client_state = 4 [(gogoproto.moretags) = "yaml:\"client_state\""]; ibc.core.client.v1.Height proof_height = 5 [(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false]; diff --git a/x/ibc/core/03-connection/client/cli/tx.go b/x/ibc/core/03-connection/client/cli/tx.go index e67ae94f42..9526c5f8c0 100644 --- a/x/ibc/core/03-connection/client/cli/tx.go +++ b/x/ibc/core/03-connection/client/cli/tx.go @@ -2,13 +2,16 @@ package cli import ( "fmt" + "io/ioutil" "strings" + "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/version" clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types" "github.com/cosmos/cosmos-sdk/x/ibc/core/03-connection/client/utils" @@ -53,7 +56,7 @@ func NewConnectionOpenInitCmd() *cobra.Command { return err } - var encodedVersion string + var version *types.Version versionIdentifier, _ := cmd.Flags().GetString(flagVersionIdentifier) if versionIdentifier != "" { @@ -64,16 +67,12 @@ func NewConnectionOpenInitCmd() *cobra.Command { features = strings.Split(versionFeatures, ",") } - version := types.NewVersion(versionIdentifier, features) - encodedVersion, err = version.Encode() - if err != nil { - return err - } + version = types.NewVersion(versionIdentifier, features) } msg := types.NewMsgConnectionOpenInit( connectionID, clientID, counterpartyConnectionID, counterpartyClientID, - counterpartyPrefix, encodedVersion, clientCtx.GetFromAddress(), + counterpartyPrefix, version, clientCtx.GetFromAddress(), ) if err := msg.ValidateBasic(); err != nil { @@ -99,9 +98,9 @@ func NewConnectionOpenTryCmd() *cobra.Command { cmd := &cobra.Command{ Use: strings.TrimSpace(`open-try [connection-id] [client-id] [counterparty-connection-id] [counterparty-client-id] [path/to/counterparty_prefix.json] [path/to/client_state.json] -[counterparty-versions] [consensus-height] [proof-height] [path/to/proof_init.json] [path/to/proof_client.json] [path/to/proof_consensus.json]`), +[path/to/counterparty_version1.json,path/to/counterparty_version2.json...] [consensus-height] [proof-height] [path/to/proof_init.json] [path/to/proof_client.json] [path/to/proof_consensus.json]`), Short: "initiate connection handshake between two chains", - Long: "Initialize a connection on chain A with a given counterparty chain B", + Long: "Initialize a connection on chain A with a given counterparty chain B. Provide counterparty versions separated by commas", Example: fmt.Sprintf( `%s tx %s %s open-try connection-id] [client-id] \ [counterparty-connection-id] [counterparty-client-id] [path/to/counterparty_prefix.json] [path/to/client_state.json]\ @@ -132,8 +131,28 @@ func NewConnectionOpenTryCmd() *cobra.Command { return err } - // TODO: parse strings? - counterpartyVersions := args[6] + cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry) + + versionsStr := strings.Split(args[6], ",") + counterpartyVersions := make([]*types.Version, len(versionsStr)) + + for _, ver := range versionsStr { + + // attempt to unmarshal version + version := &types.Version{} + if err := cdc.UnmarshalJSON([]byte(ver), version); err != nil { + + // check for file path if JSON input is not provided + contents, err := ioutil.ReadFile(ver) + if err != nil { + return errors.Wrap(err, "neither JSON input nor path to .json file for version were provided") + } + + if err := cdc.UnmarshalJSON(contents, version); err != nil { + return errors.Wrap(err, "error unmarshalling version file") + } + } + } consensusHeight, err := clienttypes.ParseHeight(args[7]) if err != nil { @@ -161,7 +180,7 @@ func NewConnectionOpenTryCmd() *cobra.Command { msg := types.NewMsgConnectionOpenTry( connectionID, provedID, clientID, counterpartyConnectionID, counterpartyClientID, - counterpartyClient, counterpartyPrefix, []string{counterpartyVersions}, + counterpartyClient, counterpartyPrefix, counterpartyVersions, proofInit, proofClient, proofConsensus, proofHeight, consensusHeight, clientCtx.GetFromAddress(), ) @@ -233,7 +252,22 @@ func NewConnectionOpenAckCmd() *cobra.Command { return err } - version := args[8] + cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry) + + // attempt to unmarshal version + version := &types.Version{} + if err := cdc.UnmarshalJSON([]byte(args[8]), version); err != nil { + + // check for file path if JSON input is not provided + contents, err := ioutil.ReadFile(args[8]) + if err != nil { + return errors.Wrap(err, "neither JSON input nor path to .json file for version were provided") + } + + if err := cdc.UnmarshalJSON(contents, version); err != nil { + return errors.Wrap(err, "error unmarshalling version file") + } + } msg := types.NewMsgConnectionOpenAck( connectionID, counterpartyConnectionID, counterpartyClient, proofTry, proofClient, proofConsensus, proofHeight, diff --git a/x/ibc/core/03-connection/keeper/grpc_query_test.go b/x/ibc/core/03-connection/keeper/grpc_query_test.go index 69443a1c03..5a8122e279 100644 --- a/x/ibc/core/03-connection/keeper/grpc_query_test.go +++ b/x/ibc/core/03-connection/keeper/grpc_query_test.go @@ -52,7 +52,7 @@ func (suite *KeeperTestSuite) TestQueryConnection() { connB := suite.chainB.GetFirstTestConnection(clientB, clientA) counterparty := types.NewCounterparty(clientB, connB.ID, suite.chainB.GetPrefix()) - expConnection = types.NewConnectionEnd(types.INIT, clientA, counterparty, types.GetCompatibleEncodedVersions()) + expConnection = types.NewConnectionEnd(types.INIT, clientA, counterparty, types.ExportedVersionsToProto(types.GetCompatibleVersions())) suite.chainA.App.IBCKeeper.ConnectionKeeper.SetConnection(suite.chainA.GetContext(), connA.ID, expConnection) req = &types.QueryConnectionRequest{ @@ -121,9 +121,9 @@ func (suite *KeeperTestSuite) TestQueryConnections() { counterparty2 := types.NewCounterparty(clientB, connB1.ID, suite.chainB.GetPrefix()) counterparty3 := types.NewCounterparty(clientB1, connB2.ID, suite.chainB.GetPrefix()) - conn1 := types.NewConnectionEnd(types.OPEN, clientA, counterparty1, types.GetCompatibleEncodedVersions()) - conn2 := types.NewConnectionEnd(types.INIT, clientA, counterparty2, types.GetCompatibleEncodedVersions()) - conn3 := types.NewConnectionEnd(types.OPEN, clientA1, counterparty3, types.GetCompatibleEncodedVersions()) + conn1 := types.NewConnectionEnd(types.OPEN, clientA, counterparty1, types.ExportedVersionsToProto(types.GetCompatibleVersions())) + conn2 := types.NewConnectionEnd(types.INIT, clientA, counterparty2, types.ExportedVersionsToProto(types.GetCompatibleVersions())) + conn3 := types.NewConnectionEnd(types.OPEN, clientA1, counterparty3, types.ExportedVersionsToProto(types.GetCompatibleVersions())) iconn1 := types.NewIdentifiedConnection(connA0.ID, conn1) iconn2 := types.NewIdentifiedConnection(connA1.ID, conn2) diff --git a/x/ibc/core/03-connection/keeper/handshake.go b/x/ibc/core/03-connection/keeper/handshake.go index 56cb9bf362..0fce7d9006 100644 --- a/x/ibc/core/03-connection/keeper/handshake.go +++ b/x/ibc/core/03-connection/keeper/handshake.go @@ -3,6 +3,8 @@ package keeper import ( "bytes" + "github.com/gogo/protobuf/proto" + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -20,24 +22,24 @@ func (k Keeper) ConnOpenInit( connectionID, // identifier clientID string, counterparty types.Counterparty, // desiredCounterpartyConnectionIdentifier, counterpartyPrefix, counterpartyClientIdentifier - version string, + version *types.Version, ) error { _, found := k.GetConnection(ctx, connectionID) if found { return sdkerrors.Wrap(types.ErrConnectionExists, connectionID) } - versions := types.GetCompatibleEncodedVersions() - if version != "" { + versions := types.GetCompatibleVersions() + if version != nil { if !types.IsSupportedVersion(version) { return sdkerrors.Wrap(types.ErrInvalidVersion, "version is not supported") } - versions = []string{version} + versions = []exported.Version{version} } // connection defines chain A's ConnectionEnd - connection := types.NewConnectionEnd(types.INIT, clientID, counterparty, versions) + connection := types.NewConnectionEnd(types.INIT, clientID, counterparty, types.ExportedVersionsToProto(versions)) k.SetConnection(ctx, connectionID, connection) if err := k.addConnectionToClient(ctx, clientID, connectionID); err != nil { @@ -66,7 +68,7 @@ func (k Keeper) ConnOpenTry( counterparty types.Counterparty, // counterpartyConnectionIdentifier, counterpartyPrefix and counterpartyClientIdentifier clientID string, // clientID of chainA clientState exported.ClientState, // clientState that chainA has for chainB - counterpartyVersions []string, // supported versions of chain A + counterpartyVersions []exported.Version, // supported versions of chain A proofInit []byte, // proof that chainA stored connectionEnd in state (on ConnOpenInit) proofClient []byte, // proof that chainA stored a light client of chainB proofConsensus []byte, // proof that chainA stored chainB's consensus state at consensus height @@ -105,7 +107,7 @@ func (k Keeper) ConnOpenTry( // NOTE: chain A's counterparty is chain B (i.e where this code is executed) prefix := k.GetCommitmentPrefix() expectedCounterparty := types.NewCounterparty(clientID, counterpartyChosenConnectionID, commitmenttypes.NewMerklePrefix(prefix.Bytes())) - expectedConnection := types.NewConnectionEnd(types.INIT, counterparty.ClientId, expectedCounterparty, counterpartyVersions) + expectedConnection := types.NewConnectionEnd(types.INIT, counterparty.ClientId, expectedCounterparty, types.ExportedVersionsToProto(counterpartyVersions)) // If connection already exists for desiredConnectionID, ensure that the existing connection's // counterparty is chainA and connection is on INIT stage. @@ -120,9 +122,9 @@ func (k Keeper) ConnOpenTry( return sdkerrors.Wrap(types.ErrInvalidConnection, "cannot relay connection attempt") } - supportedVersions := types.GetCompatibleEncodedVersions() + supportedVersions := types.GetCompatibleVersions() if len(previousConnection.Versions) != 0 { - supportedVersions = previousConnection.Versions + supportedVersions = previousConnection.GetVersions() } // chain B picks a version from Chain A's available versions that is compatible @@ -134,7 +136,7 @@ func (k Keeper) ConnOpenTry( } // connection defines chain B's ConnectionEnd - connection := types.NewConnectionEnd(types.TRYOPEN, clientID, counterparty, []string{version}) + connection := types.NewConnectionEnd(types.TRYOPEN, clientID, counterparty, []*types.Version{version}) // Check that ChainA committed expectedConnectionEnd to its state if err := k.VerifyConnectionState( @@ -179,7 +181,7 @@ func (k Keeper) ConnOpenAck( ctx sdk.Context, connectionID string, clientState exported.ClientState, // client state for chainA on chainB - encodedVersion, // version that ChainB chose in ConnOpenTry + version *types.Version, // version that ChainB chose in ConnOpenTry counterpartyConnectionID string, proofTry []byte, // proof that connectionEnd was added to ChainB state in ConnOpenTry proofClient []byte, // proof of client state on chainB for chainA @@ -222,18 +224,18 @@ func (k Keeper) ConnOpenAck( ) // if the connection is INIT then the provided version must be supproted - case connection.State == types.INIT && !types.IsSupportedVersion(encodedVersion): + case connection.State == types.INIT && !types.IsSupportedVersion(version): return sdkerrors.Wrapf( types.ErrInvalidConnectionState, - "connection state is in INIT but the provided encoded version is not supported %s", encodedVersion, + "connection state is in INIT but the provided version is not supported %s", version, ) - // if the connection is in TRYOPEN then the encoded version must be the only set version in the + // if the connection is in TRYOPEN then the version must be the only set version in the // retreived connection state. - case connection.State == types.TRYOPEN && (len(connection.Versions) != 1 || connection.Versions[0] != encodedVersion): + case connection.State == types.TRYOPEN && (len(connection.Versions) != 1 || !proto.Equal(connection.Versions[0], version)): return sdkerrors.Wrapf( types.ErrInvalidConnectionState, - "connection state is in TRYOPEN but the provided encoded version (%s) is not set in the previous connection %s", encodedVersion, connection, + "connection state is in TRYOPEN but the provided version (%s) is not set in the previous connection versions %s", version, connection.Versions, ) } @@ -250,7 +252,7 @@ func (k Keeper) ConnOpenAck( prefix := k.GetCommitmentPrefix() expectedCounterparty := types.NewCounterparty(connection.ClientId, connectionID, commitmenttypes.NewMerklePrefix(prefix.Bytes())) - expectedConnection := types.NewConnectionEnd(types.TRYOPEN, connection.Counterparty.ClientId, expectedCounterparty, []string{encodedVersion}) + expectedConnection := types.NewConnectionEnd(types.TRYOPEN, connection.Counterparty.ClientId, expectedCounterparty, []*types.Version{version}) // Ensure that ChainB stored expected connectionEnd in its state during ConnOpenTry if err := k.VerifyConnectionState( @@ -280,7 +282,7 @@ func (k Keeper) ConnOpenAck( // Update connection state to Open connection.State = types.OPEN - connection.Versions = []string{encodedVersion} + connection.Versions = []*types.Version{version} connection.Counterparty.ConnectionId = counterpartyConnectionID k.SetConnection(ctx, connectionID, connection) return nil diff --git a/x/ibc/core/03-connection/keeper/handshake_test.go b/x/ibc/core/03-connection/keeper/handshake_test.go index 117965e6da..b677b23520 100644 --- a/x/ibc/core/03-connection/keeper/handshake_test.go +++ b/x/ibc/core/03-connection/keeper/handshake_test.go @@ -17,7 +17,7 @@ func (suite *KeeperTestSuite) TestConnOpenInit() { var ( clientA string clientB string - version string + version *types.Version emptyConnBID bool ) @@ -35,14 +35,14 @@ func (suite *KeeperTestSuite) TestConnOpenInit() { }, true}, {"success with non empty version", func() { clientA, clientB = suite.coordinator.SetupClients(suite.chainA, suite.chainB, ibctesting.Tendermint) - version = types.GetCompatibleEncodedVersions()[0] + version = types.ExportedVersionsToProto(types.GetCompatibleVersions())[0] }, true}, {"connection already exists", func() { clientA, clientB, _, _ = suite.coordinator.SetupClientConnections(suite.chainA, suite.chainB, ibctesting.Tendermint) }, false}, {"invalid version", func() { clientA, clientB = suite.coordinator.SetupClients(suite.chainA, suite.chainB, ibctesting.Tendermint) - version = "bad version" + version = &types.Version{} }, false}, {"couldn't add connection to client", func() { // swap client identifiers to result in client that does not exist @@ -55,7 +55,7 @@ func (suite *KeeperTestSuite) TestConnOpenInit() { suite.Run(tc.msg, func() { suite.SetupTest() // reset emptyConnBID = false // must be explicitly changed - version = "" // must be explicitly changed + version = nil // must be explicitly changed tc.malleate() @@ -83,7 +83,7 @@ func (suite *KeeperTestSuite) TestConnOpenTry() { var ( clientA string clientB string - versions []string + versions []exported.Version consensusHeight exported.Height counterpartyClient exported.ClientState ) @@ -198,9 +198,8 @@ func (suite *KeeperTestSuite) TestConnOpenTry() { // retrieve client state of chainA to pass as counterpartyClient counterpartyClient = suite.chainA.GetClientState(clientA) - version, err := types.NewVersion("0.0", nil).Encode() - suite.Require().NoError(err) - versions = []string{version} + version := types.NewVersion("0.0", nil) + versions = []exported.Version{version} }, false}, {"connection state verification failed", func() { clientA, clientB = suite.coordinator.SetupClients(suite.chainA, suite.chainB, ibctesting.Tendermint) @@ -274,7 +273,7 @@ func (suite *KeeperTestSuite) TestConnOpenTry() { suite.Require().True(found) connection.State = types.INIT - connection.Versions = []string{"invalid version"} + connection.Versions = []*types.Version{&types.Version{}} suite.chainB.App.IBCKeeper.ConnectionKeeper.SetConnection(suite.chainB.GetContext(), connB.ID, connection) @@ -290,9 +289,9 @@ func (suite *KeeperTestSuite) TestConnOpenTry() { tc := tc suite.Run(tc.msg, func() { - suite.SetupTest() // reset - consensusHeight = clienttypes.ZeroHeight() // must be explicitly changed in malleate - versions = types.GetCompatibleEncodedVersions() // must be explicitly changed in malleate + suite.SetupTest() // reset + consensusHeight = clienttypes.ZeroHeight() // must be explicitly changed in malleate + versions = types.GetCompatibleVersions() // must be explicitly changed in malleate tc.malleate() @@ -344,7 +343,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { clientB string counterpartyConnectionID string consensusHeight exported.Height - version string + version *types.Version counterpartyClient exported.ClientState ) @@ -533,7 +532,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { err = suite.coordinator.ConnOpenTry(suite.chainB, suite.chainA, connB, connA) suite.Require().NoError(err) - version = "2.0" + version = types.NewVersion("2.0", nil) }, false}, {"connection is in TRYOPEN but the set version in the connection is invalid", func() { // chainA is in TRYOPEN, chainB is in TRYOPEN @@ -556,7 +555,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { // retrieve client state of chainB to pass as counterpartyClient counterpartyClient = suite.chainB.GetClientState(clientB) - version = "2.0" + version = types.NewVersion("2.0", nil) }, false}, {"incompatible IBC versions", func() { clientA, clientB = suite.coordinator.SetupClients(suite.chainA, suite.chainB, ibctesting.Tendermint) @@ -570,7 +569,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { suite.Require().NoError(err) // set version to a non-compatible version - version = "(2.0,[])" + version = types.NewVersion("2.0", nil) }, false}, {"empty version", func() { clientA, clientB = suite.coordinator.SetupClients(suite.chainA, suite.chainB, ibctesting.Tendermint) @@ -583,7 +582,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { err = suite.coordinator.ConnOpenTry(suite.chainB, suite.chainA, connB, connA) suite.Require().NoError(err) - version = "" + version = &types.Version{} }, false}, {"feature set verification failed - unsupported feature", func() { clientA, clientB = suite.coordinator.SetupClients(suite.chainA, suite.chainB, ibctesting.Tendermint) @@ -596,8 +595,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { err = suite.coordinator.ConnOpenTry(suite.chainB, suite.chainA, connB, connA) suite.Require().NoError(err) - version, err = types.NewVersion(types.DefaultIBCVersionIdentifier, []string{"ORDER_ORDERED", "ORDER_UNORDERED", "ORDER_DAG"}).Encode() - suite.Require().NoError(err) + version = types.NewVersion(types.DefaultIBCVersionIdentifier, []string{"ORDER_ORDERED", "ORDER_UNORDERED", "ORDER_DAG"}) }, false}, {"self consensus state not found", func() { clientA, clientB = suite.coordinator.SetupClients(suite.chainA, suite.chainB, ibctesting.Tendermint) @@ -663,10 +661,10 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { for _, tc := range testCases { tc := tc suite.Run(tc.msg, func() { - suite.SetupTest() // reset - version = types.GetCompatibleEncodedVersions()[0] // must be explicitly changed in malleate - consensusHeight = clienttypes.ZeroHeight() // must be explicitly changed in malleate - counterpartyConnectionID = "" // must be explicitly changed in malleate + suite.SetupTest() // reset + version = types.ExportedVersionsToProto(types.GetCompatibleVersions())[0] // must be explicitly changed in malleate + consensusHeight = clienttypes.ZeroHeight() // must be explicitly changed in malleate + counterpartyConnectionID = "" // must be explicitly changed in malleate tc.malleate() diff --git a/x/ibc/core/03-connection/keeper/keeper_test.go b/x/ibc/core/03-connection/keeper/keeper_test.go index 85a22d6946..3ae867a5a0 100644 --- a/x/ibc/core/03-connection/keeper/keeper_test.go +++ b/x/ibc/core/03-connection/keeper/keeper_test.go @@ -46,10 +46,11 @@ func (suite *KeeperTestSuite) TestSetAndGetClientConnectionPaths() { _, existed := suite.chainA.App.IBCKeeper.ConnectionKeeper.GetClientConnectionPaths(suite.chainA.GetContext(), clientA) suite.False(existed) - suite.chainA.App.IBCKeeper.ConnectionKeeper.SetClientConnectionPaths(suite.chainA.GetContext(), clientA, types.GetCompatibleEncodedVersions()) + connections := []string{"connectionA", "connectionB"} + suite.chainA.App.IBCKeeper.ConnectionKeeper.SetClientConnectionPaths(suite.chainA.GetContext(), clientA, connections) paths, existed := suite.chainA.App.IBCKeeper.ConnectionKeeper.GetClientConnectionPaths(suite.chainA.GetContext(), clientA) suite.True(existed) - suite.EqualValues(types.GetCompatibleEncodedVersions(), paths) + suite.EqualValues(connections, paths) } // create 2 connections: A0 - B0, A1 - B1 @@ -60,8 +61,8 @@ func (suite KeeperTestSuite) TestGetAllConnections() { counterpartyB0 := types.NewCounterparty(clientB, connB0.ID, suite.chainB.GetPrefix()) // connection B0 counterpartyB1 := types.NewCounterparty(clientB, connB1.ID, suite.chainB.GetPrefix()) // connection B1 - conn1 := types.NewConnectionEnd(types.OPEN, clientA, counterpartyB0, types.GetCompatibleEncodedVersions()) // A0 - B0 - conn2 := types.NewConnectionEnd(types.OPEN, clientA, counterpartyB1, types.GetCompatibleEncodedVersions()) // A1 - B1 + conn1 := types.NewConnectionEnd(types.OPEN, clientA, counterpartyB0, types.ExportedVersionsToProto(types.GetCompatibleVersions())) // A0 - B0 + conn2 := types.NewConnectionEnd(types.OPEN, clientA, counterpartyB1, types.ExportedVersionsToProto(types.GetCompatibleVersions())) // A1 - B1 iconn1 := types.NewIdentifiedConnection(connA0.ID, conn1) iconn2 := types.NewIdentifiedConnection(connA1.ID, conn2) diff --git a/x/ibc/core/03-connection/simulation/decoder_test.go b/x/ibc/core/03-connection/simulation/decoder_test.go index df13c8b5f0..7e36b05a70 100644 --- a/x/ibc/core/03-connection/simulation/decoder_test.go +++ b/x/ibc/core/03-connection/simulation/decoder_test.go @@ -21,7 +21,7 @@ func TestDecodeStore(t *testing.T) { connection := types.ConnectionEnd{ ClientId: "clientidone", - Versions: []string{"1.0"}, + Versions: types.ExportedVersionsToProto(types.GetCompatibleVersions()), } paths := types.ClientPaths{ diff --git a/x/ibc/core/03-connection/types/codec.go b/x/ibc/core/03-connection/types/codec.go index 9caa35332b..c784590d0c 100644 --- a/x/ibc/core/03-connection/types/codec.go +++ b/x/ibc/core/03-connection/types/codec.go @@ -13,19 +13,18 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { registry.RegisterInterface( "ibc.core.connection.v1.ConnectionI", (*exported.ConnectionI)(nil), + &ConnectionEnd{}, ) registry.RegisterInterface( "ibc.core.connection.v1.CounterpartyConnectionI", (*exported.CounterpartyConnectionI)(nil), - ) - registry.RegisterImplementations( - (*exported.ConnectionI)(nil), - &ConnectionEnd{}, - ) - registry.RegisterImplementations( - (*exported.CounterpartyConnectionI)(nil), &Counterparty{}, ) + registry.RegisterInterface( + "ibc.core.connection.v1.Version", + (*exported.Version)(nil), + &Version{}, + ) registry.RegisterImplementations( (*sdk.Msg)(nil), &MsgConnectionOpenInit{}, diff --git a/x/ibc/core/03-connection/types/connection.go b/x/ibc/core/03-connection/types/connection.go index 26fdcb49dd..224998c6a9 100644 --- a/x/ibc/core/03-connection/types/connection.go +++ b/x/ibc/core/03-connection/types/connection.go @@ -10,7 +10,7 @@ import ( var _ exported.ConnectionI = (*ConnectionEnd)(nil) // NewConnectionEnd creates a new ConnectionEnd instance. -func NewConnectionEnd(state State, clientID string, counterparty Counterparty, versions []string) ConnectionEnd { +func NewConnectionEnd(state State, clientID string, counterparty Counterparty, versions []*Version) ConnectionEnd { return ConnectionEnd{ ClientId: clientID, Versions: versions, @@ -35,8 +35,8 @@ func (c ConnectionEnd) GetCounterparty() exported.CounterpartyConnectionI { } // GetVersions implements the Connection interface -func (c ConnectionEnd) GetVersions() []string { - return c.Versions +func (c ConnectionEnd) GetVersions() []exported.Version { + return ProtoVersionsToExported(c.Versions) } // ValidateBasic implements the Connection interface. diff --git a/x/ibc/core/03-connection/types/connection.pb.go b/x/ibc/core/03-connection/types/connection.pb.go index b2b51dd75a..ff0f6db1fa 100644 --- a/x/ibc/core/03-connection/types/connection.pb.go +++ b/x/ibc/core/03-connection/types/connection.pb.go @@ -70,7 +70,7 @@ type ConnectionEnd struct { ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty" yaml:"client_id"` // IBC version which can be utilised to determine encodings or protocols for // channels or packets utilising this connection - Versions []string `protobuf:"bytes,2,rep,name=versions,proto3" json:"versions,omitempty"` + Versions []*Version `protobuf:"bytes,2,rep,name=versions,proto3" json:"versions,omitempty"` // current state of the connection end. State State `protobuf:"varint,3,opt,name=state,proto3,enum=ibc.core.connection.v1.State" json:"state,omitempty"` // counterparty chain associated with this connection. @@ -119,7 +119,7 @@ type IdentifiedConnection struct { ClientId string `protobuf:"bytes,2,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty" yaml:"client_id"` // IBC version which can be utilised to determine encodings or protocols for // channels or packets utilising this connection - Versions []string `protobuf:"bytes,3,rep,name=versions,proto3" json:"versions,omitempty"` + Versions []*Version `protobuf:"bytes,3,rep,name=versions,proto3" json:"versions,omitempty"` // current state of the connection end. State State `protobuf:"varint,4,opt,name=state,proto3,enum=ibc.core.connection.v1.State" json:"state,omitempty"` // counterparty chain associated with this connection. @@ -362,45 +362,46 @@ func init() { } var fileDescriptor_90572467c054e43a = []byte{ - // 608 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x41, 0x6b, 0xdb, 0x4c, - 0x10, 0xd5, 0xca, 0x72, 0x12, 0x6f, 0xe2, 0xef, 0x73, 0x17, 0x53, 0x84, 0x20, 0x92, 0x50, 0x0b, - 0x35, 0x85, 0x48, 0x75, 0x02, 0x3d, 0xa4, 0xf4, 0x10, 0x3b, 0x2a, 0x88, 0xb6, 0xae, 0x51, 0x9c, - 0x42, 0x73, 0x09, 0xb6, 0xb4, 0x49, 0x96, 0xc4, 0x92, 0x91, 0x36, 0x26, 0xfe, 0x07, 0xc1, 0x97, - 0xf6, 0xda, 0x83, 0xa1, 0xd0, 0x3f, 0x13, 0x7a, 0xca, 0xb1, 0x27, 0x53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, 0x33, 0x80, 0xf9, 0x78, 0x03, 0xd0, - 0x73, 0xa8, 0xec, 0xb5, 0x76, 0x5a, 0xe6, 0xe1, 0x7e, 0xc3, 0x6a, 0x58, 0x2d, 0x6b, 0xe7, 0x8d, - 0x75, 0x60, 0xee, 0x1e, 0xee, 0x37, 0xf6, 0x9a, 0x66, 0xdd, 0x7a, 0x65, 0x99, 0xbb, 0x25, 0x4e, - 0x7a, 0x30, 0x1c, 0xa9, 0xc5, 0x1b, 0x00, 0x24, 0x42, 0xc8, 0x78, 0xd1, 0x61, 0x09, 0x48, 0x2b, - 0xc3, 0x91, 0x2a, 0x44, 0x31, 0x92, 0x61, 0x91, 0x55, 0x5a, 0xf6, 0x87, 0x77, 0x4d, 0xb3, 0x51, - 0xe2, 0xa5, 0xd5, 0xe1, 0x48, 0x5d, 0x4e, 0xd2, 0x05, 0x33, 0x2e, 0xe6, 0x18, 0x33, 0x8a, 0x25, - 0xe1, 0xf2, 0xab, 0xcc, 0xd5, 0xf6, 0xaf, 0x26, 0x32, 0xb8, 0x9e, 0xc8, 0xe0, 0xc7, 0x44, 0x06, - 0x9f, 0xa6, 0x32, 0x77, 0x3d, 0x95, 0xb9, 0xef, 0x53, 0x99, 0x3b, 0x78, 0x71, 0x4c, 0xe8, 0xc9, - 0x79, 0x27, 0x1a, 0x9d, 0xe1, 0xf8, 0x61, 0xd7, 0x0f, 0x93, 0x9f, 0x8d, 0xd0, 0x3d, 0x35, 0x2e, - 0x8c, 0xf4, 0x59, 0x7a, 0xb6, 0xb5, 0x91, 0x79, 0xf0, 0xe8, 0xa0, 0x87, 0xc3, 0xce, 0x52, 0xfc, - 0x24, 0x6d, 0xfd, 0x0a, 0x00, 0x00, 0xff, 0xff, 0x61, 0x3b, 0x7e, 0x26, 0x14, 0x05, 0x00, 0x00, + // 617 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xc1, 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xf9, 0x31, 0x93, 0x98, 0xe3, 0xbd, 0x33, 0x4c, 0xce, 0xfb, 0x9d, 0xf0, 0xe9, 0x74, 0xdb, 0x0b, + 0xba, 0x5e, 0x10, 0x7f, 0xb6, 0x02, 0xe7, 0x42, 0xbf, 0xd2, 0x93, 0xc5, 0xf6, 0x62, 0x67, 0x2b, + 0xb5, 0x32, 0xc9, 0xb0, 0x87, 0x82, 0xce, 0x5a, 0xb4, 0xd4, 0x76, 0x7e, 0x05, 0x00, 0x00, 0xff, + 0xff, 0x6d, 0xfb, 0xee, 0xb6, 0x56, 0x05, 0x00, 0x00, } func (m *ConnectionEnd) Marshal() (dAtA []byte, err error) { @@ -440,9 +441,14 @@ func (m *ConnectionEnd) MarshalToSizedBuffer(dAtA []byte) (int, error) { } if len(m.Versions) > 0 { for iNdEx := len(m.Versions) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.Versions[iNdEx]) - copy(dAtA[i:], m.Versions[iNdEx]) - i = encodeVarintConnection(dAtA, i, uint64(len(m.Versions[iNdEx]))) + { + size, err := m.Versions[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintConnection(dAtA, i, uint64(size)) + } i-- dAtA[i] = 0x12 } @@ -494,9 +500,14 @@ func (m *IdentifiedConnection) MarshalToSizedBuffer(dAtA []byte) (int, error) { } if len(m.Versions) > 0 { for iNdEx := len(m.Versions) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.Versions[iNdEx]) - copy(dAtA[i:], m.Versions[iNdEx]) - i = encodeVarintConnection(dAtA, i, uint64(len(m.Versions[iNdEx]))) + { + size, err := m.Versions[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintConnection(dAtA, i, uint64(size)) + } i-- dAtA[i] = 0x1a } @@ -697,8 +708,8 @@ func (m *ConnectionEnd) Size() (n int) { n += 1 + l + sovConnection(uint64(l)) } if len(m.Versions) > 0 { - for _, s := range m.Versions { - l = len(s) + for _, e := range m.Versions { + l = e.Size() n += 1 + l + sovConnection(uint64(l)) } } @@ -725,8 +736,8 @@ func (m *IdentifiedConnection) Size() (n int) { n += 1 + l + sovConnection(uint64(l)) } if len(m.Versions) > 0 { - for _, s := range m.Versions { - l = len(s) + for _, e := range m.Versions { + l = e.Size() n += 1 + l + sovConnection(uint64(l)) } } @@ -881,7 +892,7 @@ func (m *ConnectionEnd) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Versions", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowConnection @@ -891,23 +902,25 @@ func (m *ConnectionEnd) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthConnection } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthConnection } if postIndex > l { return io.ErrUnexpectedEOF } - m.Versions = append(m.Versions, string(dAtA[iNdEx:postIndex])) + m.Versions = append(m.Versions, &Version{}) + if err := m.Versions[len(m.Versions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 3: if wireType != 0 { @@ -1082,7 +1095,7 @@ func (m *IdentifiedConnection) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Versions", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowConnection @@ -1092,23 +1105,25 @@ func (m *IdentifiedConnection) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthConnection } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthConnection } if postIndex > l { return io.ErrUnexpectedEOF } - m.Versions = append(m.Versions, string(dAtA[iNdEx:postIndex])) + m.Versions = append(m.Versions, &Version{}) + if err := m.Versions[len(m.Versions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 4: if wireType != 0 { diff --git a/x/ibc/core/03-connection/types/connection_test.go b/x/ibc/core/03-connection/types/connection_test.go index 6fe486c352..c735841b0e 100644 --- a/x/ibc/core/03-connection/types/connection_test.go +++ b/x/ibc/core/03-connection/types/connection_test.go @@ -28,12 +28,12 @@ func TestConnectionValidateBasic(t *testing.T) { }{ { "valid connection", - types.ConnectionEnd{clientID, []string{ibctesting.ConnectionVersion}, types.INIT, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, + types.ConnectionEnd{clientID, []*types.Version{ibctesting.ConnectionVersion}, types.INIT, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, true, }, { "invalid client id", - types.ConnectionEnd{"(clientID1)", []string{ibctesting.ConnectionVersion}, types.INIT, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, + types.ConnectionEnd{"(clientID1)", []*types.Version{ibctesting.ConnectionVersion}, types.INIT, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, false, }, { @@ -43,12 +43,12 @@ func TestConnectionValidateBasic(t *testing.T) { }, { "invalid version", - types.ConnectionEnd{clientID, []string{"1.0.0"}, types.INIT, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, + types.ConnectionEnd{clientID, []*types.Version{&types.Version{}}, types.INIT, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, false, }, { "invalid counterparty", - types.ConnectionEnd{clientID, []string{ibctesting.ConnectionVersion}, types.INIT, types.Counterparty{clientID2, connectionID2, emptyPrefix}}, + types.ConnectionEnd{clientID, []*types.Version{ibctesting.ConnectionVersion}, types.INIT, types.Counterparty{clientID2, connectionID2, emptyPrefix}}, false, }, } @@ -97,12 +97,12 @@ func TestIdentifiedConnectionValidateBasic(t *testing.T) { }{ { "valid connection", - types.NewIdentifiedConnection(clientID, types.ConnectionEnd{clientID, []string{ibctesting.ConnectionVersion}, types.INIT, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}), + types.NewIdentifiedConnection(clientID, types.ConnectionEnd{clientID, []*types.Version{ibctesting.ConnectionVersion}, types.INIT, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}), true, }, { "invalid connection id", - types.NewIdentifiedConnection("(connectionIDONE)", types.ConnectionEnd{clientID, []string{ibctesting.ConnectionVersion}, types.INIT, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}), + types.NewIdentifiedConnection("(connectionIDONE)", types.ConnectionEnd{clientID, []*types.Version{ibctesting.ConnectionVersion}, types.INIT, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}), false, }, } diff --git a/x/ibc/core/03-connection/types/genesis_test.go b/x/ibc/core/03-connection/types/genesis_test.go index 05f8a88988..8080f49d5c 100644 --- a/x/ibc/core/03-connection/types/genesis_test.go +++ b/x/ibc/core/03-connection/types/genesis_test.go @@ -27,7 +27,7 @@ func TestValidateGenesis(t *testing.T) { name: "valid genesis", genState: types.NewGenesisState( []types.IdentifiedConnection{ - types.NewIdentifiedConnection(connectionID, types.NewConnectionEnd(types.INIT, clientID, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{ibctesting.ConnectionVersion})), + types.NewIdentifiedConnection(connectionID, types.NewConnectionEnd(types.INIT, clientID, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []*types.Version{ibctesting.ConnectionVersion})), }, []types.ConnectionPaths{ {clientID, []string{host.ConnectionPath(connectionID)}}, @@ -39,7 +39,7 @@ func TestValidateGenesis(t *testing.T) { name: "invalid connection", genState: types.NewGenesisState( []types.IdentifiedConnection{ - types.NewIdentifiedConnection(connectionID, types.NewConnectionEnd(types.INIT, "(CLIENTIDONE)", types.Counterparty{clientID, connectionID, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{ibctesting.ConnectionVersion})), + types.NewIdentifiedConnection(connectionID, types.NewConnectionEnd(types.INIT, "(CLIENTIDONE)", types.Counterparty{clientID, connectionID, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []*types.Version{ibctesting.ConnectionVersion})), }, []types.ConnectionPaths{ {clientID, []string{host.ConnectionPath(connectionID)}}, @@ -51,7 +51,7 @@ func TestValidateGenesis(t *testing.T) { name: "invalid client id", genState: types.NewGenesisState( []types.IdentifiedConnection{ - types.NewIdentifiedConnection(connectionID, types.NewConnectionEnd(types.INIT, clientID, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{ibctesting.ConnectionVersion})), + types.NewIdentifiedConnection(connectionID, types.NewConnectionEnd(types.INIT, clientID, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []*types.Version{ibctesting.ConnectionVersion})), }, []types.ConnectionPaths{ {"(CLIENTIDONE)", []string{host.ConnectionPath(connectionID)}}, @@ -63,7 +63,7 @@ func TestValidateGenesis(t *testing.T) { name: "invalid path", genState: types.NewGenesisState( []types.IdentifiedConnection{ - types.NewIdentifiedConnection(connectionID, types.NewConnectionEnd(types.INIT, clientID, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{ibctesting.ConnectionVersion})), + types.NewIdentifiedConnection(connectionID, types.NewConnectionEnd(types.INIT, clientID, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []*types.Version{ibctesting.ConnectionVersion})), }, []types.ConnectionPaths{ {clientID, []string{connectionID}}, diff --git a/x/ibc/core/03-connection/types/msgs.go b/x/ibc/core/03-connection/types/msgs.go index a461dd1cca..6df9512e15 100644 --- a/x/ibc/core/03-connection/types/msgs.go +++ b/x/ibc/core/03-connection/types/msgs.go @@ -17,7 +17,7 @@ var _ sdk.Msg = &MsgConnectionOpenInit{} func NewMsgConnectionOpenInit( connectionID, clientID, counterpartyConnectionID, counterpartyClientID string, counterpartyPrefix commitmenttypes.MerklePrefix, - version string, signer sdk.AccAddress, + version *Version, signer sdk.AccAddress, ) *MsgConnectionOpenInit { counterparty := NewCounterparty(counterpartyClientID, counterpartyConnectionID, counterpartyPrefix) return &MsgConnectionOpenInit{ @@ -47,7 +47,8 @@ func (msg MsgConnectionOpenInit) ValidateBasic() error { if err := host.ClientIdentifierValidator(msg.ClientId); err != nil { return sdkerrors.Wrap(err, "invalid client ID") } - if msg.Version != "" { + // NOTE: Version can be nil on MsgConnectionOpenInit + if msg.Version != nil { if err := ValidateVersion(msg.Version); err != nil { return sdkerrors.Wrap(err, "basic validation of the provided version failed") } @@ -80,7 +81,7 @@ var _ sdk.Msg = &MsgConnectionOpenTry{} func NewMsgConnectionOpenTry( desiredConnectionID, counterpartyChosenConnectionID, clientID, counterpartyConnectionID, counterpartyClientID string, counterpartyClient exported.ClientState, - counterpartyPrefix commitmenttypes.MerklePrefix, counterpartyVersions []string, + counterpartyPrefix commitmenttypes.MerklePrefix, counterpartyVersions []*Version, proofInit, proofClient, proofConsensus []byte, proofHeight, consensusHeight clienttypes.Height, signer sdk.AccAddress, ) *MsgConnectionOpenTry { @@ -195,7 +196,8 @@ var _ sdk.Msg = &MsgConnectionOpenAck{} func NewMsgConnectionOpenAck( connectionID, counterpartyConnectionID string, counterpartyClient exported.ClientState, proofTry, proofClient, proofConsensus []byte, - proofHeight, consensusHeight clienttypes.Height, version string, + proofHeight, consensusHeight clienttypes.Height, + version *Version, signer sdk.AccAddress, ) *MsgConnectionOpenAck { csAny, _ := clienttypes.PackClientState(counterpartyClient) diff --git a/x/ibc/core/03-connection/types/msgs_test.go b/x/ibc/core/03-connection/types/msgs_test.go index 3ccb5114a5..cfb8ce7351 100644 --- a/x/ibc/core/03-connection/types/msgs_test.go +++ b/x/ibc/core/03-connection/types/msgs_test.go @@ -79,7 +79,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenInit() { signer, _ := sdk.AccAddressFromBech32("cosmos1ckgw5d7jfj7wwxjzs9fdrdev9vc8dzcw3n2lht") // empty versions are considered valid, the default compatible versions // will be used in protocol. - version := "" + var version *types.Version var testCases = []struct { name string @@ -91,7 +91,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenInit() { {"invalid counterparty client ID", types.NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "test/conn1", "clienttotest", prefix, version, signer), false}, {"invalid counterparty connection ID", types.NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "connectiontotest", "test/conn1", prefix, version, signer), false}, {"empty counterparty prefix", types.NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "connectiontotest", "clienttotest", emptyPrefix, version, signer), false}, - {"supplied version fails basic validation", types.NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "connectiontotest", "clienttotest", prefix, "bad version", signer), false}, + {"supplied version fails basic validation", types.NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "connectiontotest", "clienttotest", prefix, &types.Version{}, signer), false}, {"empty singer", types.NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "connectiontotest", "clienttotest", prefix, version, nil), false}, {"success", types.NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "connectiontotest", "clienttotest", prefix, version, signer), true}, } @@ -132,24 +132,24 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenTry() { msg *types.MsgConnectionOpenTry expPass bool }{ - {"invalid connection ID", types.NewMsgConnectionOpenTry("test/conn1", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []string{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"invalid connection ID", types.NewMsgConnectionOpenTry("ibcconntest", "test/conn1", "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []string{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"invalid client ID", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "test/iris", "connectiontotest", "clienttotest", clientState, prefix, []string{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"invalid counterparty connection ID", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "ibc/test", "clienttotest", clientState, prefix, []string{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"invalid counterparty client ID", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "test/conn1", clientState, prefix, []string{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"invalid nil counterparty client", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", nil, prefix, []string{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"invalid client unpacking", &types.MsgConnectionOpenTry{"ibcconntest", provedID, "clienttotesta", invalidAny, counterparty, []string{ibctesting.ConnectionVersion}, clientHeight, suite.proof, suite.proof, suite.proof, clientHeight, signer.String()}, false}, - {"counterparty failed Validate", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", invalidClient, prefix, []string{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"empty counterparty prefix", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, emptyPrefix, []string{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"empty counterpartyVersions", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []string{}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"empty proofInit", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []string{ibctesting.ConnectionVersion}, emptyProof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"empty proofClient", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []string{ibctesting.ConnectionVersion}, suite.proof, emptyProof, suite.proof, clientHeight, clientHeight, signer), false}, - {"empty proofConsensus", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []string{ibctesting.ConnectionVersion}, suite.proof, suite.proof, emptyProof, clientHeight, clientHeight, signer), false}, - {"invalid proofHeight", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []string{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clienttypes.ZeroHeight(), clientHeight, signer), false}, - {"invalid consensusHeight", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []string{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clienttypes.ZeroHeight(), signer), false}, - {"empty singer", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []string{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, nil), false}, - {"success", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []string{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), true}, - {"invalid version", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []string{"(invalid version)"}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, + {"invalid connection ID", types.NewMsgConnectionOpenTry("test/conn1", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, + {"invalid connection ID", types.NewMsgConnectionOpenTry("ibcconntest", "test/conn1", "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, + {"invalid client ID", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "test/iris", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, + {"invalid counterparty connection ID", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "ibc/test", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, + {"invalid counterparty client ID", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "test/conn1", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, + {"invalid nil counterparty client", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", nil, prefix, []*types.Version{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, + {"invalid client unpacking", &types.MsgConnectionOpenTry{"ibcconntest", provedID, "clienttotesta", invalidAny, counterparty, []*types.Version{ibctesting.ConnectionVersion}, clientHeight, suite.proof, suite.proof, suite.proof, clientHeight, signer.String()}, false}, + {"counterparty failed Validate", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", invalidClient, prefix, []*types.Version{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, + {"empty counterparty prefix", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, emptyPrefix, []*types.Version{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, + {"empty counterpartyVersions", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, + {"empty proofInit", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, emptyProof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, + {"empty proofClient", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, suite.proof, emptyProof, suite.proof, clientHeight, clientHeight, signer), false}, + {"empty proofConsensus", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, suite.proof, suite.proof, emptyProof, clientHeight, clientHeight, signer), false}, + {"invalid proofHeight", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clienttypes.ZeroHeight(), clientHeight, signer), false}, + {"invalid consensusHeight", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clienttypes.ZeroHeight(), signer), false}, + {"empty singer", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, nil), false}, + {"success", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), true}, + {"invalid version", types.NewMsgConnectionOpenTry("ibcconntest", provedID, "clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{&types.Version{}}, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, } for _, tc := range testCases { @@ -195,7 +195,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenAck() { {"empty proofConsensus", types.NewMsgConnectionOpenAck(connectionID, connectionID, clientState, suite.proof, suite.proof, emptyProof, clientHeight, clientHeight, ibctesting.ConnectionVersion, signer), false}, {"invalid proofHeight", types.NewMsgConnectionOpenAck(connectionID, connectionID, clientState, suite.proof, suite.proof, suite.proof, clienttypes.ZeroHeight(), clientHeight, ibctesting.ConnectionVersion, signer), false}, {"invalid consensusHeight", types.NewMsgConnectionOpenAck(connectionID, connectionID, clientState, suite.proof, suite.proof, suite.proof, clientHeight, clienttypes.ZeroHeight(), ibctesting.ConnectionVersion, signer), false}, - {"invalid version", types.NewMsgConnectionOpenAck(connectionID, connectionID, clientState, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, "", signer), false}, + {"invalid version", types.NewMsgConnectionOpenAck(connectionID, connectionID, clientState, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, &types.Version{}, signer), false}, {"empty signer", types.NewMsgConnectionOpenAck(connectionID, connectionID, clientState, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, ibctesting.ConnectionVersion, nil), false}, {"success", types.NewMsgConnectionOpenAck(connectionID, connectionID, clientState, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, ibctesting.ConnectionVersion, signer), true}, } diff --git a/x/ibc/core/03-connection/types/tx.pb.go b/x/ibc/core/03-connection/types/tx.pb.go index af859b042c..be78639db0 100644 --- a/x/ibc/core/03-connection/types/tx.pb.go +++ b/x/ibc/core/03-connection/types/tx.pb.go @@ -36,7 +36,7 @@ type MsgConnectionOpenInit struct { ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty" yaml:"client_id"` ConnectionId string `protobuf:"bytes,2,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty" yaml:"connection_id"` Counterparty Counterparty `protobuf:"bytes,3,opt,name=counterparty,proto3" json:"counterparty"` - Version string `protobuf:"bytes,4,opt,name=version,proto3" json:"version,omitempty"` + Version *Version `protobuf:"bytes,4,opt,name=version,proto3" json:"version,omitempty"` Signer string `protobuf:"bytes,5,opt,name=signer,proto3" json:"signer,omitempty"` } @@ -118,7 +118,7 @@ type MsgConnectionOpenTry struct { CounterpartyChosenConnectionId string `protobuf:"bytes,3,opt,name=counterparty_chosen_connection_id,json=counterpartyChosenConnectionId,proto3" json:"counterparty_chosen_connection_id,omitempty" yaml:"counterparty_chosen_connection_id"` ClientState *types.Any `protobuf:"bytes,4,opt,name=client_state,json=clientState,proto3" json:"client_state,omitempty" yaml:"client_state"` Counterparty Counterparty `protobuf:"bytes,5,opt,name=counterparty,proto3" json:"counterparty"` - CounterpartyVersions []string `protobuf:"bytes,6,rep,name=counterparty_versions,json=counterpartyVersions,proto3" json:"counterparty_versions,omitempty" yaml:"counterparty_versions"` + CounterpartyVersions []*Version `protobuf:"bytes,6,rep,name=counterparty_versions,json=counterpartyVersions,proto3" json:"counterparty_versions,omitempty" yaml:"counterparty_versions"` ProofHeight types1.Height `protobuf:"bytes,7,opt,name=proof_height,json=proofHeight,proto3" json:"proof_height" yaml:"proof_height"` // proof of the initialization the connection on Chain A: `UNITIALIZED -> // INIT` @@ -206,7 +206,7 @@ var xxx_messageInfo_MsgConnectionOpenTryResponse proto.InternalMessageInfo type MsgConnectionOpenAck struct { ConnectionId string `protobuf:"bytes,1,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty" yaml:"connection_id"` CounterpartyConnectionId string `protobuf:"bytes,2,opt,name=counterparty_connection_id,json=counterpartyConnectionId,proto3" json:"counterparty_connection_id,omitempty" yaml:"counterparty_connection_id"` - Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"` + Version *Version `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"` ClientState *types.Any `protobuf:"bytes,4,opt,name=client_state,json=clientState,proto3" json:"client_state,omitempty" yaml:"client_state"` ProofHeight types1.Height `protobuf:"bytes,5,opt,name=proof_height,json=proofHeight,proto3" json:"proof_height" yaml:"proof_height"` // proof of the initialization the connection on Chain B: `UNITIALIZED -> @@ -384,64 +384,65 @@ func init() { func init() { proto.RegisterFile("ibc/core/connection/v1/tx.proto", fileDescriptor_5d00fde5fc97399e) } var fileDescriptor_5d00fde5fc97399e = []byte{ - // 909 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xbf, 0x93, 0xdb, 0x44, - 0x14, 0xb6, 0xce, 0xf7, 0xc3, 0x5e, 0x1b, 0x92, 0x28, 0xf6, 0x9d, 0x10, 0x41, 0x72, 0x76, 0x60, - 0xb8, 0x22, 0x27, 0xc5, 0x97, 0x30, 0xc3, 0x1c, 0x43, 0x61, 0xbb, 0xe1, 0x8a, 0x00, 0x23, 0x2e, - 0x14, 0x69, 0x3c, 0xb6, 0xbc, 0x96, 0x35, 0x3e, 0xef, 0x7a, 0xb4, 0xb2, 0x13, 0xd1, 0xd2, 0x30, - 0x54, 0x34, 0xf4, 0xf9, 0x0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 0xd7, 0x27, - 0x0e, 0xef, 0xec, 0xe6, 0x89, 0x5b, 0xe6, 0x78, 0x83, 0xc4, 0x9c, 0x4c, 0xc5, 0x9f, 0x05, 0x50, - 0xcf, 0xd7, 0xe8, 0xe3, 0x1b, 0x9f, 0x17, 0x47, 0xc8, 0x5f, 0x6e, 0x1a, 0x91, 0x54, 0xd1, 0x7e, - 0xfe, 0xe6, 0x4a, 0x11, 0xde, 0x5e, 0x29, 0xc2, 0xdf, 0x57, 0x8a, 0xf0, 0xdb, 0xb5, 0x52, 0x78, - 0x7b, 0xad, 0x14, 0xfe, 0xba, 0x56, 0x0a, 0x2f, 0xbe, 0xb2, 0x6c, 0x77, 0x34, 0xeb, 0x6b, 0x26, - 0x99, 0xe8, 0x26, 0xa1, 0x13, 0x42, 0xe3, 0x9f, 0x13, 0x3a, 0x18, 0xeb, 0xaf, 0xf4, 0xf4, 0xed, - 0xfd, 0xf8, 0xc9, 0x09, 0xf7, 0xfc, 0x76, 0xbd, 0x29, 0xa2, 0xfd, 0x7d, 0x36, 0x71, 0x9f, 0xfc, - 0x17, 0x00, 0x00, 0xff, 0xff, 0x93, 0xae, 0x01, 0xa9, 0x2d, 0x0c, 0x00, 0x00, + // 917 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x3f, 0x93, 0xdb, 0x44, + 0x14, 0xb7, 0xce, 0xf7, 0xc7, 0xde, 0x33, 0x24, 0x51, 0xec, 0x3b, 0x21, 0x82, 0xe4, 0xec, 0xc0, + 0x70, 0x45, 0x4e, 0x8a, 0x93, 0x30, 0x03, 0xc7, 0x50, 0xd8, 0x6e, 0xb8, 0x22, 0xc0, 0x88, 0x83, + 0x22, 0x8d, 0xc7, 0x96, 0xd7, 0xb2, 0xc6, 0xe7, 0x5d, 0x8f, 0x56, 0x76, 0x22, 0x5a, 0x1a, 0x86, + 0x8a, 0x8f, 0x90, 0x4f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 0xb9, 0x2e, + 0x1c, 0x4f, 0x7e, 0xb6, 0x09, 0x7a, 0x75, 0xe1, 0xf0, 0xce, 0xd6, 0x2f, 0xdc, 0x34, 0x47, 0x1b, + 0x14, 0xe6, 0xda, 0x54, 0xfc, 0x59, 0x00, 0xb5, 0xfc, 0x1e, 0x7d, 0xbc, 0x76, 0xbe, 0x38, 0x42, + 0xfe, 0x7c, 0xd3, 0x88, 0x64, 0x17, 0xad, 0x1f, 0xde, 0x5c, 0x29, 0xc2, 0xdb, 0x2b, 0x45, 0xf8, + 0xeb, 0x4a, 0x11, 0x7e, 0xbb, 0x56, 0x0a, 0x6f, 0xaf, 0x95, 0xc2, 0x9f, 0xd7, 0x4a, 0xe1, 0xc5, + 0x97, 0x96, 0xed, 0x0e, 0xa7, 0x3d, 0xcd, 0x24, 0x63, 0xdd, 0x24, 0x74, 0x4c, 0x68, 0xfc, 0x39, + 0xa5, 0xfd, 0x91, 0xfe, 0x4a, 0x4f, 0x9f, 0xf7, 0x8f, 0x9f, 0x9e, 0x72, 0x2f, 0x7c, 0xd7, 0x9b, + 0x20, 0xda, 0xdb, 0x67, 0x13, 0xf7, 0xe9, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x86, 0xcf, 0x23, + 0x2c, 0x90, 0x0c, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -667,10 +668,15 @@ func (m *MsgConnectionOpenInit) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x2a } - if len(m.Version) > 0 { - i -= len(m.Version) - copy(dAtA[i:], m.Version) - i = encodeVarintTx(dAtA, i, uint64(len(m.Version))) + if m.Version != nil { + { + size, err := m.Version.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } i-- dAtA[i] = 0x22 } @@ -794,9 +800,14 @@ func (m *MsgConnectionOpenTry) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0x3a if len(m.CounterpartyVersions) > 0 { for iNdEx := len(m.CounterpartyVersions) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.CounterpartyVersions[iNdEx]) - copy(dAtA[i:], m.CounterpartyVersions[iNdEx]) - i = encodeVarintTx(dAtA, i, uint64(len(m.CounterpartyVersions[iNdEx]))) + { + size, err := m.CounterpartyVersions[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } i-- dAtA[i] = 0x32 } @@ -950,10 +961,15 @@ func (m *MsgConnectionOpenAck) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x22 } - if len(m.Version) > 0 { - i -= len(m.Version) - copy(dAtA[i:], m.Version) - i = encodeVarintTx(dAtA, i, uint64(len(m.Version))) + if m.Version != nil { + { + size, err := m.Version.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } i-- dAtA[i] = 0x1a } @@ -1101,8 +1117,8 @@ func (m *MsgConnectionOpenInit) Size() (n int) { } l = m.Counterparty.Size() n += 1 + l + sovTx(uint64(l)) - l = len(m.Version) - if l > 0 { + if m.Version != nil { + l = m.Version.Size() n += 1 + l + sovTx(uint64(l)) } l = len(m.Signer) @@ -1146,8 +1162,8 @@ func (m *MsgConnectionOpenTry) Size() (n int) { l = m.Counterparty.Size() n += 1 + l + sovTx(uint64(l)) if len(m.CounterpartyVersions) > 0 { - for _, s := range m.CounterpartyVersions { - l = len(s) + for _, e := range m.CounterpartyVersions { + l = e.Size() n += 1 + l + sovTx(uint64(l)) } } @@ -1197,8 +1213,8 @@ func (m *MsgConnectionOpenAck) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.Version) - if l > 0 { + if m.Version != nil { + l = m.Version.Size() n += 1 + l + sovTx(uint64(l)) } if m.ClientState != nil { @@ -1405,7 +1421,7 @@ func (m *MsgConnectionOpenInit) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1415,23 +1431,27 @@ func (m *MsgConnectionOpenInit) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - m.Version = string(dAtA[iNdEx:postIndex]) + if m.Version == nil { + m.Version = &Version{} + } + if err := m.Version.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 5: if wireType != 2 { @@ -1740,7 +1760,7 @@ func (m *MsgConnectionOpenTry) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field CounterpartyVersions", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1750,23 +1770,25 @@ func (m *MsgConnectionOpenTry) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - m.CounterpartyVersions = append(m.CounterpartyVersions, string(dAtA[iNdEx:postIndex])) + m.CounterpartyVersions = append(m.CounterpartyVersions, &Version{}) + if err := m.CounterpartyVersions[len(m.CounterpartyVersions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 7: if wireType != 2 { @@ -2142,7 +2164,7 @@ func (m *MsgConnectionOpenAck) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -2152,23 +2174,27 @@ func (m *MsgConnectionOpenAck) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - m.Version = string(dAtA[iNdEx:postIndex]) + if m.Version == nil { + m.Version = &Version{} + } + if err := m.Version.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 4: if wireType != 2 { diff --git a/x/ibc/core/03-connection/types/version.go b/x/ibc/core/03-connection/types/version.go index 7134719485..10c5b33d28 100644 --- a/x/ibc/core/03-connection/types/version.go +++ b/x/ibc/core/03-connection/types/version.go @@ -4,6 +4,7 @@ import ( "strings" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/ibc/core/exported" ) var ( @@ -24,9 +25,11 @@ var ( } ) +var _ exported.Version = &Version{} + // NewVersion returns a new instance of Version. -func NewVersion(identifier string, features []string) Version { - return Version{ +func NewVersion(identifier string, features []string) *Version { + return &Version{ Identifier: identifier, Features: features, } @@ -44,12 +47,10 @@ func (version Version) GetFeatures() []string { // ValidateVersion does basic validation of the version identifier and // features. It unmarshals the version string into a Version object. -func ValidateVersion(encodedVersion string) error { - var version Version - if err := SubModuleCdc.UnmarshalBinaryBare([]byte(encodedVersion), &version); err != nil { - return sdkerrors.Wrapf(err, "failed to unmarshal version string %s", encodedVersion) +func ValidateVersion(version *Version) error { + if version == nil { + return sdkerrors.Wrap(ErrInvalidVersion, "version cannot be nil") } - if strings.TrimSpace(version.Identifier) == "" { return sdkerrors.Wrap(ErrInvalidVersion, "version identifier cannot be blank") } @@ -62,173 +63,11 @@ func ValidateVersion(encodedVersion string) error { return nil } -// Encode proto encodes the version and returns the bytes as a string. -func (version Version) Encode() (string, error) { - encodedVersion, err := SubModuleCdc.MarshalBinaryBare(&version) - if err != nil { - return "", err - } - - return string(encodedVersion), nil -} - -// EncodeVersions iterates over the provided versions and marshals each -// into proto encoded strings. This represents the stored value of the version -// in the connection end as well as the value passed over the wire. -func EncodeVersions(versions []Version) ([]string, error) { - encodedVersions := make([]string, len(versions)) - - for i, version := range versions { - ver, err := version.Encode() - if err != nil { - return nil, err - } - - encodedVersions[i] = ver - } - - return encodedVersions, nil -} - -// DecodeVersion unmarshals a proto encoded version into a Version struct. -func DecodeVersion(encodedVersion string) (Version, error) { - var version Version - if err := SubModuleCdc.UnmarshalBinaryBare([]byte(encodedVersion), &version); err != nil { - return Version{}, sdkerrors.Wrapf(err, "failed to unmarshal version string %s", encodedVersion) - } - - return version, nil -} - -// DecodeVersions returns the supplied list of proto encoded version strings -// as unmarshalled Version structs. -func DecodeVersions(encodedVersions []string) ([]Version, error) { - versions := make([]Version, len(encodedVersions)) - - for i, encodedVersion := range encodedVersions { - version, err := DecodeVersion(encodedVersion) - if err != nil { - return nil, err - } - - versions[i] = version - } - - return versions, nil -} - -// GetCompatibleVersions returns a descending ordered set of compatible IBC -// versions for the caller chain's connection end. The latest supported -// version should be first element and the set should descend to the oldest -// supported version. -func GetCompatibleVersions() []Version { - return []Version{DefaultIBCVersion} -} - -// GetCompatibleEncodedVersions returns the return value from GetCompatibleVersions -// as a proto encoded string. -func GetCompatibleEncodedVersions() []string { - versions, err := EncodeVersions(GetCompatibleVersions()) - if err != nil { - panic(err) // should not occur with properly set hardcoded versions - } - - return versions -} - -// IsSupportedVersion returns true if the proposed version has a matching version -// identifier and its entire feature set is supported or the version identifier -// supports an empty feature set. -func IsSupportedVersion(encodedProposedVersion string) bool { - proposedVersion, err := DecodeVersion(encodedProposedVersion) - if err != nil { - return false - } - - supportedVersion, found := FindSupportedVersion(proposedVersion, GetCompatibleVersions()) - if !found { - return false - } - - if err := supportedVersion.VerifyProposedVersion(proposedVersion); err != nil { - return false - } - - return true -} - -// FindSupportedVersion returns the version with a matching version identifier -// if it exists. The returned boolean is true if the version is found and -// false otherwise. -func FindSupportedVersion(version Version, supportedVersions []Version) (Version, bool) { - for _, supportedVersion := range supportedVersions { - if version.GetIdentifier() == supportedVersion.GetIdentifier() { - return supportedVersion, true - } - } - return Version{}, false -} - -// PickVersion iterates over the descending ordered set of compatible IBC -// versions and selects the first version with a version identifier that is -// supported by the counterparty. The returned version contains a feature -// set with the intersection of the features supported by the source and -// counterparty chains. If the feature set intersection is nil and this is -// not allowed for the chosen version identifier then the search for a -// compatible version continues. This function is called in the ConnOpenTry -// handshake procedure. -// -// CONTRACT: PickVersion must only provide a version that is in the -// intersection of the supported versions and the counterparty versions. -func PickVersion(encodedSupportedVersions, encodedCounterpartyVersions []string) (string, error) { - supportedVersions, err := DecodeVersions(encodedSupportedVersions) - if err != nil { - return "", sdkerrors.Wrapf(err, "failed to unmarshal supported versions (%s) when attempting to pick compatible version", encodedSupportedVersions) - } - - counterpartyVersions, err := DecodeVersions(encodedCounterpartyVersions) - if err != nil { - return "", sdkerrors.Wrapf(err, "failed to unmarshal counterparty versions (%s) when attempting to pick compatible version", encodedCounterpartyVersions) - } - - for _, supportedVersion := range supportedVersions { - // check if the source version is supported by the counterparty - if counterpartyVersion, found := FindSupportedVersion(supportedVersion, counterpartyVersions); found { - - featureSet := GetFeatureSetIntersection(supportedVersion.GetFeatures(), counterpartyVersion.GetFeatures()) - if len(featureSet) == 0 && !allowNilFeatureSet[supportedVersion.GetIdentifier()] { - continue - } - - return NewVersion(supportedVersion.GetIdentifier(), featureSet).Encode() - } - } - - return "", sdkerrors.Wrapf( - ErrVersionNegotiationFailed, - "failed to find a matching counterparty version (%s) from the supported version list (%s)", counterpartyVersions, supportedVersions, - ) -} - -// GetFeatureSetIntersection returns the intersections of source feature set -// and the counterparty feature set. This is done by iterating over all the -// features in the source version and seeing if they exist in the feature -// set for the counterparty version. -func GetFeatureSetIntersection(sourceFeatureSet, counterpartyFeatureSet []string) (featureSet []string) { - for _, feature := range sourceFeatureSet { - if contains(feature, counterpartyFeatureSet) { - featureSet = append(featureSet, feature) - } - } - - return featureSet -} - // VerifyProposedVersion verifies that the entire feature set in the // proposed version is supported by this chain. If the feature set is // empty it verifies that this is allowed for the specified version // identifier. -func (version Version) VerifyProposedVersion(proposedVersion Version) error { +func (version Version) VerifyProposedVersion(proposedVersion exported.Version) error { if proposedVersion.GetIdentifier() != version.GetIdentifier() { return sdkerrors.Wrapf( ErrVersionNegotiationFailed, @@ -257,12 +96,7 @@ func (version Version) VerifyProposedVersion(proposedVersion Version) error { // VerifySupportedFeature takes in a version and feature string and returns // true if the feature is supported by the version and false otherwise. -func VerifySupportedFeature(encodedVersion, feature string) bool { - version, err := DecodeVersion(encodedVersion) - if err != nil { - return false - } - +func VerifySupportedFeature(version exported.Version, feature string) bool { for _, f := range version.GetFeatures() { if f == feature { return true @@ -271,6 +105,108 @@ func VerifySupportedFeature(encodedVersion, feature string) bool { return false } +// GetCompatibleVersions returns a descending ordered set of compatible IBC +// versions for the caller chain's connection end. The latest supported +// version should be first element and the set should descend to the oldest +// supported version. +func GetCompatibleVersions() []exported.Version { + return []exported.Version{DefaultIBCVersion} +} + +// IsSupportedVersion returns true if the proposed version has a matching version +// identifier and its entire feature set is supported or the version identifier +// supports an empty feature set. +func IsSupportedVersion(proposedVersion *Version) bool { + supportedVersion, found := FindSupportedVersion(proposedVersion, GetCompatibleVersions()) + if !found { + return false + } + + if err := supportedVersion.VerifyProposedVersion(proposedVersion); err != nil { + return false + } + + return true +} + +// FindSupportedVersion returns the version with a matching version identifier +// if it exists. The returned boolean is true if the version is found and +// false otherwise. +func FindSupportedVersion(version exported.Version, supportedVersions []exported.Version) (exported.Version, bool) { + for _, supportedVersion := range supportedVersions { + if version.GetIdentifier() == supportedVersion.GetIdentifier() { + return supportedVersion, true + } + } + return nil, false +} + +// PickVersion iterates over the descending ordered set of compatible IBC +// versions and selects the first version with a version identifier that is +// supported by the counterparty. The returned version contains a feature +// set with the intersection of the features supported by the source and +// counterparty chains. If the feature set intersection is nil and this is +// not allowed for the chosen version identifier then the search for a +// compatible version continues. This function is called in the ConnOpenTry +// handshake procedure. +// +// CONTRACT: PickVersion must only provide a version that is in the +// intersection of the supported versions and the counterparty versions. +func PickVersion(supportedVersions, counterpartyVersions []exported.Version) (*Version, error) { + for _, supportedVersion := range supportedVersions { + // check if the source version is supported by the counterparty + if counterpartyVersion, found := FindSupportedVersion(supportedVersion, counterpartyVersions); found { + featureSet := GetFeatureSetIntersection(supportedVersion.GetFeatures(), counterpartyVersion.GetFeatures()) + if len(featureSet) == 0 && !allowNilFeatureSet[supportedVersion.GetIdentifier()] { + continue + } + + return NewVersion(supportedVersion.GetIdentifier(), featureSet), nil + } + } + + return nil, sdkerrors.Wrapf( + ErrVersionNegotiationFailed, + "failed to find a matching counterparty version (%v) from the supported version list (%v)", counterpartyVersions, supportedVersions, + ) +} + +// GetFeatureSetIntersection returns the intersections of source feature set +// and the counterparty feature set. This is done by iterating over all the +// features in the source version and seeing if they exist in the feature +// set for the counterparty version. +func GetFeatureSetIntersection(sourceFeatureSet, counterpartyFeatureSet []string) (featureSet []string) { + for _, feature := range sourceFeatureSet { + if contains(feature, counterpartyFeatureSet) { + featureSet = append(featureSet, feature) + } + } + + return featureSet +} + +// ExportedVersionsToProto casts a slice of the Version interface to a slice +// of the Version proto definition. +func ExportedVersionsToProto(exportedVersions []exported.Version) []*Version { + versions := make([]*Version, len(exportedVersions)) + for i := range exportedVersions { + versions[i] = exportedVersions[i].(*Version) + } + + return versions +} + +// ProtoVersionsToExported converts a slice of the Version proto definition to +// the Version interface. +func ProtoVersionsToExported(versions []*Version) []exported.Version { + exportedVersions := make([]exported.Version, len(versions)) + for i := range versions { + exportedVersions[i] = versions[i] + } + + return exportedVersions +} + // contains returns true if the provided string element exists within the // string set. func contains(elem string, set []string) bool { diff --git a/x/ibc/core/03-connection/types/version_test.go b/x/ibc/core/03-connection/types/version_test.go index a18c87dde3..8f882dd327 100644 --- a/x/ibc/core/03-connection/types/version_test.go +++ b/x/ibc/core/03-connection/types/version_test.go @@ -6,13 +6,14 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/x/ibc/core/03-connection/types" + "github.com/cosmos/cosmos-sdk/x/ibc/core/exported" ibctesting "github.com/cosmos/cosmos-sdk/x/ibc/testing" ) func TestValidateVersion(t *testing.T) { testCases := []struct { name string - version types.Version + version *types.Version expPass bool }{ {"valid version", types.DefaultIBCVersion, true}, @@ -22,10 +23,7 @@ func TestValidateVersion(t *testing.T) { } for i, tc := range testCases { - encodedVersion, err := tc.version.Encode() - require.NoError(t, err, "test case %d failed to marshal version string: %s", i, tc.name) - - err = types.ValidateVersion(encodedVersion) + err := types.ValidateVersion(tc.version) if tc.expPass { require.NoError(t, err, "valid test case %d failed: %s", i, tc.name) @@ -35,44 +33,20 @@ func TestValidateVersion(t *testing.T) { } } -func TestDecodeVersion(t *testing.T) { - testCases := []struct { - name string - version string - expVersion types.Version - expPass bool - }{ - {"valid version", ibctesting.ConnectionVersion, types.DefaultIBCVersion, true}, - {"invalid version", "not a proto encoded version", types.Version{}, false}, - {"empty string", " ", types.Version{}, false}, - } - - for i, tc := range testCases { - version, err := types.DecodeVersion(tc.version) - - if tc.expPass { - require.NoError(t, err, "valid test case %d failed: %s", i, tc.name) - require.Equal(t, tc.expVersion, version) - } else { - require.Error(t, err, "invalid test case %d passed: %s", i, tc.name) - } - } -} - func TestIsSupportedVersion(t *testing.T) { testCases := []struct { name string - version types.Version + version *types.Version expPass bool }{ { "version is supported", - types.GetCompatibleVersions()[0], + types.ExportedVersionsToProto(types.GetCompatibleVersions())[0], true, }, { "version is not supported", - types.Version{}, + &types.Version{}, false, }, { @@ -82,75 +56,64 @@ func TestIsSupportedVersion(t *testing.T) { }, } - // test that a version that cannot be decoded does not pass - require.False(t, types.IsSupportedVersion("1.0")) - for _, tc := range testCases { - encodedVersion, err := tc.version.Encode() - require.NoError(t, err) - - require.Equal(t, tc.expPass, types.IsSupportedVersion(encodedVersion)) + require.Equal(t, tc.expPass, types.IsSupportedVersion(tc.version)) } } func TestFindSupportedVersion(t *testing.T) { testCases := []struct { name string - version types.Version - supportedVersions []types.Version - expVersion types.Version + version *types.Version + supportedVersions []exported.Version + expVersion *types.Version expFound bool }{ {"valid supported version", types.DefaultIBCVersion, types.GetCompatibleVersions(), types.DefaultIBCVersion, true}, - {"empty (invalid) version", types.Version{}, types.GetCompatibleVersions(), types.Version{}, false}, - {"empty supported versions", types.DefaultIBCVersion, []types.Version{}, types.Version{}, false}, - {"desired version is last", types.DefaultIBCVersion, []types.Version{types.NewVersion("1.1", nil), types.NewVersion("2", []string{"ORDER_UNORDERED"}), types.NewVersion("3", nil), types.DefaultIBCVersion}, types.DefaultIBCVersion, true}, + {"empty (invalid) version", &types.Version{}, types.GetCompatibleVersions(), &types.Version{}, false}, + {"empty supported versions", types.DefaultIBCVersion, []exported.Version{}, &types.Version{}, false}, + {"desired version is last", types.DefaultIBCVersion, []exported.Version{types.NewVersion("1.1", nil), types.NewVersion("2", []string{"ORDER_UNORDERED"}), types.NewVersion("3", nil), types.DefaultIBCVersion}, types.DefaultIBCVersion, true}, {"desired version identifier with different feature set", types.NewVersion(types.DefaultIBCVersionIdentifier, []string{"ORDER_DAG"}), types.GetCompatibleVersions(), types.DefaultIBCVersion, true}, - {"version not supported", types.NewVersion("2", []string{"ORDER_DAG"}), types.GetCompatibleVersions(), types.Version{}, false}, + {"version not supported", types.NewVersion("2", []string{"ORDER_DAG"}), types.GetCompatibleVersions(), &types.Version{}, false}, } for i, tc := range testCases { version, found := types.FindSupportedVersion(tc.version, tc.supportedVersions) - - require.Equal(t, tc.expVersion.GetIdentifier(), version.GetIdentifier(), "test case %d: %s", i, tc.name) - require.Equal(t, tc.expFound, found, "test case %d: %s", i, tc.name) + if tc.expFound { + require.Equal(t, tc.expVersion.GetIdentifier(), version.GetIdentifier(), "test case %d: %s", i, tc.name) + require.True(t, found, "test case %d: %s", i, tc.name) + } else { + require.False(t, found, "test case: %s", tc.name) + require.Nil(t, version, "test case: %s", tc.name) + } } } func TestPickVersion(t *testing.T) { testCases := []struct { name string - supportedVersions []types.Version - counterpartyVersions []types.Version - expVer types.Version + supportedVersions []exported.Version + counterpartyVersions []exported.Version + expVer *types.Version expPass bool }{ {"valid default ibc version", types.GetCompatibleVersions(), types.GetCompatibleVersions(), types.DefaultIBCVersion, true}, - {"valid version in counterparty versions", types.GetCompatibleVersions(), []types.Version{types.NewVersion("version1", nil), types.NewVersion("2.0.0", []string{"ORDER_UNORDERED-ZK"}), types.DefaultIBCVersion}, types.DefaultIBCVersion, true}, - {"valid identifier match but empty feature set not allowed", types.GetCompatibleVersions(), []types.Version{types.NewVersion(types.DefaultIBCVersionIdentifier, []string{"DAG", "ORDERED-ZK", "UNORDERED-zk]"})}, types.NewVersion(types.DefaultIBCVersionIdentifier, nil), false}, - {"empty counterparty versions", types.GetCompatibleVersions(), []types.Version{}, types.Version{}, false}, - {"non-matching counterparty versions", types.GetCompatibleVersions(), []types.Version{types.NewVersion("2.0.0", nil)}, types.Version{}, false}, - {"non-matching counterparty versions (uses ordered channels only) contained in supported versions (uses unordered channels only)", []types.Version{types.NewVersion(types.DefaultIBCVersionIdentifier, []string{"ORDER_UNORDERED"})}, []types.Version{types.NewVersion(types.DefaultIBCVersionIdentifier, []string{"ORDER_ORDERED"})}, types.Version{}, false}, + {"valid version in counterparty versions", types.GetCompatibleVersions(), []exported.Version{types.NewVersion("version1", nil), types.NewVersion("2.0.0", []string{"ORDER_UNORDERED-ZK"}), types.DefaultIBCVersion}, types.DefaultIBCVersion, true}, + {"valid identifier match but empty feature set not allowed", types.GetCompatibleVersions(), []exported.Version{types.NewVersion(types.DefaultIBCVersionIdentifier, []string{"DAG", "ORDERED-ZK", "UNORDERED-zk]"})}, types.NewVersion(types.DefaultIBCVersionIdentifier, nil), false}, + {"empty counterparty versions", types.GetCompatibleVersions(), []exported.Version{}, &types.Version{}, false}, + {"non-matching counterparty versions", types.GetCompatibleVersions(), []exported.Version{types.NewVersion("2.0.0", nil)}, &types.Version{}, false}, + {"non-matching counterparty versions (uses ordered channels only) contained in supported versions (uses unordered channels only)", []exported.Version{types.NewVersion(types.DefaultIBCVersionIdentifier, []string{"ORDER_UNORDERED"})}, []exported.Version{types.NewVersion(types.DefaultIBCVersionIdentifier, []string{"ORDER_ORDERED"})}, &types.Version{}, false}, } for i, tc := range testCases { - encodedSupportedVersions, err := types.EncodeVersions(tc.supportedVersions) - require.NoError(t, err) - - encodedCounterpartyVersions, err := types.EncodeVersions(tc.counterpartyVersions) - require.NoError(t, err) - - encodedVersion, err := types.PickVersion(encodedSupportedVersions, encodedCounterpartyVersions) + version, err := types.PickVersion(tc.supportedVersions, tc.counterpartyVersions) if tc.expPass { require.NoError(t, err, "valid test case %d failed: %s", i, tc.name) - - version, err := types.DecodeVersion(encodedVersion) - require.NoError(t, err) - require.Equal(t, tc.expVer, version, "valid test case %d falied: %s", i, tc.name) } else { require.Error(t, err, "invalid test case %d passed: %s", i, tc.name) - require.Equal(t, "", encodedVersion, "invalid test case %d passed: %s", i, tc.name) + var emptyVersion *types.Version + require.Equal(t, emptyVersion, version, "invalid test case %d passed: %s", i, tc.name) } } } @@ -158,8 +121,8 @@ func TestPickVersion(t *testing.T) { func TestVerifyProposedVersion(t *testing.T) { testCases := []struct { name string - proposedVersion types.Version - supportedVersion types.Version + proposedVersion *types.Version + supportedVersion *types.Version expPass bool }{ {"entire feature set supported", types.DefaultIBCVersion, types.NewVersion("1", []string{"ORDER_ORDERED", "ORDER_UNORDERED", "ORDER_DAG"}), true}, @@ -182,12 +145,11 @@ func TestVerifyProposedVersion(t *testing.T) { } func TestVerifySupportedFeature(t *testing.T) { - nilFeatures, err := types.NewVersion(types.DefaultIBCVersionIdentifier, nil).Encode() - require.NoError(t, err) + nilFeatures := types.NewVersion(types.DefaultIBCVersionIdentifier, nil) testCases := []struct { name string - version string + version *types.Version feature string expPass bool }{ @@ -195,7 +157,6 @@ func TestVerifySupportedFeature(t *testing.T) { {"check UNORDERED supported", ibctesting.ConnectionVersion, "ORDER_UNORDERED", true}, {"check DAG unsupported", ibctesting.ConnectionVersion, "ORDER_DAG", false}, {"check empty feature set returns false", nilFeatures, "ORDER_ORDERED", false}, - {"failed to unmarshal version", "not an encoded version", "ORDER_ORDERED", false}, } for i, tc := range testCases { diff --git a/x/ibc/core/04-channel/keeper/handshake_test.go b/x/ibc/core/04-channel/keeper/handshake_test.go index 927bc3131b..fe5dc3593a 100644 --- a/x/ibc/core/04-channel/keeper/handshake_test.go +++ b/x/ibc/core/04-channel/keeper/handshake_test.go @@ -56,8 +56,7 @@ func (suite *KeeperTestSuite) TestChanOpenInit() { // modify connA versions conn := suite.chainA.GetConnection(connA) - version, err := connectiontypes.NewVersion("2", []string{"ORDER_ORDERED", "ORDER_UNORDERED"}).Encode() - suite.Require().NoError(err) + version := connectiontypes.NewVersion("2", []string{"ORDER_ORDERED", "ORDER_UNORDERED"}) conn.Versions = append(conn.Versions, version) suite.chainA.App.IBCKeeper.ConnectionKeeper.SetConnection( @@ -74,9 +73,8 @@ func (suite *KeeperTestSuite) TestChanOpenInit() { // modify connA versions to only support UNORDERED channels conn := suite.chainA.GetConnection(connA) - version, err := connectiontypes.NewVersion("1", []string{"ORDER_UNORDERED"}).Encode() - suite.Require().NoError(err) - conn.Versions = []string{version} + version := connectiontypes.NewVersion("1", []string{"ORDER_UNORDERED"}) + conn.Versions = []*connectiontypes.Version{version} suite.chainA.App.IBCKeeper.ConnectionKeeper.SetConnection( suite.chainA.GetContext(), @@ -244,8 +242,7 @@ func (suite *KeeperTestSuite) TestChanOpenTry() { // modify connB versions conn := suite.chainB.GetConnection(connB) - version, err := connectiontypes.NewVersion("2", []string{"ORDER_ORDERED", "ORDER_UNORDERED"}).Encode() - suite.Require().NoError(err) + version := connectiontypes.NewVersion("2", []string{"ORDER_ORDERED", "ORDER_UNORDERED"}) conn.Versions = append(conn.Versions, version) suite.chainB.App.IBCKeeper.ConnectionKeeper.SetConnection( @@ -262,9 +259,8 @@ func (suite *KeeperTestSuite) TestChanOpenTry() { // modify connA versions to only support UNORDERED channels conn := suite.chainA.GetConnection(connA) - version, err := connectiontypes.NewVersion("1", []string{"ORDER_UNORDERED"}).Encode() - suite.Require().NoError(err) - conn.Versions = []string{version} + version := connectiontypes.NewVersion("1", []string{"ORDER_UNORDERED"}) + conn.Versions = []*connectiontypes.Version{version} suite.chainA.App.IBCKeeper.ConnectionKeeper.SetConnection( suite.chainA.GetContext(), diff --git a/x/ibc/core/exported/connection.go b/x/ibc/core/exported/connection.go index d8eddf9df1..a21c5a5364 100644 --- a/x/ibc/core/exported/connection.go +++ b/x/ibc/core/exported/connection.go @@ -5,7 +5,7 @@ type ConnectionI interface { GetClientID() string GetState() int32 GetCounterparty() CounterpartyConnectionI - GetVersions() []string + GetVersions() []Version ValidateBasic() error } @@ -16,3 +16,10 @@ type CounterpartyConnectionI interface { GetPrefix() Prefix ValidateBasic() error } + +// Version defines an IBC version used in connection handshake negotiation. +type Version interface { + GetIdentifier() string + GetFeatures() []string + VerifyProposedVersion(Version) error +} diff --git a/x/ibc/core/genesis_test.go b/x/ibc/core/genesis_test.go index 6dc06a5de8..482027fb88 100644 --- a/x/ibc/core/genesis_test.go +++ b/x/ibc/core/genesis_test.go @@ -100,7 +100,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() { ), ConnectionGenesis: connectiontypes.NewGenesisState( []connectiontypes.IdentifiedConnection{ - connectiontypes.NewIdentifiedConnection(connectionID, connectiontypes.NewConnectionEnd(connectiontypes.INIT, clientID, connectiontypes.NewCounterparty(clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))), []string{ibctesting.ConnectionVersion})), + connectiontypes.NewIdentifiedConnection(connectionID, connectiontypes.NewConnectionEnd(connectiontypes.INIT, clientID, connectiontypes.NewCounterparty(clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))), []*connectiontypes.Version{ibctesting.ConnectionVersion})), }, []connectiontypes.ConnectionPaths{ connectiontypes.NewConnectionPaths(clientID, []string{host.ConnectionPath(connectionID)}), @@ -159,7 +159,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() { ClientGenesis: clienttypes.DefaultGenesisState(), ConnectionGenesis: connectiontypes.NewGenesisState( []connectiontypes.IdentifiedConnection{ - connectiontypes.NewIdentifiedConnection(connectionID, connectiontypes.NewConnectionEnd(connectiontypes.INIT, "(CLIENTIDONE)", connectiontypes.NewCounterparty(clientID, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))), []string{"1.0.0"})), + connectiontypes.NewIdentifiedConnection(connectionID, connectiontypes.NewConnectionEnd(connectiontypes.INIT, "(CLIENTIDONE)", connectiontypes.NewCounterparty(clientID, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))), []*connectiontypes.Version{connectiontypes.NewVersion("1.1", nil)})), }, []connectiontypes.ConnectionPaths{ connectiontypes.NewConnectionPaths(clientID, []string{host.ConnectionPath(connectionID)}), @@ -234,7 +234,7 @@ func (suite *IBCTestSuite) TestInitGenesis() { ), ConnectionGenesis: connectiontypes.NewGenesisState( []connectiontypes.IdentifiedConnection{ - connectiontypes.NewIdentifiedConnection(connectionID, connectiontypes.NewConnectionEnd(connectiontypes.INIT, clientID, connectiontypes.NewCounterparty(clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))), []string{ibctesting.ConnectionVersion})), + connectiontypes.NewIdentifiedConnection(connectionID, connectiontypes.NewConnectionEnd(connectiontypes.INIT, clientID, connectiontypes.NewCounterparty(clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))), []*connectiontypes.Version{ibctesting.ConnectionVersion})), }, []connectiontypes.ConnectionPaths{ connectiontypes.NewConnectionPaths(clientID, []string{host.ConnectionPath(connectionID)}), diff --git a/x/ibc/core/keeper/msg_server.go b/x/ibc/core/keeper/msg_server.go index 15af734846..d448aca8b6 100644 --- a/x/ibc/core/keeper/msg_server.go +++ b/x/ibc/core/keeper/msg_server.go @@ -165,7 +165,7 @@ func (k Keeper) ConnectionOpenTry(goCtx context.Context, msg *connectiontypes.Ms if err := k.ConnectionKeeper.ConnOpenTry( ctx, msg.DesiredConnectionId, msg.CounterpartyChosenConnectionId, msg.Counterparty, msg.ClientId, targetClient, - msg.CounterpartyVersions, msg.ProofInit, msg.ProofClient, msg.ProofConsensus, + connectiontypes.ProtoVersionsToExported(msg.CounterpartyVersions), msg.ProofInit, msg.ProofClient, msg.ProofConsensus, msg.ProofHeight, msg.ConsensusHeight, ); err != nil { return nil, sdkerrors.Wrap(err, "connection handshake open try failed") diff --git a/x/ibc/core/simulation/decoder_test.go b/x/ibc/core/simulation/decoder_test.go index 17f584d00a..d14a9f28cc 100644 --- a/x/ibc/core/simulation/decoder_test.go +++ b/x/ibc/core/simulation/decoder_test.go @@ -30,7 +30,7 @@ func TestDecodeStore(t *testing.T) { } connection := connectiontypes.ConnectionEnd{ ClientId: "clientidone", - Versions: []string{"1.0"}, + Versions: []*connectiontypes.Version{connectiontypes.NewVersion("1", nil)}, } channel := channeltypes.Channel{ State: channeltypes.OPEN, diff --git a/x/ibc/core/spec/01_concepts.md b/x/ibc/core/spec/01_concepts.md index 9e7654ddda..079e6fa702 100644 --- a/x/ibc/core/spec/01_concepts.md +++ b/x/ibc/core/spec/01_concepts.md @@ -160,7 +160,7 @@ connection is set and stored in the OPEN state upon success. ## Connection Version Negotiation -During the handshake procedure for connections a version string is agreed +During the handshake procedure for connections a version is agreed upon between the two parties. This occurs during the first 3 steps of the handshake. @@ -181,16 +181,20 @@ During `ConnOpenAck`, party A will verify that they can support the version party B selected. If they do not support the selected version an error is returned. After this step, the connection version is considered agreed upon. -A valid connection version is considered to be in the following format: -`(version-identifier,[feature-0,feature-1])` -- the version tuple must be enclosed in parentheses -- the feature set must be enclosed in brackets -- there should be no space between the comma separating the identifier and the - feature set -- the version identifier must no contain any commas -- each feature must not contain any commas -- each feature must be separated by commas +A `Version` is defined as follows: + +```go +type Version struct { + // unique version identifier + Identifier string + // list of features compatible with the specified identifier + Features []string +} +``` + +A version must contain a non empty identifier. Empty feature sets are allowed, but each +feature must be a non empty string. ::: warning A set of versions should not contain two versions with the same diff --git a/x/ibc/light-clients/06-solomachine/types/client_state_test.go b/x/ibc/light-clients/06-solomachine/types/client_state_test.go index 30da780488..f13eba0576 100644 --- a/x/ibc/light-clients/06-solomachine/types/client_state_test.go +++ b/x/ibc/light-clients/06-solomachine/types/client_state_test.go @@ -336,7 +336,7 @@ func (suite *SoloMachineTestSuite) TestVerifyClientConsensusState() { func (suite *SoloMachineTestSuite) TestVerifyConnectionState() { counterparty := connectiontypes.NewCounterparty("clientB", testConnectionID, prefix) - conn := connectiontypes.NewConnectionEnd(connectiontypes.OPEN, "clientA", counterparty, []string{"1.0.0"}) + conn := connectiontypes.NewConnectionEnd(connectiontypes.OPEN, "clientA", counterparty, connectiontypes.ExportedVersionsToProto(connectiontypes.GetCompatibleVersions())) path := suite.solomachine.GetConnectionStatePath(testConnectionID) diff --git a/x/ibc/light-clients/06-solomachine/types/codec_test.go b/x/ibc/light-clients/06-solomachine/types/codec_test.go index 5f9589466e..eb304bb28d 100644 --- a/x/ibc/light-clients/06-solomachine/types/codec_test.go +++ b/x/ibc/light-clients/06-solomachine/types/codec_test.go @@ -68,7 +68,7 @@ func (suite SoloMachineTestSuite) TestUnmarshalDataByType() { { "connection", types.CONNECTION, func() { counterparty := connectiontypes.NewCounterparty("clientB", testConnectionID, prefix) - conn := connectiontypes.NewConnectionEnd(connectiontypes.OPEN, "clientA", counterparty, []string{"1.0.0"}) + conn := connectiontypes.NewConnectionEnd(connectiontypes.OPEN, "clientA", counterparty, connectiontypes.ExportedVersionsToProto(connectiontypes.GetCompatibleVersions())) path := solomachine.GetConnectionStatePath("connectionID") data, err = types.ConnectionStateDataBytes(cdc, path, conn) @@ -99,7 +99,7 @@ func (suite SoloMachineTestSuite) TestUnmarshalDataByType() { { "bad channel (uses connection data)", types.CHANNEL, func() { counterparty := connectiontypes.NewCounterparty("clientB", testConnectionID, prefix) - conn := connectiontypes.NewConnectionEnd(connectiontypes.OPEN, "clientA", counterparty, []string{"1.0.0"}) + conn := connectiontypes.NewConnectionEnd(connectiontypes.OPEN, "clientA", counterparty, connectiontypes.ExportedVersionsToProto(connectiontypes.GetCompatibleVersions())) path := solomachine.GetConnectionStatePath("connectionID") data, err = types.ConnectionStateDataBytes(cdc, path, conn) diff --git a/x/ibc/light-clients/09-localhost/types/client_state_test.go b/x/ibc/light-clients/09-localhost/types/client_state_test.go index f251d086f6..abe6f20b60 100644 --- a/x/ibc/light-clients/09-localhost/types/client_state_test.go +++ b/x/ibc/light-clients/09-localhost/types/client_state_test.go @@ -145,8 +145,8 @@ func (suite *LocalhostTestSuite) TestProposedHeaderAndUpdateState() { func (suite *LocalhostTestSuite) TestVerifyConnectionState() { counterparty := connectiontypes.NewCounterparty("clientB", testConnectionID, commitmenttypes.NewMerklePrefix([]byte("ibc"))) - conn1 := connectiontypes.NewConnectionEnd(connectiontypes.OPEN, "clientA", counterparty, []string{"1.0.0"}) - conn2 := connectiontypes.NewConnectionEnd(connectiontypes.OPEN, "clientA", counterparty, []string{"2.0.0"}) + conn1 := connectiontypes.NewConnectionEnd(connectiontypes.OPEN, "clientA", counterparty, []*connectiontypes.Version{connectiontypes.NewVersion("1", nil)}) + conn2 := connectiontypes.NewConnectionEnd(connectiontypes.OPEN, "clientA", counterparty, []*connectiontypes.Version{connectiontypes.NewVersion("2", nil)}) testCases := []struct { name string diff --git a/x/ibc/testing/chain.go b/x/ibc/testing/chain.go index 923e6ae4eb..4ef4676eef 100644 --- a/x/ibc/testing/chain.go +++ b/x/ibc/testing/chain.go @@ -50,9 +50,8 @@ const ( UnbondingPeriod time.Duration = time.Hour * 24 * 7 * 3 MaxClockDrift time.Duration = time.Second * 10 - DefaultChannelVersion = ibctransfertypes.Version - DefaultOpenInitVersion = "" - InvalidID = "IDisInvalid" + DefaultChannelVersion = ibctransfertypes.Version + InvalidID = "IDisInvalid" ConnectionIDPrefix = "conn" ChannelIDPrefix = "chan" @@ -68,6 +67,8 @@ const ( var ( DefaultConsensusParams = simapp.DefaultConsensusParams + DefaultOpenInitVersion *connectiontypes.Version + // Default params variables used to create a TM client DefaultTrustLevel ibctmtypes.Fraction = ibctmtypes.DefaultTrustLevel TestHash = tmhash.Sum([]byte("TESTING HASH")) @@ -75,7 +76,7 @@ var ( UpgradePath = fmt.Sprintf("%s/%s", "upgrade", "upgradedClient") - ConnectionVersion = connectiontypes.GetCompatibleEncodedVersions()[0] + ConnectionVersion = connectiontypes.ExportedVersionsToProto(connectiontypes.GetCompatibleVersions())[0] MockAcknowledgement = mock.MockAcknowledgement MockCommitment = mock.MockCommitment @@ -654,7 +655,7 @@ func (chain *TestChain) ConnectionOpenTry( msg := connectiontypes.NewMsgConnectionOpenTry( connection.ID, connection.ID, connection.ClientID, // testing doesn't use flexible selection counterpartyConnection.ID, counterpartyConnection.ClientID, - counterpartyClient, counterparty.GetPrefix(), []string{ConnectionVersion}, + counterpartyClient, counterparty.GetPrefix(), []*connectiontypes.Version{ConnectionVersion}, proofInit, proofClient, proofConsensus, proofHeight, consensusHeight, chain.SenderAccount.GetAddress(),