Skip to content

Commit

Permalink
x/ibc: gRPC query service (#6466)
Browse files Browse the repository at this point in the history
* x/ibc: gRPC query service

* fixes

* connection updates

* register channel query service

* update clients

* change proofs to bytes

* implement additional channel grpc queries

* unrelayed packets query

* query.proto files

* move next sequence recv query to channel client

* update REST

* wip test

* add missing cli queries

* install the right tools

* fixes

* build

* lint

* use gRPC when query proof is not requested

* connection gRPC tests

* IBC query server interface

* more gRPC channel tests

* pagination tests

* connection use query server

* connection pagination tests

* channel pagination tests

* typo

* remove buf

* Update x/ibc/03-connection/keeper/grpc_query_test.go

Co-authored-by: colin axner <25233464+colin-axner@users.noreply.github.com>

* address comments from review

* fix tests

* unrelayed packet sequences flag

* remove ClientsConnections query

* fix

Co-authored-by: colin axner <25233464+colin-axner@users.noreply.github.com>
  • Loading branch information
fedekunze and colin-axner committed Jul 6, 2020
1 parent 2f44fbf commit f35e3b2
Show file tree
Hide file tree
Showing 49 changed files with 9,828 additions and 1,601 deletions.
103 changes: 70 additions & 33 deletions proto/ibc/channel/channel.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,32 @@ message MsgChannelOpenInit {
// MsgChannelOpenInit defines a msg sent by a Relayer to try to open a channel
// on Chain B.
message MsgChannelOpenTry {
string port_id = 1 [(gogoproto.customname) = "PortID", (gogoproto.moretags) = "yaml:\"port_id\""];
string channel_id = 2 [(gogoproto.customname) = "ChannelID", (gogoproto.moretags) = "yaml:\"channel_id\""];
Channel channel = 3 [(gogoproto.nullable) = false];
string counterparty_version = 4 [(gogoproto.moretags) = "yaml:\"counterparty_version\""];
bytes proof_init = 5 [(gogoproto.moretags) = "yaml:\"proof_init\""];
uint64 proof_height = 6 [(gogoproto.moretags) = "yaml:\"proof_height\""];
bytes signer = 7 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
string port_id = 1 [(gogoproto.customname) = "PortID", (gogoproto.moretags) = "yaml:\"port_id\""];
string channel_id = 2 [(gogoproto.customname) = "ChannelID", (gogoproto.moretags) = "yaml:\"channel_id\""];
Channel channel = 3 [(gogoproto.nullable) = false];
string counterparty_version = 4 [(gogoproto.moretags) = "yaml:\"counterparty_version\""];
bytes proof_init = 5 [(gogoproto.moretags) = "yaml:\"proof_init\""];
uint64 proof_height = 6 [(gogoproto.moretags) = "yaml:\"proof_height\""];
bytes signer = 7 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}

// MsgChannelOpenAck defines a msg sent by a Relayer to Chain A to acknowledge
// the change of channel state to TRYOPEN on Chain B.
message MsgChannelOpenAck {
string port_id = 1 [(gogoproto.customname) = "PortID", (gogoproto.moretags) = "yaml:\"port_id\""];
string channel_id = 2 [(gogoproto.customname) = "ChannelID", (gogoproto.moretags) = "yaml:\"channel_id\""];
string counterparty_version = 3 [(gogoproto.moretags) = "yaml:\"counterparty_version\""];
bytes proof_try = 4 [(gogoproto.moretags) = "yaml:\"proof_try\""];
uint64 proof_height = 5 [(gogoproto.moretags) = "yaml:\"proof_height\""];
bytes signer = 6 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
string port_id = 1 [(gogoproto.customname) = "PortID", (gogoproto.moretags) = "yaml:\"port_id\""];
string channel_id = 2 [(gogoproto.customname) = "ChannelID", (gogoproto.moretags) = "yaml:\"channel_id\""];
string counterparty_version = 3 [(gogoproto.moretags) = "yaml:\"counterparty_version\""];
bytes proof_try = 4 [(gogoproto.moretags) = "yaml:\"proof_try\""];
uint64 proof_height = 5 [(gogoproto.moretags) = "yaml:\"proof_height\""];
bytes signer = 6 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}

// MsgChannelOpenConfirm defines a msg sent by a Relayer to Chain B to acknowledge
// the change of channel state to OPEN on Chain A.
message MsgChannelOpenConfirm {
string port_id = 1 [(gogoproto.customname) = "PortID", (gogoproto.moretags) = "yaml:\"port_id\""];
string channel_id = 2 [(gogoproto.customname) = "ChannelID", (gogoproto.moretags) = "yaml:\"channel_id\""];
bytes proof_ack = 3 [(gogoproto.moretags) = "yaml:\"proof_ack\""];
string port_id = 1 [(gogoproto.customname) = "PortID", (gogoproto.moretags) = "yaml:\"port_id\""];
string channel_id = 2 [(gogoproto.customname) = "ChannelID", (gogoproto.moretags) = "yaml:\"channel_id\""];
bytes proof_ack = 3 [(gogoproto.moretags) = "yaml:\"proof_ack\""];
uint64 proof_height = 4 [(gogoproto.moretags) = "yaml:\"proof_height\""];
bytes signer = 5 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}
Expand All @@ -58,37 +58,37 @@ message MsgChannelCloseInit {
// MsgChannelCloseConfirm defines a msg sent by a Relayer to Chain B
// to acknowledge the change of channel state to CLOSED on Chain A.
message MsgChannelCloseConfirm {
string port_id = 1 [(gogoproto.customname) = "PortID", (gogoproto.moretags) = "yaml:\"port_id\""];
string channel_id = 2 [(gogoproto.customname) = "ChannelID", (gogoproto.moretags) = "yaml:\"channel_id\""];
bytes proof_init = 3 [(gogoproto.moretags) = "yaml:\"proof_init\""];
string port_id = 1 [(gogoproto.customname) = "PortID", (gogoproto.moretags) = "yaml:\"port_id\""];
string channel_id = 2 [(gogoproto.customname) = "ChannelID", (gogoproto.moretags) = "yaml:\"channel_id\""];
bytes proof_init = 3 [(gogoproto.moretags) = "yaml:\"proof_init\""];
uint64 proof_height = 4 [(gogoproto.moretags) = "yaml:\"proof_height\""];
bytes signer = 5 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}

// MsgPacket receives incoming IBC packet
message MsgPacket {
Packet packet = 1 [(gogoproto.nullable) = false];
bytes proof = 2;
uint64 proof_height = 3 [(gogoproto.moretags) = "yaml:\"proof_height\""];
bytes signer = 4 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
Packet packet = 1 [(gogoproto.nullable) = false];
bytes proof = 2;
uint64 proof_height = 3 [(gogoproto.moretags) = "yaml:\"proof_height\""];
bytes signer = 4 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}

// MsgTimeout receives timed-out packet
message MsgTimeout {
Packet packet = 1 [(gogoproto.nullable) = false];
bytes proof = 2;
uint64 proof_height = 3 [(gogoproto.moretags) = "yaml:\"proof_height\""];
uint64 next_sequence_recv = 4 [(gogoproto.moretags) = "yaml:\"next_sequence_recv\""];
bytes signer = 5 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
Packet packet = 1 [(gogoproto.nullable) = false];
bytes proof = 2;
uint64 proof_height = 3 [(gogoproto.moretags) = "yaml:\"proof_height\""];
uint64 next_sequence_recv = 4 [(gogoproto.moretags) = "yaml:\"next_sequence_recv\""];
bytes signer = 5 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}

// MsgAcknowledgement receives incoming IBC acknowledgement
message MsgAcknowledgement {
Packet packet = 1 [(gogoproto.nullable) = false];
bytes acknowledgement = 2;
bytes proof = 3;
uint64 proof_height = 4 [(gogoproto.moretags) = "yaml:\"proof_height\""];
bytes signer = 5 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
Packet packet = 1 [(gogoproto.nullable) = false];
bytes acknowledgement = 2;
bytes proof = 3;
uint64 proof_height = 4 [(gogoproto.moretags) = "yaml:\"proof_height\""];
bytes signer = 5 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}

// Channel defines pipeline for exactly-once packet delivery between specific
Expand All @@ -110,6 +110,28 @@ message Channel {
string version = 5;
}

// IdentifiedChannel defines a channel with additional port and channel identifier
// fields.
message IdentifiedChannel {
option (gogoproto.goproto_getters) = false;

// current state of the channel end
State state = 1;
// whether the channel is ordered or unordered
Order ordering = 2;
// counterparty channel end
Counterparty counterparty = 3 [(gogoproto.nullable) = false];
// list of connection identifiers, in order, along which packets sent on this
// channel will travel
repeated string connection_hops = 4 [(gogoproto.moretags) = "yaml:\"connection_hops\""];
// opaque channel version, which is agreed upon during the handshake
string version = 5;
// port identifier
string port_id = 6 [(gogoproto.customname) = "PortID"];
// channel identifier
string channel_id = 7 [(gogoproto.customname) = "ChannelID"];
}

// State defines if a channel is in one of the following states:
// CLOSED, INIT, TRYOPEN, OPEN or UNINITIALIZED.
enum State {
Expand Down Expand Up @@ -173,3 +195,18 @@ message Packet {
// block timestamp (in nanoseconds) after which the packet times out
uint64 timeout_timestamp = 8 [(gogoproto.moretags) = "yaml:\"timeout_timestamp\""];
}

// PacketAckCommitment defines the genesis type necessary to retrieve and store
// acknowlegements.
message PacketAckCommitment {
option (gogoproto.goproto_getters) = false;

// channel port identifier.
string port_id = 1 [(gogoproto.customname) = "PortID", (gogoproto.moretags) = "yaml:\"port_id\""];
// channel unique identifier.
string channel_id = 2 [(gogoproto.customname) = "ChannelID", (gogoproto.moretags) = "yaml:\"channel_id\""];
// packet sequence.
uint64 sequence = 3;
// packet commitment hash.
bytes hash = 4;
}
183 changes: 183 additions & 0 deletions proto/ibc/channel/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
syntax = "proto3";
package ibc.channel;

import "gogoproto/gogo.proto";
import "cosmos/query/pagination.proto";
import "ibc/channel/channel.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types";

// Query provides defines the gRPC querier service
service Query {
// Channel queries an IBC Channel.
rpc Channel(QueryChannelRequest) returns (QueryChannelResponse) {}

// Channels queries all the IBC channels of a chain.
rpc Channels(QueryChannelsRequest) returns (QueryChannelsResponse) {}

// ConnectionChannels queries all the channels associated with a connection end.
rpc ConnectionChannels(QueryConnectionChannelsRequest) returns (QueryConnectionChannelsResponse) {}

// PacketCommitment queries a stored packet commitment hash.
rpc PacketCommitment(QueryPacketCommitmentRequest) returns (QueryPacketCommitmentResponse) {}

// PacketCommitments returns the all the packet commitments hashes associated with a channel.
rpc PacketCommitments(QueryPacketCommitmentsRequest) returns (QueryPacketCommitmentsResponse) {}

// UnrelayedPackets returns all the unrelayed IBC packets associated with a channel and sequences.
rpc UnrelayedPackets(QueryUnrelayedPacketsRequest) returns (QueryUnrelayedPacketsResponse) {}

// NextSequenceReceive returns the next receive sequence for a given channel
rpc NextSequenceReceive(QueryNextSequenceReceiveRequest) returns (QueryNextSequenceReceiveResponse) {}

// TODO: blocked by client proto migration
// rpc ChannelClientState(QueryChannelClientStateRequest) returns (QueryChannelClientStateRequest) {}
}

// QueryChannelRequest is the request type for the Query/Channel RPC method
message QueryChannelRequest {
// port unique identifier
string port_id = 1 [(gogoproto.customname) = "PortID"];
// channel unique identifier
string channel_id = 2 [(gogoproto.customname) = "ChannelID"];
}

// QueryChannelResponse is the response type for the Query/Channel RPC method.
// Besides the Channel end, it includes a proof and the height from which the
// proof was retrieved.
message QueryChannelResponse {
// channel associated with the request identifiers
ibc.channel.Channel channel = 1;
// merkle proof of existence
bytes proof = 2;
// merkle proof path
string proof_path = 3;
// height at which the proof was retrieved
uint64 proof_height = 4;
}

// QueryChannelsRequest is the request type for the Query/Channels RPC method
message QueryChannelsRequest {
// pagination request
cosmos.query.PageRequest req = 1;
}

// QueryChannelsResponse is the response type for the Query/Channels RPC method.
message QueryChannelsResponse {
// list of stored channels of the chain.
repeated ibc.channel.IdentifiedChannel channels = 1;
// pagination response
cosmos.query.PageResponse res = 2;
// query block height
int64 height = 3;
}

// QueryConnectionChannelsRequest is the request type for the Query/QueryConnectionChannels RPC method
message QueryConnectionChannelsRequest {
// connection unique identifier
string connection = 1;
// pagination request
cosmos.query.PageRequest req = 2;
}

// QueryConnectionChannelsResponse is the Response type for the Query/QueryConnectionChannels RPC method
message QueryConnectionChannelsResponse {
// list of channels associated with a connection.
repeated ibc.channel.IdentifiedChannel channels = 1;
// pagination response
cosmos.query.PageResponse res = 2;
// query block height
int64 height = 3;
}

// QueryPacketCommitmentRequest is the request type for the Query/PacketCommitment RPC method
message QueryPacketCommitmentRequest {
// port unique identifier
string port_id = 1 [(gogoproto.customname) = "PortID"];
// channel unique identifier
string channel_id = 2 [(gogoproto.customname) = "ChannelID"];
// packet sequence
uint64 sequence = 3;
}

// QueryPacketCommitmentResponse defines the client query response for a packet which also
// includes a proof, its path and the height form which the proof was retrieved
message QueryPacketCommitmentResponse {
// packet associated with the request fields
bytes commitment = 1;
// merkle proof of existence
bytes proof = 2;
// merkle proof path
string proof_path = 3;
// height at which the proof was retrieved
uint64 proof_height = 4;
}

// QueryPacketCommitmentsRequest is the request type for the Query/QueryPacketCommitments RPC method
message QueryPacketCommitmentsRequest {
// port unique identifier
string port_id = 1 [(gogoproto.customname) = "PortID"];
// channel unique identifier
string channel_id = 2 [(gogoproto.customname) = "ChannelID"];
// pagination request
cosmos.query.PageRequest req = 3;
}

// QueryPacketCommitmentsResponse is the request type for the Query/QueryPacketCommitments RPC method
message QueryPacketCommitmentsResponse {
repeated ibc.channel.PacketAckCommitment commitments = 1;
// pagination response
cosmos.query.PageResponse res = 2;
// query block height
int64 height = 3;
}

// QueryUnrelayedPacketsRequest is the request type for the Query/QueryConnectionChannels RPC method
message QueryUnrelayedPacketsRequest {
// port unique identifier
string port_id = 1 [(gogoproto.customname) = "PortID"];
// channel unique identifier
string channel_id = 2 [(gogoproto.customname) = "ChannelID"];
// list of packet sequences
repeated uint64 sequences = 3;
// pagination request
cosmos.query.PageRequest req = 4;
}

// QueryUnrelayedPacketsResponse is the request type for the Query/QueryConnectionChannels RPC method
message QueryUnrelayedPacketsResponse {
// list of unrelayed packets sequences
repeated uint64 packets = 1;
// pagination response
cosmos.query.PageResponse res = 2;
// query block height
int64 height = 3;
}

// QueryNextSequenceReceiveRequest is the request type for the Query/QueryNextSequenceReceiveRequest RPC method
message QueryNextSequenceReceiveRequest {
// port unique identifier
string port_id = 1 [(gogoproto.customname) = "PortID"];
// channel unique identifier
string channel_id = 2 [(gogoproto.customname) = "ChannelID"];
}

// QuerySequenceResponse is the request type for the Query/QueryNextSequenceReceiveResponse RPC method
message QueryNextSequenceReceiveResponse {
// next sequence receive number
uint64 next_sequence_receive = 1;
// merkle proof of existence
bytes proof = 2;
// merkle proof path
string proof_path = 3;
// height at which the proof was retrieved
uint64 proof_height = 4;
}

// QueryChannelClientStateRequest is the request type for the Query/ClientState RPC method
message QueryChannelClientStateRequest {
// port unique identifier
string port_id = 1 [(gogoproto.customname) = "PortID"];
// channel unique identifier
string channel_id = 2 [(gogoproto.customname) = "ChannelID"];
}
11 changes: 10 additions & 1 deletion proto/ibc/connection/connection.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ message MsgConnectionOpenTry {
Counterparty counterparty = 3 [(gogoproto.nullable) = false];
repeated string counterparty_versions = 4 [(gogoproto.moretags) = "yaml:\"counterparty_versions\""];
// proof of the initialization the connection on Chain A: `UNITIALIZED -> INIT`
bytes proof_init = 5 [(gogoproto.moretags) = "yaml:\"proof_init\""];
bytes proof_init = 5 [(gogoproto.moretags) = "yaml:\"proof_init\""];
uint64 proof_height = 6;
// proof of client consensus state
bytes proof_consensus = 7
Expand Down Expand Up @@ -110,5 +110,14 @@ message Counterparty {

// ClientPaths define all the connection paths for a client state.
message ClientPaths {
// list of connection paths
repeated string paths = 1;
}

// ConnectionPaths define all the connection paths for a given client state.
message ConnectionPaths {
// client state unique identifier
string client_id = 1 [(gogoproto.customname) = "ClientID", (gogoproto.moretags) = "yaml:\"client_id\""];
// list of connection paths
repeated string paths = 2;
}
Loading

0 comments on commit f35e3b2

Please sign in to comment.