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

Generic 02-client cli cmds, removes light client specific ones #8259

Merged
merged 14 commits into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
remove old light client cli cmds and replace with generic ones housed…
… in client
  • Loading branch information
colin-axner committed Jan 5, 2021
commit def06d5d891f561cdaf79db36ed22c90feb2a4b7
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cli
import (
"fmt"
"io/ioutil"
"strconv"

"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand All @@ -13,37 +12,43 @@ import (
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/version"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types"
"github.com/cosmos/cosmos-sdk/x/ibc/light-clients/06-solomachine/types"
"github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types"
"github.com/cosmos/cosmos-sdk/x/ibc/core/exported"
)

const (
flagAllowUpdateAfterProposal = "allow_update_after_proposal"
)

// NewCreateClientCmd defines the command to create a new solo machine client.
// NewCreateClientCmd defines the command to create a new IBC light client.
func NewCreateClientCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "create [sequence] [path/to/consensus_state.json]",
Short: "create new solo machine client",
Long: `create a new solo machine client with the specified identifier and public key
Use: "create [path/to/client_state.json] [path/to/consensus_state.json]",
Short: "create new IBC client",
Long: `create a new IBC client with the specified client state and consensus state
- ConsensusState json example: {"public_key":{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A/3SXL2ONYaOkxpdR5P8tHTlSlPv1AwQwSFxKRee5JQW"},"diversifier":"diversifier","timestamp":"10"}`,
Example: fmt.Sprintf("%s tx ibc %s create [sequence] [path/to/consensus_state] --from node0 --home ../node0/<app>cli --chain-id $CID", version.AppName, types.SubModuleName),
Example: fmt.Sprintf("%s tx ibc %s create [path/to/client_state.json] [path/to/consensus_state] --from node0 --home ../node0/<app>cli --chain-id $CID", version.AppName, types.SubModuleName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
sequence, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}

cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)

// attempt to unmarshal client state argument
var clientState exported.ClientState
if err := cdc.UnmarshalJSON([]byte(args[0]), clientState); err != nil {

// check for file path if JSON input is not provided
contents, err := ioutil.ReadFile(args[0])
if err != nil {
return errors.Wrap(err, "neither JSON input nor path to .json file for client state were provided")
}

if err := cdc.UnmarshalJSON(contents, clientState); err != nil {
return errors.Wrap(err, "error unmarshalling client state file")
}
}

// attempt to unmarshal consensus state argument
consensusState := &types.ConsensusState{}
var consensusState exported.ConsensusState
if err := cdc.UnmarshalJSON([]byte(args[1]), consensusState); err != nil {

// check for file path if JSON input is not provided
Expand All @@ -57,10 +62,7 @@ func NewCreateClientCmd() *cobra.Command {
}
}

allowUpdateAfterProposal, _ := cmd.Flags().GetBool(flagAllowUpdateAfterProposal)

clientState := types.NewClientState(sequence, consensusState, allowUpdateAfterProposal)
msg, err := clienttypes.NewMsgCreateClient(clientState, consensusState, clientCtx.GetFromAddress())
msg, err := types.NewMsgCreateClient(clientState, consensusState, clientCtx.GetFromAddress())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I intentionally do not return the client identifier generated since the call below is GenerateOrBroadcastTx. This code cannot return a client identifier if the transaction is simply generated and not broadcasted. If users want this functionality, they should use external resources like a relayer. This should really only be for testing

if err != nil {
return err
}
Expand All @@ -69,22 +71,22 @@ func NewCreateClientCmd() *cobra.Command {
return err
}

// TODO: determine info to print out for client identifier created
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

cmd.Flags().Bool(flagAllowUpdateAfterProposal, false, "allow governance proposal to update client")
flags.AddTxFlagsToCmd(cmd)

return cmd
}

// NewUpdateClientCmd defines the command to update a solo machine client.
// NewUpdateClientCmd defines the command to update an IBC client.
func NewUpdateClientCmd() *cobra.Command {
return &cobra.Command{
Use: "update [client-id] [path/to/header.json]",
Short: "update existing client with a header",
Long: "update existing client with a solo machine header",
Long: "update existing client with a header",
Example: fmt.Sprintf("%s tx ibc %s update [client-id] [path/to/header.json] --from node0 --home ../node0/<app>cli --chain-id $CID", version.AppName, types.SubModuleName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -96,7 +98,7 @@ func NewUpdateClientCmd() *cobra.Command {

cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)

header := &types.Header{}
var header exported.Header
if err := cdc.UnmarshalJSON([]byte(args[1]), header); err != nil {

// check for file path if JSON input is not provided
Expand All @@ -110,7 +112,7 @@ func NewUpdateClientCmd() *cobra.Command {
}
}

msg, err := clienttypes.NewMsgUpdateClient(clientID, header, clientCtx.GetFromAddress())
msg, err := types.NewMsgUpdateClient(clientID, header, clientCtx.GetFromAddress())
if err != nil {
return err
}
Expand Down Expand Up @@ -140,21 +142,21 @@ func NewSubmitMisbehaviourCmd() *cobra.Command {
}
cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)

m := &types.Misbehaviour{}
if err := cdc.UnmarshalJSON([]byte(args[0]), m); err != nil {
var misbehaviour exported.Misbehaviour
if err := cdc.UnmarshalJSON([]byte(args[0]), misbehaviour); err != nil {

// check for file path if JSON input is not provided
contents, err := ioutil.ReadFile(args[0])
if err != nil {
return errors.Wrap(err, "neither JSON input nor path to .json file for misbehaviour were provided")
}

if err := cdc.UnmarshalJSON(contents, m); err != nil {
if err := cdc.UnmarshalJSON(contents, misbehaviour); err != nil {
return errors.Wrap(err, "error unmarshalling misbehaviour file")
}
}

msg, err := clienttypes.NewMsgSubmitMisbehaviour(m.ClientId, m, clientCtx.GetFromAddress())
msg, err := types.NewMsgSubmitMisbehaviour(misbehaviour.GetClientID(), misbehaviour, clientCtx.GetFromAddress())
if err != nil {
return err
}
Expand Down
2 changes: 0 additions & 2 deletions x/ibc/core/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
connection "github.com/cosmos/cosmos-sdk/x/ibc/core/03-connection"
channel "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel"
host "github.com/cosmos/cosmos-sdk/x/ibc/core/24-host"
solomachine "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/06-solomachine"
tendermint "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/07-tendermint"
)

Expand All @@ -23,7 +22,6 @@ func GetTxCmd() *cobra.Command {
}

ibcTxCmd.AddCommand(
solomachine.GetTxCmd(),
tendermint.GetTxCmd(),
connection.GetTxCmd(),
channel.GetTxCmd(),
Expand Down
4 changes: 4 additions & 0 deletions x/ibc/core/exported/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ type ConsensusState interface {

// Misbehaviour defines counterparty misbehaviour for a specific consensus type
type Misbehaviour interface {
proto.Message

ClientType() string
GetClientID() string
ValidateBasic() error
Expand All @@ -188,6 +190,8 @@ type Misbehaviour interface {

// Header is the consensus state update information
type Header interface {
proto.Message

ClientType() string
GetHeight() Height
ValidateBasic() error
Expand Down
27 changes: 0 additions & 27 deletions x/ibc/light-clients/06-solomachine/client/cli/cli.go

This file was deleted.

8 changes: 0 additions & 8 deletions x/ibc/light-clients/06-solomachine/module.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
package solomachine

import (
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/x/ibc/light-clients/06-solomachine/client/cli"
"github.com/cosmos/cosmos-sdk/x/ibc/light-clients/06-solomachine/types"
)

// Name returns the solo machine client name.
func Name() string {
return types.SubModuleName
}

// GetTxCmd returns the root tx command for the solo machine client.
func GetTxCmd() *cobra.Command {
return cli.NewTxCmd()
}
4 changes: 4 additions & 0 deletions x/ibc/light-clients/06-solomachine/types/client_state_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types_test

import (
"fmt"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types"
connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/core/03-connection/types"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types"
Expand Down Expand Up @@ -69,6 +70,9 @@ func (suite *SoloMachineTestSuite) TestClientStateValidateBasic() {

suite.Run(tc.name, func() {

cdc := suite.chainA.App.AppCodec()

fmt.Printf("%s\n", cdc.MustMarshalJSON(tc.clientState))
err := tc.clientState.Validate()

if tc.expPass {
Expand Down
2 changes: 1 addition & 1 deletion x/ibc/light-clients/06-solomachine/types/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/ibc/core/exported"
)

var _ exported.Header = Header{}
var _ exported.Header = &Header{}

// ClientType defines that the Header is a Solo Machine.
func (Header) ClientType() string {
Expand Down
4 changes: 1 addition & 3 deletions x/ibc/light-clients/06-solomachine/types/misbehaviour.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/ibc/core/exported"
)

var (
_ exported.Misbehaviour = (*Misbehaviour)(nil)
)
var _ exported.Misbehaviour = &Misbehaviour{}

// ClientType is a Solo Machine light client.
func (misbehaviour Misbehaviour) ClientType() string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (suite *SoloMachineTestSuite) TestCheckMisbehaviourAndUpdateState() {
"invalid misbehaviour type",
func() {
clientState = solomachine.ClientState()
misbehaviour = ibctmtypes.Misbehaviour{}
misbehaviour = &ibctmtypes.Misbehaviour{}
},
false,
},
Expand Down
25 changes: 0 additions & 25 deletions x/ibc/light-clients/07-tendermint/client/cli/cli.go

This file was deleted.

Loading