Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ibc: Connection Version changed from string to proto definition #7644

Merged
merged 18 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 2 additions & 106 deletions proto/ibc/core/connection/v1/connection.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,110 +8,6 @@ import "google/protobuf/any.proto";
import "ibc/core/commitment/v1/commitment.proto";
import "ibc/core/client/v1/client.proto";

// Msg defines the ibc/connection Msg service.
service Msg {
// ConnectionOpenInit defines a rpc handler method for MsgConnectionOpenInit.
rpc ConnectionOpenInit(MsgConnectionOpenInit) returns (MsgConnectionOpenInitResponse);

// ConnectionOpenTry defines a rpc handler method for MsgConnectionOpenTry.
rpc ConnectionOpenTry(MsgConnectionOpenTry) returns (MsgConnectionOpenTryResponse);

// ConnectionOpenAck defines a rpc handler method for MsgConnectionOpenAck.
rpc ConnectionOpenAck(MsgConnectionOpenAck) returns (MsgConnectionOpenAckResponse);

// ConnectionOpenConfirm defines a rpc handler method for MsgConnectionOpenConfirm.
rpc ConnectionOpenConfirm(MsgConnectionOpenConfirm) returns (MsgConnectionOpenConfirmResponse);
}

// MsgConnectionOpenInit defines the msg sent by an account on Chain A to
// initialize a connection with Chain B.
message MsgConnectionOpenInit {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

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;
string signer = 5;
}

// MsgConnectionOpenInitResponse defines the Msg/ConnectionOpenInit response type.
message MsgConnectionOpenInitResponse { }

// MsgConnectionOpenTry defines a msg sent by a Relayer to try to open a
// connection on Chain B.
message MsgConnectionOpenTry {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
string desired_connection_id = 2 [(gogoproto.moretags) = "yaml:\"desired_connection_id\""];
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\""];
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 ->
// INIT`
bytes proof_init = 8 [(gogoproto.moretags) = "yaml:\"proof_init\""];
// proof of client state included in message
bytes proof_client = 9 [(gogoproto.moretags) = "yaml:\"proof_client\""];
// proof of client consensus state
bytes proof_consensus = 10 [(gogoproto.moretags) = "yaml:\"proof_consensus\""];
ibc.core.client.v1.Height consensus_height = 11
[(gogoproto.moretags) = "yaml:\"consensus_height\"", (gogoproto.nullable) = false];
string signer = 12;
}

// MsgConnectionOpenTryResponse defines the Msg/ConnectionOpenTry response type.
message MsgConnectionOpenTryResponse { }

// MsgConnectionOpenAck defines a msg sent by a Relayer to Chain A to
// acknowledge the change of connection state to TRYOPEN on Chain B.
message MsgConnectionOpenAck {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string connection_id = 1 [(gogoproto.moretags) = "yaml:\"connection_id\""];
string counterparty_connection_id = 2 [(gogoproto.moretags) = "yaml:\"counterparty_connection_id\""];
string 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];
// proof of the initialization the connection on Chain B: `UNITIALIZED ->
// TRYOPEN`
bytes proof_try = 6 [(gogoproto.moretags) = "yaml:\"proof_try\""];
// proof of client state included in message
bytes proof_client = 7 [(gogoproto.moretags) = "yaml:\"proof_client\""];
// proof of client consensus state
bytes proof_consensus = 8 [(gogoproto.moretags) = "yaml:\"proof_consensus\""];
ibc.core.client.v1.Height consensus_height = 9
[(gogoproto.moretags) = "yaml:\"consensus_height\"", (gogoproto.nullable) = false];
string signer = 10;
}

// MsgConnectionOpenAckResponse defines the Msg/ConnectionOpenAck response type.
message MsgConnectionOpenAckResponse { }

// MsgConnectionOpenConfirm defines a msg sent by a Relayer to Chain B to
// acknowledge the change of connection state to OPEN on Chain A.
message MsgConnectionOpenConfirm {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string connection_id = 1 [(gogoproto.moretags) = "yaml:\"connection_id\""];
// proof for the change of the connection state on Chain A: `INIT -> OPEN`
bytes proof_ack = 2 [(gogoproto.moretags) = "yaml:\"proof_ack\""];
ibc.core.client.v1.Height proof_height = 3
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
string signer = 4;
}

// MsgConnectionOpenConfirmResponse defines the Msg/ConnectionOpenConfirm response type.
message MsgConnectionOpenConfirmResponse { }

// ICS03 - Connection Data Structures as defined in
// https://github.com/cosmos/ics/tree/master/spec/ics-003-connection-semantics#data-structures

Expand All @@ -124,7 +20,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.
Expand All @@ -141,7 +37,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.
Expand Down
115 changes: 115 additions & 0 deletions proto/ibc/core/connection/v1/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
syntax = "proto3";
package ibc.core.connection.v1;

option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/core/03-connection/types";

import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";
import "ibc/core/commitment/v1/commitment.proto";
import "ibc/core/client/v1/client.proto";
import "ibc/core/connection/v1/connection.proto";

// Msg defines the ibc/connection Msg service.
service Msg {
// ConnectionOpenInit defines a rpc handler method for MsgConnectionOpenInit.
rpc ConnectionOpenInit(MsgConnectionOpenInit) returns (MsgConnectionOpenInitResponse);

// ConnectionOpenTry defines a rpc handler method for MsgConnectionOpenTry.
rpc ConnectionOpenTry(MsgConnectionOpenTry) returns (MsgConnectionOpenTryResponse);

// ConnectionOpenAck defines a rpc handler method for MsgConnectionOpenAck.
rpc ConnectionOpenAck(MsgConnectionOpenAck) returns (MsgConnectionOpenAckResponse);

// ConnectionOpenConfirm defines a rpc handler method for MsgConnectionOpenConfirm.
rpc ConnectionOpenConfirm(MsgConnectionOpenConfirm) returns (MsgConnectionOpenConfirmResponse);
}


// MsgConnectionOpenInit defines the msg sent by an account on Chain A to
// initialize a connection with Chain B.
message MsgConnectionOpenInit {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
string connection_id = 2 [(gogoproto.moretags) = "yaml:\"connection_id\""];
Counterparty counterparty = 3 [(gogoproto.nullable) = false];
Version version = 4;
string signer = 5;
}

// MsgConnectionOpenInitResponse defines the Msg/ConnectionOpenInit response type.
message MsgConnectionOpenInitResponse { }

// MsgConnectionOpenTry defines a msg sent by a Relayer to try to open a
// connection on Chain B.
message MsgConnectionOpenTry {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
string desired_connection_id = 2 [(gogoproto.moretags) = "yaml:\"desired_connection_id\""];
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 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 ->
// INIT`
bytes proof_init = 8 [(gogoproto.moretags) = "yaml:\"proof_init\""];
// proof of client state included in message
bytes proof_client = 9 [(gogoproto.moretags) = "yaml:\"proof_client\""];
// proof of client consensus state
bytes proof_consensus = 10 [(gogoproto.moretags) = "yaml:\"proof_consensus\""];
ibc.core.client.v1.Height consensus_height = 11
[(gogoproto.moretags) = "yaml:\"consensus_height\"", (gogoproto.nullable) = false];
string signer = 12;
}

// MsgConnectionOpenTryResponse defines the Msg/ConnectionOpenTry response type.
message MsgConnectionOpenTryResponse { }

// MsgConnectionOpenAck defines a msg sent by a Relayer to Chain A to
// acknowledge the change of connection state to TRYOPEN on Chain B.
message MsgConnectionOpenAck {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string connection_id = 1 [(gogoproto.moretags) = "yaml:\"connection_id\""];
string counterparty_connection_id = 2 [(gogoproto.moretags) = "yaml:\"counterparty_connection_id\""];
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];
// proof of the initialization the connection on Chain B: `UNITIALIZED ->
// TRYOPEN`
bytes proof_try = 6 [(gogoproto.moretags) = "yaml:\"proof_try\""];
// proof of client state included in message
bytes proof_client = 7 [(gogoproto.moretags) = "yaml:\"proof_client\""];
// proof of client consensus state
bytes proof_consensus = 8 [(gogoproto.moretags) = "yaml:\"proof_consensus\""];
ibc.core.client.v1.Height consensus_height = 9
[(gogoproto.moretags) = "yaml:\"consensus_height\"", (gogoproto.nullable) = false];
string signer = 10;
}

// MsgConnectionOpenAckResponse defines the Msg/ConnectionOpenAck response type.
message MsgConnectionOpenAckResponse { }

// MsgConnectionOpenConfirm defines a msg sent by a Relayer to Chain B to
// acknowledge the change of connection state to OPEN on Chain A.
message MsgConnectionOpenConfirm {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string connection_id = 1 [(gogoproto.moretags) = "yaml:\"connection_id\""];
// proof for the change of the connection state on Chain A: `INIT -> OPEN`
bytes proof_ack = 2 [(gogoproto.moretags) = "yaml:\"proof_ack\""];
ibc.core.client.v1.Height proof_height = 3
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
string signer = 4;
}

// MsgConnectionOpenConfirmResponse defines the Msg/ConnectionOpenConfirm response type.
message MsgConnectionOpenConfirmResponse { }
2 changes: 1 addition & 1 deletion x/ibc/applications/transfer/types/transfer.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/ibc/core/02-client/types/client.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 47 additions & 13 deletions x/ibc/core/03-connection/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -53,7 +56,7 @@ func NewConnectionOpenInitCmd() *cobra.Command {
return err
}

var encodedVersion string
var version *types.Version
versionIdentifier, _ := cmd.Flags().GetString(flagVersionIdentifier)

if versionIdentifier != "" {
Expand All @@ -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 {
Expand All @@ -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]\
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
)
Expand Down Expand Up @@ -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,
Expand Down
Loading