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

WIP Connection queries for Relayer #136

Merged
merged 12 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions modules/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ serde_derive = "1.0.104"
serde = "1.0.104"
serde_json = "1"
tracing = "0.1.13"
prost = "0.6.1"
bytes = "0.5.5"

[dev-dependencies]
tokio = { version = "0.2", features = ["macros"] }
subtle-encoding = { version = "0.5" }

[build-dependencies]
prost-build = { version = "0.6.1" }
5 changes: 5 additions & 0 deletions modules/build.rs
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/ibc/connection/connection.proto"], &["src/proto"]).unwrap();
}
5 changes: 5 additions & 0 deletions modules/src/ics03_connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ pub mod events;
pub mod exported;
pub mod msgs;
pub mod query;

// Use the generated proto file for the connection according to prost_build instructions
pub mod proto_ibc_connection {
include!(concat!(env!("OUT_DIR"), "/ibc.connection.rs"));
}
54 changes: 43 additions & 11 deletions modules/src/ics03_connection/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ use tendermint_rpc::endpoint::abci_query::AbciQuery;

use tendermint::abci;

use crate::ics23_commitment::{CommitmentPath, CommitmentProof};
use crate::ics24_host::identifier::ConnectionId;
use crate::ics23_commitment::{CommitmentPath, CommitmentProof, CommitmentPrefix};
use crate::ics24_host::identifier::{ConnectionId, ClientId};

use crate::error;
use crate::ics03_connection::connection::ConnectionEnd;
use crate::ics03_connection::connection::{ConnectionEnd, Counterparty};
use crate::path::{ConnectionPath, Path};
use crate::query::{IbcQuery, IbcResponse};
use crate::Height;

// Protobuf
use crate::ics03_connection::proto_ibc_connection;
use prost::Message;
use bytes::Bytes;
use std::str::FromStr;

pub struct QueryConnection {
pub chain_height: Height,
pub connection_id: ConnectionId,
Expand Down Expand Up @@ -79,14 +85,22 @@ impl IbcResponse<QueryConnection> for ConnectionResponse {
query: QueryConnection,
response: AbciQuery,
) -> Result<Self, error::Error> {
let connection = amino_unmarshal_binary_length_prefixed(&response.value)?;

Ok(ConnectionResponse::new(
query.connection_id,
connection,
response.proof,
response.height.into(),
))

let connection = proto_unmarshal(response.value);
match connection {
Ok(conn) => {
Ok(ConnectionResponse::new(
query.connection_id,
conn,
response.proof,
response.height.into(),
))
},
Err(e) => {
println!("Error proto un-marshall: {:?}", e);
todo!()
}
}
}
}

Expand All @@ -105,6 +119,24 @@ impl IdentifiedConnectionEnd {
}
}

fn proto_unmarshal(bytes: Vec<u8>) -> Result<ConnectionEnd, error::Error> {
let buf = Bytes::from(bytes);
let decoded = proto_ibc_connection::ConnectionEnd::decode(buf);
match decoded {
Ok(conn) => {
let client_id = ClientId::from_str(&conn.client_id).unwrap();
adizere marked this conversation as resolved.
Show resolved Hide resolved
let prefix = CommitmentPrefix{};
let counterparty = Counterparty::new(client_id.to_string(), conn.id, prefix).unwrap();
let connection_end = ConnectionEnd::new(client_id, counterparty, conn.versions).unwrap();
Ok(connection_end)
},
Err(e) => {
println!("Error proto un-marshall: {:?}", e);
todo!()
}
}
}

adizere marked this conversation as resolved.
Show resolved Hide resolved
fn amino_unmarshal_binary_length_prefixed<T>(_bytes: &[u8]) -> Result<T, error::Error> {
todo!()
}
2 changes: 1 addition & 1 deletion modules/src/ics23_commitment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl CommitmentPath {
where
P: Path,
{
todo!()
CommitmentPath{}
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
trivial_casts,
trivial_numeric_casts,
unused_import_braces,
unused_qualifications,
//unused_qualifications,
rust_2018_idioms
)]
#![allow(dead_code)]
Expand Down
144 changes: 144 additions & 0 deletions modules/src/proto/gogoproto/gogo.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// Protocol Buffers for Go with Gadgets
//
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
// http://github.com/gogo/protobuf
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

syntax = "proto2";
package gogoproto;

import "google/protobuf/descriptor.proto";

option java_package = "com.google.protobuf";
option java_outer_classname = "GoGoProtos";
option go_package = "github.com/gogo/protobuf/gogoproto";

extend google.protobuf.EnumOptions {
optional bool goproto_enum_prefix = 62001;
optional bool goproto_enum_stringer = 62021;
optional bool enum_stringer = 62022;
optional string enum_customname = 62023;
optional bool enumdecl = 62024;
}

extend google.protobuf.EnumValueOptions {
optional string enumvalue_customname = 66001;
}

extend google.protobuf.FileOptions {
optional bool goproto_getters_all = 63001;
optional bool goproto_enum_prefix_all = 63002;
optional bool goproto_stringer_all = 63003;
optional bool verbose_equal_all = 63004;
optional bool face_all = 63005;
optional bool gostring_all = 63006;
optional bool populate_all = 63007;
optional bool stringer_all = 63008;
optional bool onlyone_all = 63009;

optional bool equal_all = 63013;
optional bool description_all = 63014;
optional bool testgen_all = 63015;
optional bool benchgen_all = 63016;
optional bool marshaler_all = 63017;
optional bool unmarshaler_all = 63018;
optional bool stable_marshaler_all = 63019;

optional bool sizer_all = 63020;

optional bool goproto_enum_stringer_all = 63021;
optional bool enum_stringer_all = 63022;

optional bool unsafe_marshaler_all = 63023;
optional bool unsafe_unmarshaler_all = 63024;

optional bool goproto_extensions_map_all = 63025;
optional bool goproto_unrecognized_all = 63026;
optional bool gogoproto_import = 63027;
optional bool protosizer_all = 63028;
optional bool compare_all = 63029;
optional bool typedecl_all = 63030;
optional bool enumdecl_all = 63031;

optional bool goproto_registration = 63032;
optional bool messagename_all = 63033;

optional bool goproto_sizecache_all = 63034;
optional bool goproto_unkeyed_all = 63035;
}

extend google.protobuf.MessageOptions {
optional bool goproto_getters = 64001;
optional bool goproto_stringer = 64003;
optional bool verbose_equal = 64004;
optional bool face = 64005;
optional bool gostring = 64006;
optional bool populate = 64007;
optional bool stringer = 67008;
optional bool onlyone = 64009;

optional bool equal = 64013;
optional bool description = 64014;
optional bool testgen = 64015;
optional bool benchgen = 64016;
optional bool marshaler = 64017;
optional bool unmarshaler = 64018;
optional bool stable_marshaler = 64019;

optional bool sizer = 64020;

optional bool unsafe_marshaler = 64023;
optional bool unsafe_unmarshaler = 64024;

optional bool goproto_extensions_map = 64025;
optional bool goproto_unrecognized = 64026;

optional bool protosizer = 64028;
optional bool compare = 64029;

optional bool typedecl = 64030;

optional bool messagename = 64033;

optional bool goproto_sizecache = 64034;
optional bool goproto_unkeyed = 64035;
}

extend google.protobuf.FieldOptions {
optional bool nullable = 65001;
optional bool embed = 65002;
optional string customtype = 65003;
optional string customname = 65004;
optional string jsontag = 65005;
optional string moretags = 65006;
optional string casttype = 65007;
optional string castkey = 65008;
optional string castvalue = 65009;

optional bool stdtime = 65010;
optional bool stdduration = 65011;
optional bool wktpointer = 65012;

}
69 changes: 69 additions & 0 deletions modules/src/proto/ibc/commitment/commitment.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
syntax = "proto3";
package ibc.commitment;

option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types";

import "gogoproto/gogo.proto";
import "tendermint/crypto/proof.proto";

// MerkleRoot defines a merkle root hash.
// In the Cosmos SDK, the AppHash of a block header becomes the root.
message MerkleRoot {
option (gogoproto.goproto_getters) = false;

bytes hash = 1;
}

// 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 [(gogoproto.moretags) = "yaml:\"key_prefix\""];
}

// MerklePath is the path used to verify commitment proofs, which can be an arbitrary
// structured object (defined by a commitment type).
message MerklePath {
option (gogoproto.goproto_stringer) = false;

KeyPath key_path = 1 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"key_path\""
];
}

// MerkleProof is a wrapper type that contains a merkle proof.
// It demonstrates membership or non-membership for an element or set of elements,
// verifiable in conjunction with a known commitment root. Proofs should be
// succinct.
message MerkleProof {
option (gogoproto.equal) = true;

tendermint.crypto.Proof proof = 1;
}

// KeyPath defines a slice of keys
message KeyPath {
option (gogoproto.goproto_stringer) = false;
option (gogoproto.goproto_getters) = false;

repeated Key keys = 1;
}

// Key defines a proof Key
message Key {
option (gogoproto.goproto_getters) = false;

bytes name = 1 [(gogoproto.customname) = "name"];
KeyEncoding enc = 2 [(gogoproto.customname) = "enc"];
}

// KeyEncoding defines the encoding format of a key's bytes.
enum KeyEncoding {
option (gogoproto.goproto_enum_stringer) = false;
option (gogoproto.goproto_enum_prefix) = false;

// URL encoding
KEY_ENCODING_URL_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "URL"];
// Hex encoding
KEY_ENCODING_HEX = 1 [(gogoproto.enumvalue_customname) = "HEX"];
}
Loading