Skip to content

Commit

Permalink
Merge branch 'master' into aaronc/adr-fee-grant
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronc authored Aug 20, 2020
2 parents 1ba33d4 + 3368dae commit b43519d
Show file tree
Hide file tree
Showing 36 changed files with 4,180 additions and 994 deletions.
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,6 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
Expand Down
14 changes: 11 additions & 3 deletions proto/ibc/client/client.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ import "google/protobuf/any.proto";

// IdentifiedClientState defines a client state with additional client identifier field.
message IdentifiedClientState {
option (gogoproto.goproto_getters) = false;
// client identifier
string id = 1 [(gogoproto.moretags) = "yaml:\"id\""];
google.protobuf.Any client_state = 2;
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
// client state
google.protobuf.Any client_state = 2 [(gogoproto.moretags) = "yaml:\"client_state\""];
}

// ClientConsensusStates defines all the stored consensus states for a given client.
message ClientConsensusStates {
// client identifier
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
// consensus states associated with the client
repeated google.protobuf.Any consensus_states = 2 [(gogoproto.moretags) = "yaml:\"consensus_states\""];
}
33 changes: 8 additions & 25 deletions proto/ibc/client/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,19 @@ package ibc.client;

option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types";

import "ibc/client/client.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";

// GenesisClientState defines an identified ClientState as protobuf Any format.
message GenesisClientState {
string client_id = 1 [
(gogoproto.moretags) = "yaml:\"client_id\""
];
google.protobuf.Any client_state = 2 [(gogoproto.moretags) = "yaml:\"client_state\""];
}

// ClientConsensusStates defines all the stored consensus states for a given client.
message ClientConsensusStates {
string client_id = 1;
repeated google.protobuf.Any consensus_states = 2 [
(gogoproto.moretags) = "yaml:\"consensus_states\""
];
}

// GenesisState defines the ibc client submodule's genesis state.
message GenesisState {
repeated GenesisClientState clients = 1 [
(gogoproto.nullable) = false
];
// client states with their corresponding identifiers
repeated IdentifiedClientState clients = 1 [(gogoproto.nullable) = false];
// consensus states from each client
repeated ClientConsensusStates clients_consensus = 2 [
(gogoproto.nullable) = false,
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "ClientsConsensusStates",
(gogoproto.moretags) = "yaml:\"clients_consensus\""
];
bool create_localhost = 3 [
(gogoproto.moretags) = "yaml:\"create_localhost\""
(gogoproto.moretags) = "yaml:\"clients_consensus\""
];
// create localhost on initialization
bool create_localhost = 3 [(gogoproto.moretags) = "yaml:\"create_localhost\""];
}
108 changes: 108 additions & 0 deletions proto/ibc/client/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
syntax = "proto3";
package ibc.client;

import "cosmos/base/query/v1beta1/pagination.proto";
import "ibc/client/client.proto";
import "google/protobuf/any.proto";
import "google/api/annotations.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types";

// Query provides defines the gRPC querier service
service Query {
// ClientState queries an IBC light client.
rpc ClientState(QueryClientStateRequest) returns (QueryClientStateResponse) {
option (google.api.http).get = "/ibc/client/v1beta1/client_states/{client_id}";
}

// ClientStates queries all the IBC light clients of a chain.
rpc ClientStates(QueryClientStatesRequest) returns (QueryClientStatesResponse) {
option (google.api.http).get = "/ibc/client/v1beta1/client_states";
}

// ConsensusState queries a consensus state associated with a client state at a given height.
rpc ConsensusState(QueryConsensusStateRequest) returns (QueryConsensusStateResponse) {
option (google.api.http).get = "/ibc/client/v1beta1/consensus_states/{client_id}/{height}";
}

// ConsensusStates queries all the consensus state associated with a given client.
rpc ConsensusStates(QueryConsensusStatesRequest) returns (QueryConsensusStatesResponse) {
option (google.api.http).get = "/ibc/client/v1beta1/consensus_states/{client_id}";
}
}

// QueryClientStateRequest is the request type for the Query/ClientState RPC
// method
message QueryClientStateRequest {
// client state unique identifier
string client_id = 1;
}

// QueryClientStateResponse is the response type for the Query/ClientState RPC
// method. Besides the client state, it includes a proof and the height from
// which the proof was retrieved.
message QueryClientStateResponse {
// client state associated with the request identifier
google.protobuf.Any client_state = 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;
}

// QueryClientStatesRequest is the request type for the Query/ClientStates RPC
// method
message QueryClientStatesRequest {
// pagination request
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

// QueryClientStatesResponse is the response type for the Query/ClientStates RPC
// method.
message QueryClientStatesResponse {
// list of stored ClientStates of the chain.
repeated IdentifiedClientState client_states = 1;
// pagination response
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryConsensusStateRequest is the request type for the Query/ConsensusState RPC method. Besides
// the consensus state, it includes a proof and the height from which the proof was retrieved.
message QueryConsensusStateRequest {
// client identifier
string client_id = 1;
// consensus state height
uint64 height = 2;
// latest_height overrrides the height field and queries the latest stored ConsensusState
bool latest_height = 3;
}

// QueryConsensusStateResponse is the response type for the Query/ConsensusState RPC method
message QueryConsensusStateResponse {
// consensus state associated with the client identifier at the given height
google.protobuf.Any consensus_state = 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;
}

// QueryConsensusStatesRequest is the request type for the Query/ConsensusStates RPC method.
message QueryConsensusStatesRequest {
// client identifier
string client_id = 1;
// pagination request
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

// QueryConsensusStatesResponse is the response type for the Query/ConsensusStates RPC method
message QueryConsensusStatesResponse {
// consensus states associated with the identifier
repeated google.protobuf.Any consensus_states = 1;
// pagination response
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
1 change: 1 addition & 0 deletions x/ibc/02-client/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func GetQueryCmd() *cobra.Command {
queryCmd.AddCommand(
GetCmdQueryClientStates(),
GetCmdQueryClientState(),
GetCmdQueryConsensusStates(),
GetCmdQueryConsensusState(),
GetCmdQueryHeader(),
GetCmdNodeConsensusState(),
Expand Down
112 changes: 83 additions & 29 deletions x/ibc/02-client/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package cli

import (
"context"
"errors"
"fmt"
"strconv"
"strings"

"github.com/spf13/cobra"

Expand All @@ -16,6 +16,8 @@ import (
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
)

const flagLatestHeight = "latest-height"

// GetCmdQueryClientStates defines the command to query all the light clients
// that this chain mantains.
func GetCmdQueryClientStates() *cobra.Command {
Expand All @@ -32,23 +34,27 @@ func GetCmdQueryClientStates() *cobra.Command {
return err
}

page, _ := cmd.Flags().GetInt(flags.FlagPage)
limit, _ := cmd.Flags().GetInt(flags.FlagLimit)
queryClient := types.NewQueryClient(clientCtx)

clientStates, height, err := utils.QueryAllClientStates(clientCtx, page, limit)
pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}

clientCtx = clientCtx.WithHeight(height)
req := &types.QueryClientStatesRequest{
Pagination: pageReq,
}

res, err := queryClient.ClientStates(context.Background(), req)
if err != nil {
return err
}

return clientCtx.PrintOutputLegacy(clientStates)
return clientCtx.PrintOutput(res)
},
}

cmd.Flags().Int(flags.FlagPage, 1, "pagination page of light clients to query for")
cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit of light clients to query for")
flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "client states")

return cmd
}
Expand All @@ -70,19 +76,14 @@ func GetCmdQueryClientState() *cobra.Command {
}

clientID := args[0]
if strings.TrimSpace(clientID) == "" {
return errors.New("client ID can't be blank")
}

prove, _ := cmd.Flags().GetBool(flags.FlagProve)

clientStateRes, err := utils.QueryClientState(clientCtx, clientID, prove)
if err != nil {
return err
}

clientCtx = clientCtx.WithHeight(int64(clientStateRes.ProofHeight))
return clientCtx.PrintOutputLegacy(clientStateRes)
return clientCtx.PrintOutput(clientStateRes)
},
}

Expand All @@ -92,15 +93,60 @@ func GetCmdQueryClientState() *cobra.Command {
return cmd
}

// GetCmdQueryConsensusStates defines the command to query all the consensus states from a given
// client state.
func GetCmdQueryConsensusStates() *cobra.Command {
cmd := &cobra.Command{
Use: "consensus-states [client-id]",
Short: "Query all the consensus states of a client.",
Long: "Query all the consensus states from a given client state.",
Example: fmt.Sprintf("%s query %s %s consensus-states [client-id]", version.AppName, host.ModuleName, types.SubModuleName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}

clientID := args[0]

queryClient := types.NewQueryClient(clientCtx)

pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}

req := &types.QueryConsensusStatesRequest{
ClientId: clientID,
Pagination: pageReq,
}

res, err := queryClient.ConsensusStates(context.Background(), req)
if err != nil {
return err
}

return clientCtx.PrintOutput(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "consensus states")

return cmd
}

// GetCmdQueryConsensusState defines the command to query the consensus state of
// the chain as defined in https://github.com/cosmos/ics/tree/master/spec/ics-002-client-semantics#query
func GetCmdQueryConsensusState() *cobra.Command {
cmd := &cobra.Command{
Use: "consensus-state [client-id] [height]",
Short: "Query the consensus state of a client at a given height",
Long: "Query the consensus state for a particular light client at a given height",
Use: "consensus-state [client-id] [height]",
Short: "Query the consensus state of a client at a given height",
Long: `Query the consensus state for a particular light client at a given height.
If the '--latest' flag is included, the query returns the latest consensus state, overriding the height argument.`,
Example: fmt.Sprintf("%s query %s %s consensus-state [client-id] [height]", version.AppName, host.ModuleName, types.SubModuleName),
Args: cobra.ExactArgs(2),
Args: cobra.RangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
Expand All @@ -109,28 +155,35 @@ func GetCmdQueryConsensusState() *cobra.Command {
}

clientID := args[0]
if strings.TrimSpace(clientID) == "" {
return errors.New("client ID can't be blank")
}

height, err := strconv.ParseUint(args[1], 10, 64)
if err != nil {
return fmt.Errorf("expected integer height, got: %s", args[1])
queryLatestHeight, _ := cmd.Flags().GetBool(flagLatestHeight)

var height uint64

if !queryLatestHeight {
if len(args) != 2 {
return errors.New("must include a second 'height' argument when '--latest-height' flag is not provided")
}

height, err = strconv.ParseUint(args[1], 10, 64)
if err != nil {
return fmt.Errorf("expected integer height, got: %s", args[1])
}
}

prove, _ := cmd.Flags().GetBool(flags.FlagProve)

csRes, err := utils.QueryConsensusState(clientCtx, clientID, height, prove)
csRes, err := utils.QueryConsensusState(clientCtx, clientID, height, prove, queryLatestHeight)
if err != nil {
return err
}

clientCtx = clientCtx.WithHeight(int64(csRes.ProofHeight))
return clientCtx.PrintOutputLegacy(csRes)
return clientCtx.PrintOutput(csRes)
},
}

cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results")
cmd.Flags().Bool(flagLatestHeight, false, "return latest stored consensus state")
flags.AddQueryFlagsToCmd(cmd)

return cmd
Expand All @@ -143,6 +196,7 @@ func GetCmdQueryHeader() *cobra.Command {
Short: "Query the latest header of the running chain",
Long: "Query the latest Tendermint header of the running chain",
Example: fmt.Sprintf("%s query %s %s header", version.AppName, host.ModuleName, types.SubModuleName),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
Expand Down Expand Up @@ -173,7 +227,7 @@ func GetCmdNodeConsensusState() *cobra.Command {
Short: "Query a node consensus state",
Long: "Query a node consensus state. This result is feed to the client creation transaction.",
Example: fmt.Sprintf("%s query %s %s node-state", version.AppName, host.ModuleName, types.SubModuleName),
Args: cobra.ExactArgs(0),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
Expand Down
Loading

0 comments on commit b43519d

Please sign in to comment.