-
Notifications
You must be signed in to change notification settings - Fork 332
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
WIP Connection queries for Relayer #136
Changes from 7 commits
7e6e76a
030c4d0
ae792c0
d332fd6
949ad61
107cccb
3aae417
9c2f528
7423376
4db544c
a8ed4d5
f8c0721
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extern crate prost_build; | ||
|
||
fn main() { | ||
prost_build::compile_protos(&["src/proto/connection.proto"], &["src/proto"]).unwrap(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,15 @@ impl State { | |
Self::Open => "OPEN", | ||
} | ||
} | ||
|
||
pub fn from_i32(nr: i32) -> Self { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ancazamfir was not sure this is accurate, please double-check. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good. |
||
match nr { | ||
1 => Self::Init, | ||
2 => Self::TryOpen, | ||
3 => Self::Open, | ||
_ => Self::Uninitialized, | ||
} | ||
} | ||
} | ||
|
||
impl std::str::FromStr for State { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ impl CommitmentPath { | |
where | ||
P: Path, | ||
{ | ||
todo!() | ||
CommitmentPath {} | ||
} | ||
} | ||
|
||
|
@@ -32,6 +32,10 @@ impl CommitmentProof { | |
*/ | ||
|
||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub struct CommitmentPrefix; | ||
pub struct CommitmentPrefix(Vec<u8>); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering if we should have a formatter for this. The output of the query shows: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implemented a fmt::Debug trait to properly format the CommitmentPrefix output in this commit |
||
|
||
// TODO: impl CommitPrefix | ||
impl CommitmentPrefix { | ||
pub fn new(content: Vec<u8>) -> Self { | ||
Self { 0: content } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
syntax = "proto3"; | ||
|
||
package connection; | ||
|
||
// ICS03 - Connection Data Structures as defined in | ||
// https://github.com/cosmos/ics/tree/master/spec/ics-003-connection-semantics#data-structures | ||
|
||
// 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 { | ||
// connection identifier. | ||
string id = 1; | ||
// client associated with this connection. | ||
string client_id = 2; | ||
// 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 connection. | ||
Counterparty counterparty = 5; | ||
} | ||
|
||
// State defines if a connection is in one of the following states: | ||
// INIT, TRYOPEN, OPEN or UNINITIALIZED. | ||
enum State { | ||
// Default State | ||
STATE_UNINITIALIZED_UNSPECIFIED = 0; | ||
// A connection end has just started the opening handshake. | ||
STATE_INIT = 1; | ||
// A connection end has acknowledged the handshake step on the counterparty chain. | ||
STATE_TRYOPEN = 2; | ||
// A connection end has completed the handshake. | ||
STATE_OPEN = 3; | ||
} | ||
|
||
// Counterparty defines the counterparty chain associated with a connection end. | ||
message Counterparty { | ||
// identifies the client on the counterparty chain associated with a given connection. | ||
string client_id = 1; | ||
// identifies the connection end on the counterparty chain associated with a given connection. | ||
string connection_id = 2; | ||
// commitment merkle prefix of the counterparty chain | ||
MerklePrefix prefix = 3; | ||
} | ||
|
||
|
||
// MerklePrefix is merkle path prefixed to the key. | ||
// The constructed key from the Path and the key will be append(Path.KeyPath, append(Path.KeyPrefix, key...)) | ||
message MerklePrefix { | ||
bytes key_prefix = 1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we get rid of the
unwrap()
s? If the user issues a query command and gets back a few pages of traces it does not help. I had this comment earlier but I guess it got lost. Try to query with non-exsiting connection id.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to make this into a From trait, if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I guess this should be verifying all the fields, not just 2? And should we really have an error per field or maybe start with a more general InvalidConnectionEnd error of some kind and include what's missing as a string? Not sure ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either option could work, the question is if we want to keep validation inside the
from
or outside. The current code uses theFromStr
trait, with the signaturefn from_str(s: &str) -> Result<Self, Self::Err>
so we can do validation inside there and return error if validation fails. WithFrom
, the sig isfn from(T) -> Self
so we'd have to do validation after callingfrom
. Is it generally speaking, or specifically in this case, better to do validation outside offrom
?LE: Maybe this helps?
Agree this deserves a discussion to find a more principled approach.