-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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 implement solo machine client #6115
Closed
colin-axner
wants to merge
19
commits into
cosmos:master
from
colin-axner:colin/5382-solo-machine-client
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
cbc16d7
pause work until client refactor resolved
colin-axner e045498
continued scaffolding
colin-axner c993f95
add msgs and evidence
colin-axner 6de06a4
add update and misbehaviour functionality
colin-axner c7e2b38
implement cli
colin-axner fedb7c8
various types compile issues
colin-axner 066d6b0
add sig proof and various bug fixes
colin-axner 57c7ad5
added rest routes
colin-axner f83c1d6
Merge branch 'master' of github.com:cosmos/cosmos-sdk into colin/5382…
colin-axner aa8703b
verification funcs now update sequence number
colin-axner c70d6ec
add sm suite and header test
colin-axner 5c31eda
msgcreateclient and msgupdateclient tests
colin-axner dcb688b
add basic evidence test
colin-axner d6de635
Merge branch 'master' of github.com:cosmos/cosmos-sdk into colin/5382…
colin-axner 3463dc1
evidence validate basic test
colin-axner fa52816
consensus state tests
colin-axner c163056
rm accidental file
colin-axner 9e30000
add verify con state and channel state, pause work for counterparty c…
colin-axner 480aa6c
client state tests added
colin-axner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package solomachine | ||
|
||
// nolint | ||
// autogenerated code using github.com/rigelrozanski/multitool | ||
// aliases generated for the following subdirectories: | ||
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/ibc/06-solomachine/types/ | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/x/ibc/06-solomachine/types" | ||
) | ||
|
||
const ( | ||
SubModuleName = types.SubModuleName | ||
) | ||
|
||
var ( | ||
// functions aliases | ||
InitializeFromMsg = types.InitializeFromMsg | ||
Initialize = types.Initialize | ||
RegisterCodec = types.RegisterCodec | ||
SetSubModuleCodec = types.SetSubModuleCodec | ||
NewMsgCreateClient = types.NewMsgCreateClient | ||
NewMsgUpdateClient = types.NewMsgUpdateClient | ||
NewMsgSubmitClientMisbehaviour = types.NewMsgSubmitClientMisbehaviour | ||
|
||
// variable aliases | ||
SubModuleCdc = types.SubModuleCdc | ||
ErrInvalidHeader = types.ErrInvalidHeader | ||
ErrInvalidSequence = types.ErrInvalidSequence | ||
) | ||
|
||
type ( | ||
ClientState = types.ClientState | ||
ConsensusState = types.ConsensusState | ||
Evidence = types.Evidence | ||
SignatureAndData = types.SignatureAndData | ||
Header = types.Header | ||
MsgCreateClient = types.MsgCreateClient | ||
MsgUpdateClient = types.MsgUpdateClient | ||
MsgSubmitClientMisbehaviour = types.MsgSubmitClientMisbehaviour | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
) | ||
|
||
// GetTxCmd returns the transaction commands for IBC clients | ||
func GetTxCmd(cdc *codec.Codec, storeKey string) *cobra.Command { | ||
ics06SoloMachineTxCmd := &cobra.Command{ | ||
Use: "solomachine", | ||
Short: "Solo Machine transaction subcommands", | ||
DisableFlagParsing: true, | ||
SuggestionsMinimumDistance: 2, | ||
RunE: client.ValidateCmd, | ||
} | ||
|
||
ics06SoloMachineTxCmd.AddCommand(flags.PostCommands( | ||
GetCmdCreateClient(cdc), | ||
GetCmdUpdateClient(cdc), | ||
GetCmdSubmitMisbehaviour(cdc), | ||
)...) | ||
|
||
return ics06SoloMachineTxCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package cli | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io/ioutil" | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/cosmos/cosmos-sdk/client/context" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/version" | ||
authclient "github.com/cosmos/cosmos-sdk/x/auth/client" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
evidenceexported "github.com/cosmos/cosmos-sdk/x/evidence/exported" | ||
ibcsmtypes "github.com/cosmos/cosmos-sdk/x/ibc/06-solomachine/types" | ||
) | ||
|
||
// GetCmdCreateClient defines the command to create a new IBC Client. | ||
func GetCmdCreateClient(cdc *codec.Codec) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "create [client-id] [path/to/consensus_state.json]", | ||
Short: "create new client with a consensus state", | ||
Long: strings.TrimSpace(fmt.Sprintf(` create new client with specified identifier and consensus state: | ||
|
||
Example: | ||
$ %s tx ibc client create [client-id] [path/to/consensus_state.json] --from node0 --home ../node0/<app>cli --chain-id $CID | ||
`, version.ClientName), | ||
), | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
inBuf := bufio.NewReader(cmd.InOrStdin()) | ||
txBldr := authtypes.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) | ||
cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc).WithBroadcastMode(flags.BroadcastBlock) | ||
|
||
clientID := args[0] | ||
|
||
var consensusState ibcsmtypes.ConsensusState | ||
if err := cdc.UnmarshalJSON([]byte(args[1]), &consensusState); err != nil { | ||
// check for file path if JSON input is not provided | ||
contents, err := ioutil.ReadFile(args[1]) | ||
if err != nil { | ||
return errors.New("neither JSON input nor path to .json file were provided") | ||
} | ||
if err := cdc.UnmarshalJSON(contents, &consensusState); err != nil { | ||
return errors.Wrap(err, "error unmarshalling consensus header file") | ||
} | ||
} | ||
|
||
msg := ibcsmtypes.NewMsgCreateClient(clientID, consensusState) | ||
|
||
if err := msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
|
||
return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
// GetCmdUpdateClient defines the command to update a client. | ||
func GetCmdUpdateClient(cdc *codec.Codec) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "update [client-id] [path/to/header.json]", | ||
Short: "update existing client with a header", | ||
Long: strings.TrimSpace(fmt.Sprintf(`update existing client with a header: | ||
|
||
Example: | ||
$ %s tx ibc client update [client-id] [path/to/header.json] --from node0 --home ../node0/<app>cli --chain-id $CID | ||
`, version.ClientName), | ||
), | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
inBuf := bufio.NewReader(cmd.InOrStdin()) | ||
txBldr := authtypes.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) | ||
cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) | ||
|
||
clientID := args[0] | ||
|
||
var header ibcsmtypes.Header | ||
if err := cdc.UnmarshalJSON([]byte(args[1]), &header); err != nil { | ||
// check for file path if JSON input is not provided | ||
contents, err := ioutil.ReadFile(args[1]) | ||
if err != nil { | ||
return errors.New("neither JSON input nor path to .json file were provided") | ||
} | ||
if err := cdc.UnmarshalJSON(contents, &header); err != nil { | ||
return errors.Wrap(err, "error unmarshalling header file") | ||
} | ||
} | ||
|
||
msg := ibcsmtypes.NewMsgUpdateClient(clientID, header) | ||
if err := msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
|
||
return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
// GetCmdSubmitMisbehaviour defines the command to submit a misbehaviour to prevent | ||
// future updates as defined in | ||
// 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 [path/to/evidence.json]", | ||
Short: "submit a client misbehaviour", | ||
Long: strings.TrimSpace(fmt.Sprintf(`submit a client misbehaviour to prevent future updates: | ||
|
||
Example: | ||
$ %s tx ibc client misbehaviour [path/to/evidence.json] --from node0 --home ../node0/<app>cli --chain-id $CID | ||
`, version.ClientName), | ||
), | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
inBuf := bufio.NewReader(cmd.InOrStdin()) | ||
txBldr := authtypes.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) | ||
cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) | ||
|
||
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[0]) | ||
if err != nil { | ||
return errors.New("neither JSON input nor path to .json file were provided") | ||
} | ||
if err := cdc.UnmarshalJSON(contents, &ev); err != nil { | ||
return errors.Wrap(err, "error unmarshalling evidence file") | ||
} | ||
} | ||
|
||
msg := ibcsmtypes.NewMsgSubmitClientMisbehaviour(ev, cliCtx.GetFromAddress()) | ||
if err := msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
|
||
return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) | ||
}, | ||
} | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package rest | ||
|
||
import ( | ||
"github.com/gorilla/mux" | ||
|
||
"github.com/cosmos/cosmos-sdk/client/context" | ||
"github.com/cosmos/cosmos-sdk/types/rest" | ||
evidenceexported "github.com/cosmos/cosmos-sdk/x/evidence/exported" | ||
ibcsmtypes "github.com/cosmos/cosmos-sdk/x/ibc/06-solomachine/types" | ||
) | ||
|
||
// REST client flags | ||
const ( | ||
RestClientID = "client-id" | ||
) | ||
|
||
// RegisterRoutes - General function to define routes that get registered by the main application | ||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, queryRoute string) { | ||
registerTxRoutes(cliCtx, r) | ||
} | ||
|
||
// CreateClientReq defines the properties of a create client request's body. | ||
type CreateClientReq struct { | ||
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` | ||
ClientID string `json:"client_id" yaml:"client_id"` | ||
ConsensusState ibcsmtypes.ConsensusState `json:"consensus_state" yaml:"consensus_state"` | ||
} | ||
|
||
// UpdateClientReq defines the properties of an update client request's body. | ||
type UpdateClientReq struct { | ||
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` | ||
ClientID string `json:"client_id" yaml:"client_id"` | ||
Header ibcsmtypes.Header `json:"header" yaml:"header"` | ||
} | ||
|
||
// SubmitMisbehaviourReq defines the properties of a submit misbehaviour request's body. | ||
type SubmitMisbehaviourReq struct { | ||
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` | ||
Evidence evidenceexported.Evidence `json:"evidence" yaml:"evidence"` | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally they should be sorted according to their ICS number imo