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

Complete example for compiling and decoding ConnectionEnd with Prost. #139

Closed
wants to merge 1 commit into from

Conversation

adizere
Copy link
Member

@adizere adizere commented Jul 9, 2020

Closes: #130

Description


For contributor use:

  • Unit tests written
  • Added test to CI if applicable
  • Updated CHANGELOG_PENDING.md
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Updated relevant documentation (docs/) and code comments
  • Re-reviewed Files changed in the Github PR explorer

@adizere adizere requested review from ancazamfir and romac as code owners July 9, 2020 16:24
let buf = Bytes::from(_response.value);

let conn_end:items::ConnectionEnd = items::ConnectionEnd::decode(buf).unwrap();

Copy link
Member Author

Choose a reason for hiding this comment

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

@andynog This is perhaps the most important part for decoding.

@adizere
Copy link
Member Author

adizere commented Jul 9, 2020

One major part we should decide is how to handle the gogoproto annotations that are Go-specific.

The .proto file in this commit is as follows (everything that starts with gogo is irrelevant for Rust code):

syntax = "proto3";

package items;

import "proto/gogo.proto";
//import "ibc/commitment/commitment.proto";

// ConnectionEnd defines a stateful object on a chain connected to another separate
// one.
// NOTE: there must only be 2 defined ConnectionEnds to establish a connection
// between two chains.
message ConnectionEnd {
  option (gogoproto.goproto_getters) = false;
  // connection identifier.
  string id = 1 [(gogoproto.customname) = "ID", (gogoproto.moretags) = "yaml:\"id\""];
  // client associated with this connection.
  string client_id = 2 [(gogoproto.customname) = "ClientID", (gogoproto.moretags) = "yaml:\"client_id\""];
  // opaque string which can be utilised to determine encodings or protocols for
  // channels or packets utilising this connection
  repeated string versions = 3;
  // current state of the connection end.
  State state = 4;
  // counterparty chain associated with this corparty = 5 [(gogoprotonnection.
//  Counterparty counte.nullable) = false];
}

// State defines if a connection is in one of the following states:
// INIT, TRYOPEN, OPEN or UNINITIALIZED.
enum State {
  option (gogoproto.goproto_enum_prefix) = false;

  // Default State
  STATE_UNINITIALIZED_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "UNINITIALIZED"];
  // A connection end has just started the opening handshake.
  STATE_INIT = 1 [(gogoproto.enumvalue_customname) = "INIT"];
  // A connection end has acknowledged the handshake step on the counterparty chain.
  STATE_TRYOPEN = 2 [(gogoproto.enumvalue_customname) = "TRYOPEN"];
  // A connection end has completed the handshake.
  STATE_OPEN = 3 [(gogoproto.enumvalue_customname) = "OPEN"];
}

The resulting .rs file is as follows:

/// ConnectionEnd defines a stateful object on a chain connected to another separate
/// one.
/// NOTE: there must only be 2 defined ConnectionEnds to establish a connection
/// between two chains.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ConnectionEnd {
    /// connection identifier.
    #[prost(string, tag="1")]
    pub id: std::string::String,
    /// client associated with this connection.
    #[prost(string, tag="2")]
    pub client_id: std::string::String,
    /// opaque string which can be utilised to determine encodings or protocols for
    /// channels or packets utilising this connection
    #[prost(string, repeated, tag="3")]
    pub versions: ::std::vec::Vec<std::string::String>,
    /// current state of the connection end.
    ///
    ///  // counterparty chain associated with this connection.
    ///  Counterparty counterparty = 5 [(gogoproto.nullable) = false];
    #[prost(enumeration="State", tag="4")]
    pub state: i32,
}
/// State defines if a connection is in one of the following states:
/// INIT, TRYOPEN, OPEN or UNINITIALIZED.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum State {
    /// Default State
    UninitializedUnspecified = 0,
    /// A connection end has just started the opening handshake.
    Init = 1,
    /// A connection end has acknowledged the handshake step on the counterparty chain.
    Tryopen = 2,
    /// A connection end has completed the handshake.
    Open = 3,
}

TODOs:

  • if we want to keep the .proto files in this repo:
    • figure out if we can compile without the import gogo...
    • figure out if all the gogo annotations can go away, basically trim the .proto file to its bare minimum
  • preferable alternative: use in Rust the compiled version directly (and forget about the .proto)

@@ -6,7 +6,7 @@
trivial_casts,
trivial_numeric_casts,
unused_import_braces,
unused_qualifications,
// unused_qualifications,
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason for commenting this out?

Copy link
Member Author

Choose a reason for hiding this comment

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

It has to do with the generated Rust code which prost generated, for instance: pub versions: ::std::vec::Vec<std::string::String>. This seems to be the offending part that triggers the unused_qualifications warning, but I have not digged into it.

Any thoughts or prior experience with unused_qualifications ? I almost forgot about this. We should probably fix & enable the warning again it before merge.

@adizere adizere closed this Jul 10, 2020
@adizere adizere deleted the adi/prost_decoding branch July 10, 2020 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

query connection given connection_id
3 participants