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

ICS07 Tendermint Client implementation #5485

Merged
merged 39 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a32d4b9
implement ICS07
fedekunze Jan 6, 2020
c2e66b8
build
fedekunze Jan 6, 2020
7705818
update tests and cleanup
fedekunze Jan 6, 2020
6404caa
x/ibc/02-client/types: remove misbehaviour in favor of evidence
fedekunze Jan 7, 2020
062b748
remove root query, update queriers, implement verification funcs
fedekunze Jan 8, 2020
2126cc8
remove committer; cleanup
fedekunze Jan 8, 2020
1b17735
move keys to ibc/types
fedekunze Jan 14, 2020
4a53fc1
Merge branch 'ibc-alpha' of https://github.com/cosmos/cosmos-sdk into…
fedekunze Jan 14, 2020
9c15f5d
fix paths
fedekunze Jan 14, 2020
9a4a93d
update ICS03 connection verification
fedekunze Jan 15, 2020
4db2bdf
move order and states to exported pkg
fedekunze Jan 16, 2020
3fc142f
update ICS04 to latest spec
fedekunze Jan 16, 2020
592a1ff
Merge branch 'ibc-alpha' of https://github.com/cosmos/cosmos-sdk into…
fedekunze Jan 16, 2020
32160b9
fix build
fedekunze Jan 16, 2020
944fec8
move ics02 types/errors package to /types
fedekunze Jan 16, 2020
3d48b9b
update a few tests
fedekunze Jan 16, 2020
c1de08b
update tests; fix codec registration
fedekunze Jan 17, 2020
bbd9826
merge ibc-alpha
fedekunze Jan 20, 2020
959a4f5
minor changes from code review
fedekunze Jan 20, 2020
dd899bc
ibc/client/types: fix tests
fedekunze Jan 20, 2020
f285fa1
ibc/02-client/keeper: fix tests
fedekunze Jan 20, 2020
4561d8f
ibc/03-connection/keeper: begin tests for verify.go
fedekunze Jan 20, 2020
613d522
ibc/23-commitment: add IsEmpty() to Prefix, Path and Proof
fedekunze Jan 21, 2020
b7e1dce
address comments from review
fedekunze Jan 21, 2020
0073060
add tests for evidence
fedekunze Jan 21, 2020
c9fadfa
x/ibc/07-tendermint: add tests for consensus state, header and update
fedekunze Jan 21, 2020
8e18839
ibc/07-tendermint: fix verification panic and add tests
fedekunze Jan 22, 2020
32189d1
ibc/07-tendermint: add failure test cases
fedekunze Jan 22, 2020
9a06451
x/ibc/03-connection/keeper: add verification tests for failing cases
fedekunze Jan 23, 2020
c889f3d
remove unused queriers
fedekunze Jan 23, 2020
8db8eea
Update ICS 7 tests (#5556)
cwgoes Jan 23, 2020
d8e237d
add TODOs for ADR 03 dynamic store
fedekunze Jan 23, 2020
2256db7
add tests for msgs and packet (#5559)
cwgoes Jan 23, 2020
5a3f3fc
use app.Commit for tests
fedekunze Jan 23, 2020
aa5c3d9
Merge branch 'fedekunze/5476-ics-07-tendermint' of https://github.com…
fedekunze Jan 23, 2020
0eccd5e
update verify.go
fedekunze Jan 23, 2020
1fa0ad0
Fix all ICS 07 Tests (#5565)
jackzampolin Jan 27, 2020
0f1b1d7
cleanup comments and add a few tests
fedekunze Jan 27, 2020
ddf6a25
typo
fedekunze Jan 27, 2020
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
73 changes: 26 additions & 47 deletions x/ibc/02-client/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,36 @@ package client
import (
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/keeper"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types/errors"
)

const (
AttributeKeyClientID = types.AttributeKeyClientID
SubModuleName = types.SubModuleName
StoreKey = types.StoreKey
RouterKey = types.RouterKey
QuerierRoute = types.QuerierRoute
QueryAllClients = types.QueryAllClients
QueryClientState = types.QueryClientState
QueryConsensusState = types.QueryConsensusState
QueryVerifiedRoot = types.QueryVerifiedRoot
AttributeKeyClientID = types.AttributeKeyClientID
AttrbuteKeyClientType = types.AttributeKeyClientType
SubModuleName = types.SubModuleName
RouterKey = types.RouterKey
QuerierRoute = types.QuerierRoute
QueryAllClients = types.QueryAllClients
QueryClientState = types.QueryClientState
QueryConsensusState = types.QueryConsensusState
)

var (
// functions aliases
NewKeeper = keeper.NewKeeper
QuerierClients = keeper.QuerierClients
QuerierClientState = keeper.QuerierClientState
QuerierConsensusState = keeper.QuerierConsensusState
QuerierVerifiedRoot = keeper.QuerierVerifiedRoot
RegisterCodec = types.RegisterCodec
ErrClientExists = errors.ErrClientExists
ErrClientNotFound = errors.ErrClientNotFound
ErrClientFrozen = errors.ErrClientFrozen
ErrConsensusStateNotFound = errors.ErrConsensusStateNotFound
ErrInvalidConsensus = errors.ErrInvalidConsensus
ErrClientTypeNotFound = errors.ErrClientTypeNotFound
ErrInvalidClientType = errors.ErrInvalidClientType
ErrRootNotFound = errors.ErrRootNotFound
ErrInvalidHeader = errors.ErrInvalidHeader
ErrInvalidEvidence = errors.ErrInvalidEvidence
ClientStatePath = types.ClientStatePath
ClientTypePath = types.ClientTypePath
ConsensusStatePath = types.ConsensusStatePath
RootPath = types.RootPath
KeyClientState = types.KeyClientState
KeyClientType = types.KeyClientType
KeyConsensusState = types.KeyConsensusState
KeyRoot = types.KeyRoot
NewMsgCreateClient = types.NewMsgCreateClient
NewMsgUpdateClient = types.NewMsgUpdateClient
NewMsgSubmitMibehaviour = types.NewMsgSubmitMisbehaviour
NewQueryClientStateParams = types.NewQueryClientStateParams
NewQueryCommitmentRootParams = types.NewQueryCommitmentRootParams
NewClientState = types.NewClientState
NewKeeper = keeper.NewKeeper
QuerierClients = keeper.QuerierClients
RegisterCodec = types.RegisterCodec
ErrClientExists = types.ErrClientExists
ErrClientNotFound = types.ErrClientNotFound
ErrClientFrozen = types.ErrClientFrozen
ErrConsensusStateNotFound = types.ErrConsensusStateNotFound
ErrInvalidConsensus = types.ErrInvalidConsensus
ErrClientTypeNotFound = types.ErrClientTypeNotFound
ErrInvalidClientType = types.ErrInvalidClientType
ErrRootNotFound = types.ErrRootNotFound
ErrInvalidHeader = types.ErrInvalidHeader
ErrInvalidEvidence = types.ErrInvalidEvidence
NewMsgCreateClient = types.NewMsgCreateClient
NewMsgUpdateClient = types.NewMsgUpdateClient

// variable aliases
SubModuleCdc = types.SubModuleCdc
Expand All @@ -65,11 +48,7 @@ var (
)

type (
Keeper = keeper.Keeper
MsgCreateClient = types.MsgCreateClient
MsgUpdateClient = types.MsgUpdateClient
MsgSubmitMisbehaviour = types.MsgSubmitMisbehaviour
QueryClientStateParams = types.QueryClientStateParams
QueryCommitmentRootParams = types.QueryCommitmentRootParams
State = types.State
Keeper = keeper.Keeper
MsgCreateClient = types.MsgCreateClient
MsgUpdateClient = types.MsgUpdateClient
)
2 changes: 1 addition & 1 deletion x/ibc/02-client/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
GetCmdQueryClientStates(queryRoute, cdc),
GetCmdQueryClientState(queryRoute, cdc),
GetCmdQueryConsensusState(queryRoute, cdc),
GetCmdQueryRoot(queryRoute, cdc),
GetCmdQueryHeader(cdc),
GetCmdNodeConsensusState(queryRoute, cdc),
GetCmdQueryPath(queryRoute, cdc),
Expand All @@ -40,6 +39,7 @@ func GetTxCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
ics02ClientTxCmd.AddCommand(flags.PostCommands(
GetCmdCreateClient(cdc),
GetCmdUpdateClient(cdc),
GetCmdSubmitMisbehaviour(cdc),
)...)

return ics02ClientTxCmd
Expand Down
90 changes: 8 additions & 82 deletions x/ibc/02-client/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,85 +88,11 @@ $ %s query ibc client state [client-id]
// the chain as defined in https://github.com/cosmos/ics/tree/master/spec/ics-002-client-semantics#query
func GetCmdQueryConsensusState(queryRoute string, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "consensus-state [client-id]",
Short: "Query the latest consensus state of the client",
Long: "Query the consensus state for a particular light client",
Example: fmt.Sprintf("%s query ibc client consensus-state [client-id]", version.ClientName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
clientID := args[0]
if strings.TrimSpace(clientID) == "" {
return errors.New("client ID can't be blank")
}

prove := viper.GetBool(flags.FlagProve)

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

return cliCtx.PrintOutput(csRes)
},
}
cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results")
return cmd
}

// GetCmdQueryRoot defines the command to query a verified commitment root
func GetCmdQueryRoot(queryRoute string, cdc *codec.Codec) *cobra.Command {
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
cmd := &cobra.Command{
Use: "root [client-id] [height]",
Short: "Query a verified commitment root",
Long: strings.TrimSpace(
fmt.Sprintf(`Query an already verified commitment root at a specific height for a particular client

Example:
$ %s query ibc client root [client-id] [height]
`, version.ClientName),
),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
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: %v", args[1])
}

prove := viper.GetBool(flags.FlagProve)

rootRes, err := utils.QueryCommitmentRoot(cliCtx, clientID, height, prove)
if err != nil {
return err
}

return cliCtx.PrintOutput(rootRes)
},
}
cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results")
return cmd
}

// GetCmdQueryCommitter defines the command to query the committer of the chain
// at a given height
func GetCmdQueryCommitter(queryRoute string, cdc *codec.Codec) *cobra.Command {
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
cmd := &cobra.Command{
Use: "committer [client-id] [height]",
Short: "Query a committer",
Long: strings.TrimSpace(
fmt.Sprintf(`Query a committer at a specific height for a particular client

Example:
$ %s query ibc client committer [client-id] [height]
`, version.ClientName),
),
Args: cobra.ExactArgs(2),
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",
Example: fmt.Sprintf("%s query ibc client consensus-state [client-id] [height]", version.ClientName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
clientID := args[0]
Expand All @@ -176,17 +102,17 @@ $ %s query ibc client committer [client-id] [height]

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

prove := viper.GetBool(flags.FlagProve)

committerRes, err := utils.QueryCommitter(cliCtx, clientID, height, prove)
csRes, err := utils.QueryConsensusState(cliCtx, clientID, height, prove)
if err != nil {
return err
}

return cliCtx.PrintOutput(committerRes)
return cliCtx.PrintOutput(csRes)
},
}
cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results")
Expand Down
21 changes: 9 additions & 12 deletions x/ibc/02-client/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/pkg/errors"
Expand All @@ -18,6 +17,7 @@ import (
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
"github.com/cosmos/cosmos-sdk/x/evidence"
evidenceexported "github.com/cosmos/cosmos-sdk/x/evidence/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
Expand Down Expand Up @@ -118,36 +118,33 @@ $ %s tx ibc client update [client-id] [path/to/header.json] --from node0 --home
// https://github.com/cosmos/ics/tree/master/spec/ics-002-client-semantics#misbehaviour
func GetCmdSubmitMisbehaviour(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "misbehaviour [client-it] [path/to/evidence.json]",
Use: "misbehaviour [path/to/evidence.json]",
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
Short: "submit a client misbehaviour",
Long: strings.TrimSpace(fmt.Sprintf(`submit a client misbehaviour to invalidate to invalidate previous state roots and prevent future updates:

Example:
$ %s tx ibc client misbehaviour [client-id] [path/to/evidence.json] --from node0 --home ../node0/<app>cli --chain-id $CID
$ %s tx ibc client misbehaviour [path/to/evidence.json] --from node0 --home ../node0/<app>cli --chain-id $CID
`, version.ClientName),
),
Args: cobra.ExactArgs(2),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc)

clientID := args[0]

var evidence evidenceexported.Evidence
if err := cdc.UnmarshalJSON([]byte(args[1]), &evidence); err != nil {
fmt.Fprintf(os.Stderr, "failed to unmarshall input into struct, checking for file...")
var ev evidenceexported.Evidence
if err := cdc.UnmarshalJSON([]byte(args[0]), &ev); err != nil {
// check for file path if JSON input is not provided
contents, err := ioutil.ReadFile(args[1])
contents, err := ioutil.ReadFile(args[0])
jackzampolin marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return errors.New("neither JSON input nor path to .json file were provided")
}
if err := cdc.UnmarshalJSON(contents, &evidence); err != nil {
if err := cdc.UnmarshalJSON(contents, &ev); err != nil {
return errors.Wrap(err, "error unmarshalling evidence file")
}
}

msg := types.NewMsgSubmitMisbehaviour(clientID, evidence, cliCtx.GetFromAddress())
msg := evidence.NewMsgSubmitEvidence(ev, cliCtx.GetFromAddress())
if err := msg.ValidateBasic(); err != nil {
return err
}
Expand Down
Loading