diff --git a/.gitignore b/.gitignore index f8bd5b336..21f9eb7f9 100644 --- a/.gitignore +++ b/.gitignore @@ -29,7 +29,8 @@ prototype/vendor/ .idea/ # Generated Mocks (for testing) -shared/modules/mocks/ +shared/modules/mocks/* +!shared/modules/mocks/mocks.go p2p/types/mocks/ # TODO(team): Does the `types` directory contain generated or raw type files? diff --git a/Makefile b/Makefile index 3ca0ac38f..6423eb566 100644 --- a/Makefile +++ b/Makefile @@ -87,6 +87,7 @@ go_oapi-codegen: echo "Install with 'go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@v1.11.0'"; \ fi; \ } + .PHONY: go_clean_deps ## Runs `go mod tidy` && `go mod vendor` go_clean_deps: @@ -214,7 +215,7 @@ docker_loki_install: docker_check ## Use `mockgen` to generate mocks used for testing purposes of all the modules. mockgen: $(eval modules_dir = "shared/modules") - rm -rf ${modules_dir}/mocks + find ${modules_dir}/mocks -maxdepth 1 -type f ! -name "mocks.go" -exec rm {} \; go generate ./${modules_dir} echo "Mocks generated in ${modules_dir}/mocks" diff --git a/README.md b/README.md index b0ca09e90..49f26abe3 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,9 @@ All the links you'll need are listed below. If you'd like to contribute to the P - _Coming Soon: Consensus Architecture_ // TODO(olshansky): needs a README file with proper code structure - [Persistence Architecture](persistence/docs/README.md) - [P2P Architecture](p2p/README.md) +- [CLI Architecture](app/client/cli/doc/README.md) +- [RPC Architecture](app/pocket/rpc/doc/README.md) +- [Node binary Architecture](app/pocket/doc/README.md) ### Changelogs @@ -49,6 +52,10 @@ All the links you'll need are listed below. If you'd like to contribute to the P - [Consensus Changelog](consensus/CHANGELOG.md) - [Persistence Changelog](persistence/docs/CHANGELOG.md) - [P2P Changelog](p2p/CHANGELOG.md) +- [CLI Changelog](app/client/cli/doc/CHANGELOG.md) +- [RPC Changelog](app/pocket/rpc/doc/CHANGELOG.md) +- [Node binary Changelog](app/pocket/doc/CHANGELOG.md) + - _Coming Soon: Telemetry Changelog_ ## Support & Contact @@ -64,4 +71,4 @@ All the links you'll need are listed below. If you'd like to contribute to the P ## License -This project is licensed under the MIT License; see the [LICENSE.md](LICENSE.md) file for details. +This project is licensed under the MIT License; see the [LICENSE](LICENSE) file for details. diff --git a/app/client/cli/account.go b/app/client/cli/account.go index 5d63256c5..7c1c15cbc 100644 --- a/app/client/cli/account.go +++ b/app/client/cli/account.go @@ -54,7 +54,7 @@ func accountCommands() []*cobra.Command { Amount: amount, } - tx, err := prepareTxJson(msg, pk) + tx, err := prepareTxBytes(msg, pk) if err != nil { return err } diff --git a/app/client/cli/actor.go b/app/client/cli/actor.go index 25e147acc..6661cb532 100644 --- a/app/client/cli/actor.go +++ b/app/client/cli/actor.go @@ -77,9 +77,13 @@ func newStakeCmd(cmdDef actorCmdDef) *cobra.Command { Use: "Stake ", Short: "Stake a node in the network. Custodial stake uses the same address as operator/output for rewards/return of staked funds.", Long: `Stake the node into the network, making it available for service. -Will prompt the user for the account passphrase. If the node is already staked, this transaction acts as an *update* transaction. + +Will prompt the user for the *fromAddr* account passphrase. If the node is already staked, this transaction acts as an *update* transaction. + A node can update relayChainIDs, serviceURI, and raise the stake amount with this transaction. -If the node is currently staked at X and you submit an update with new stake Y. Only Y-X will be subtracted from an account + +If the node is currently staked at X and you submit an update with new stake Y. Only Y-X will be subtracted from an account. + If no changes are desired for the parameter, just enter the current param value just as before.`, Args: cobra.ExactArgs(4), // REFACTOR(#150): not being used at the moment. Update once a keybase is implemented. RunE: func(cmd *cobra.Command, args []string) error { @@ -116,7 +120,7 @@ If no changes are desired for the parameter, just enter the current param value ActorType: cmdDef.ActorType, } - tx, err := prepareTxJson(msg, pk) + tx, err := prepareTxBytes(msg, pk) if err != nil { return err } @@ -171,7 +175,7 @@ func newEditStakeCmd(cmdDef actorCmdDef) *cobra.Command { ActorType: cmdDef.ActorType, } - tx, err := prepareTxJson(msg, pk) + tx, err := prepareTxBytes(msg, pk) if err != nil { return err } @@ -212,7 +216,7 @@ func newUnstakeCmd(cmdDef actorCmdDef) *cobra.Command { ActorType: cmdDef.ActorType, } - tx, err := prepareTxJson(msg, pk) + tx, err := prepareTxBytes(msg, pk) if err != nil { return err } @@ -253,7 +257,7 @@ func newUnpauseCmd(cmdDef actorCmdDef) *cobra.Command { ActorType: cmdDef.ActorType, } - tx, err := prepareTxJson(msg, pk) + tx, err := prepareTxBytes(msg, pk) if err != nil { return err } diff --git a/app/client/cli/consensus.go b/app/client/cli/consensus.go new file mode 100644 index 000000000..e909fcd2d --- /dev/null +++ b/app/client/cli/consensus.go @@ -0,0 +1,108 @@ +package cli + +import ( + "fmt" + + "github.com/pokt-network/pocket/rpc" + "github.com/spf13/cobra" +) + +func init() { + consensusCmd := NewConsensusCommand() + rootCmd.AddCommand(consensusCmd) +} + +func NewConsensusCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "Consensus", + Short: "Consensus specific commands", + Aliases: []string{"consensus"}, + Args: cobra.ExactArgs(0), + } + + cmd.AddCommand(consensusCommands()...) + + return cmd +} + +func consensusCommands() []*cobra.Command { + cmds := []*cobra.Command{ + { + Use: "State", + Short: "Returns \"Height/Round/Step\"", + Long: "State returns the height, round and step in \"Height/Round/Step\" format", + Aliases: []string{"state"}, + RunE: func(cmd *cobra.Command, args []string) error { + response, err := getConsensusState(cmd) + if err != nil { + return err + } + + fmt.Printf("%d/%d/%d\n", response.JSONDefault.Height, response.JSONDefault.Round, response.JSONDefault.Step) + + return nil + }, + }, + { + Use: "Height", + Short: "Returns the Height", + Long: "Height returns the height in the node's current consensus state", + Aliases: []string{"height"}, + RunE: func(cmd *cobra.Command, args []string) error { + response, err := getConsensusState(cmd) + if err != nil { + return err + } + + fmt.Printf("%d\n", response.JSONDefault.Height) + + return nil + }, + }, + { + Use: "Round", + Short: "Returns the Round", + Long: "Round returns the round in the node's current consensus state", + Aliases: []string{"round"}, + RunE: func(cmd *cobra.Command, args []string) error { + response, err := getConsensusState(cmd) + if err != nil { + return err + } + + fmt.Printf("%d\n", response.JSONDefault.Round) + + return nil + }, + }, + { + Use: "Step", + Short: "Returns the Step", + Long: "Step returns the step in the node's current consensus state", + Aliases: []string{"step"}, + RunE: func(cmd *cobra.Command, args []string) error { + response, err := getConsensusState(cmd) + if err != nil { + return err + } + + fmt.Printf("%d\n", response.JSONDefault.Step) + + return nil + }, + }, + } + return cmds +} + +func getConsensusState(cmd *cobra.Command) (*rpc.GetV1ConsensusStateResponse, error) { + client, err := rpc.NewClientWithResponses(remoteCLIURL) + if err != nil { + return nil, nil + } + response, err := client.GetV1ConsensusStateWithResponse(cmd.Context()) + if err != nil { + return nil, unableToConnectToRpc(err) + } + return response, nil +} diff --git a/app/client/cli/debug.go b/app/client/cli/debug.go index 3c6026603..74d2327a8 100644 --- a/app/client/cli/debug.go +++ b/app/client/cli/debug.go @@ -11,6 +11,7 @@ import ( "github.com/manifoldco/promptui" "github.com/pokt-network/pocket/consensus" "github.com/pokt-network/pocket/p2p" + "github.com/pokt-network/pocket/rpc" "github.com/pokt-network/pocket/runtime" "github.com/pokt-network/pocket/shared" pocketCrypto "github.com/pokt-network/pocket/shared/crypto" @@ -203,7 +204,13 @@ func initDebug(remoteCLIURL string) { } telemetryMod := telemetryM.(modules.TelemetryModule) - _ = shared.CreateBusWithOptionalModules(runtimeMgr, nil, p2pMod, nil, consensusMod, telemetryMod) // TODO: refactor using the `WithXXXModule()` pattern accepting a slice of IntegratableModule + rpcM, err := rpc.Create(runtimeMgr) + if err != nil { + log.Fatalf("[ERROR] Failed to create rpc module: %v", err.Error()) + } + rpcMod := rpcM.(modules.RPCModule) + + _ = shared.CreateBusWithOptionalModules(runtimeMgr, nil, p2pMod, nil, consensusMod, telemetryMod, rpcMod) // TODO: refactor using the `WithXXXModule()` pattern accepting a slice of IntegratableModule p2pMod.Start() }) diff --git a/app/client/cli/doc/CHANGELOG.md b/app/client/cli/doc/CHANGELOG.md index 5dcc4d29c..3f8516c53 100644 --- a/app/client/cli/doc/CHANGELOG.md +++ b/app/client/cli/doc/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed message signing - Reporting RPC StatusCode and body +- System commands working end-to-end +- Added Consensus State commands ## [0.0.1] - 2022-09-09 diff --git a/app/client/cli/doc/commands/client.md b/app/client/cli/doc/commands/client.md index 5ca0233d0..8e446cbca 100644 --- a/app/client/cli/doc/commands/client.md +++ b/app/client/cli/doc/commands/client.md @@ -18,9 +18,11 @@ The CLI is meant to be an user but also a machine friendly way for interacting w * [client Account](client_Account.md) - Account specific commands * [client Application](client_Application.md) - Application actor specific commands +* [client Consensus](client_Consensus.md) - Consensus specific commands * [client Fisherman](client_Fisherman.md) - Fisherman actor specific commands * [client Governance](client_Governance.md) - Governance specific commands * [client Node](client_Node.md) - Node actor specific commands +* [client System](client_System.md) - Commands related to health and troubleshooting of the node instance * [client Validator](client_Validator.md) - Validator actor specific commands -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Account.md b/app/client/cli/doc/commands/client_Account.md index 36d9a117c..9391cf4aa 100644 --- a/app/client/cli/doc/commands/client_Account.md +++ b/app/client/cli/doc/commands/client_Account.md @@ -21,4 +21,4 @@ Account specific commands * [client](client.md) - Pocket Network Command Line Interface (CLI) * [client Account Send](client_Account_Send.md) - Send -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Account_Send.md b/app/client/cli/doc/commands/client_Account_Send.md index f77348d16..0e2bc312f 100644 --- a/app/client/cli/doc/commands/client_Account_Send.md +++ b/app/client/cli/doc/commands/client_Account_Send.md @@ -27,4 +27,4 @@ client Account Send [flags] * [client Account](client_Account.md) - Account specific commands -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Application.md b/app/client/cli/doc/commands/client_Application.md index 7860641ee..7a42ff1f0 100644 --- a/app/client/cli/doc/commands/client_Application.md +++ b/app/client/cli/doc/commands/client_Application.md @@ -19,8 +19,8 @@ Application actor specific commands * [client](client.md) - Pocket Network Command Line Interface (CLI) * [client Application EditStake](client_Application_EditStake.md) - EditStake -* [client Application Stake](client_Application_Stake.md) - Stake an actor (Application) in the network. +* [client Application Stake](client_Application_Stake.md) - Stake a node in the network. Custodial stake uses the same address as operator/output for rewards/return of staked funds. * [client Application Unpause](client_Application_Unpause.md) - Unpause * [client Application Unstake](client_Application_Unstake.md) - Unstake -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Application_EditStake.md b/app/client/cli/doc/commands/client_Application_EditStake.md index 901c2d339..16f9ff834 100644 --- a/app/client/cli/doc/commands/client_Application_EditStake.md +++ b/app/client/cli/doc/commands/client_Application_EditStake.md @@ -28,4 +28,4 @@ client Application EditStake [f * [client Application](client_Application.md) - Application actor specific commands -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Application_Stake.md b/app/client/cli/doc/commands/client_Application_Stake.md index ec3c5d55a..56b00b6e3 100644 --- a/app/client/cli/doc/commands/client_Application_Stake.md +++ b/app/client/cli/doc/commands/client_Application_Stake.md @@ -1,10 +1,22 @@ ## client Application Stake -Stake an actor (Application) in the network. +Stake a node in the network. Custodial stake uses the same address as operator/output for rewards/return of staked funds. ### Synopsis -Stake the Application actor into the network, making it available for service. +Stake the node into the network, making it available for service. + +Will prompt the user for the *fromAddr* account passphrase. If the node is already staked, this transaction acts as an *update* transaction. + +A node can update relayChainIDs, serviceURI, and raise the stake amount with this transaction. + +If the node is currently staked at X and you submit an update with new stake Y. Only Y-X will be subtracted from an account. + +If no changes are desired for the parameter, just enter the current param value just as before. + +``` +client Application Stake [flags] +``` ### Options @@ -23,6 +35,5 @@ Stake the Application actor into the network, making it available for service. ### SEE ALSO * [client Application](client_Application.md) - Application actor specific commands -* [client Application Stake Custodial](client_Application_Stake_Custodial.md) - Stake a node in the network. Custodial stake uses the same address as operator/output for rewards/return of staked funds. -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Application_Stake_Custodial.md b/app/client/cli/doc/commands/client_Application_Stake_Custodial.md deleted file mode 100644 index e47b59344..000000000 --- a/app/client/cli/doc/commands/client_Application_Stake_Custodial.md +++ /dev/null @@ -1,35 +0,0 @@ -## client Application Stake Custodial - -Stake a node in the network. Custodial stake uses the same address as operator/output for rewards/return of staked funds. - -### Synopsis - -Stake the node into the network, making it available for service. -Will prompt the user for the account passphrase. If the node is already staked, this transaction acts as an *update* transaction. -A node can update relayChainIDs, serviceURI, and raise the stake amount with this transaction. -If the node is currently staked at X and you submit an update with new stake Y. Only Y-X will be subtracted from an account -If no changes are desired for the parameter, just enter the current param value just as before. - -``` -client Application Stake Custodial [flags] -``` - -### Options - -``` - -h, --help help for Custodial - --pwd string passphrase used by the cmd, non empty usage bypass interactive prompt -``` - -### Options inherited from parent commands - -``` - --path_to_private_key_file string Path to private key to use when signing (default "./pk.json") - --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") -``` - -### SEE ALSO - -* [client Application Stake](client_Application_Stake.md) - Stake an actor (Application) in the network. - -###### Auto generated by spf13/cobra on 19-Oct-2022 diff --git a/app/client/cli/doc/commands/client_Application_Unpause.md b/app/client/cli/doc/commands/client_Application_Unpause.md index 3e6adc4af..0fb2aad9c 100644 --- a/app/client/cli/doc/commands/client_Application_Unpause.md +++ b/app/client/cli/doc/commands/client_Application_Unpause.md @@ -28,4 +28,4 @@ client Application Unpause [flags] * [client Application](client_Application.md) - Application actor specific commands -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Application_Unstake.md b/app/client/cli/doc/commands/client_Application_Unstake.md index cb0d44aef..316e96e3e 100644 --- a/app/client/cli/doc/commands/client_Application_Unstake.md +++ b/app/client/cli/doc/commands/client_Application_Unstake.md @@ -28,4 +28,4 @@ client Application Unstake [flags] * [client Application](client_Application.md) - Application actor specific commands -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Consensus.md b/app/client/cli/doc/commands/client_Consensus.md new file mode 100644 index 000000000..08af6c184 --- /dev/null +++ b/app/client/cli/doc/commands/client_Consensus.md @@ -0,0 +1,26 @@ +## client Consensus + +Consensus specific commands + +### Options + +``` + -h, --help help for Consensus +``` + +### Options inherited from parent commands + +``` + --path_to_private_key_file string Path to private key to use when signing (default "./pk.json") + --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") +``` + +### SEE ALSO + +* [client](client.md) - Pocket Network Command Line Interface (CLI) +* [client Consensus Height](client_Consensus_Height.md) - Returns the Height +* [client Consensus Round](client_Consensus_Round.md) - Returns the Round +* [client Consensus State](client_Consensus_State.md) - Returns "Height/Round/Step" +* [client Consensus Step](client_Consensus_Step.md) - Returns the Step + +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Consensus_Height.md b/app/client/cli/doc/commands/client_Consensus_Height.md new file mode 100644 index 000000000..c9826be3c --- /dev/null +++ b/app/client/cli/doc/commands/client_Consensus_Height.md @@ -0,0 +1,30 @@ +## client Consensus Height + +Returns the Height + +### Synopsis + +Height returns the height in the node's current consensus state + +``` +client Consensus Height [flags] +``` + +### Options + +``` + -h, --help help for Height +``` + +### Options inherited from parent commands + +``` + --path_to_private_key_file string Path to private key to use when signing (default "./pk.json") + --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") +``` + +### SEE ALSO + +* [client Consensus](client_Consensus.md) - Consensus specific commands + +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Consensus_Round.md b/app/client/cli/doc/commands/client_Consensus_Round.md new file mode 100644 index 000000000..ae7771c18 --- /dev/null +++ b/app/client/cli/doc/commands/client_Consensus_Round.md @@ -0,0 +1,30 @@ +## client Consensus Round + +Returns the Round + +### Synopsis + +Round returns the round in the node's current consensus state + +``` +client Consensus Round [flags] +``` + +### Options + +``` + -h, --help help for Round +``` + +### Options inherited from parent commands + +``` + --path_to_private_key_file string Path to private key to use when signing (default "./pk.json") + --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") +``` + +### SEE ALSO + +* [client Consensus](client_Consensus.md) - Consensus specific commands + +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Consensus_State.md b/app/client/cli/doc/commands/client_Consensus_State.md new file mode 100644 index 000000000..af2817529 --- /dev/null +++ b/app/client/cli/doc/commands/client_Consensus_State.md @@ -0,0 +1,30 @@ +## client Consensus State + +Returns "Height/Round/Step" + +### Synopsis + +State returns the height, round and step in "Height/Round/Step" format + +``` +client Consensus State [flags] +``` + +### Options + +``` + -h, --help help for State +``` + +### Options inherited from parent commands + +``` + --path_to_private_key_file string Path to private key to use when signing (default "./pk.json") + --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") +``` + +### SEE ALSO + +* [client Consensus](client_Consensus.md) - Consensus specific commands + +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Consensus_Step.md b/app/client/cli/doc/commands/client_Consensus_Step.md new file mode 100644 index 000000000..7c99b941b --- /dev/null +++ b/app/client/cli/doc/commands/client_Consensus_Step.md @@ -0,0 +1,30 @@ +## client Consensus Step + +Returns the Step + +### Synopsis + +Step returns the step in the node's current consensus state + +``` +client Consensus Step [flags] +``` + +### Options + +``` + -h, --help help for Step +``` + +### Options inherited from parent commands + +``` + --path_to_private_key_file string Path to private key to use when signing (default "./pk.json") + --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") +``` + +### SEE ALSO + +* [client Consensus](client_Consensus.md) - Consensus specific commands + +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Fisherman.md b/app/client/cli/doc/commands/client_Fisherman.md index 4fe0659f1..b0f046abb 100644 --- a/app/client/cli/doc/commands/client_Fisherman.md +++ b/app/client/cli/doc/commands/client_Fisherman.md @@ -19,8 +19,8 @@ Fisherman actor specific commands * [client](client.md) - Pocket Network Command Line Interface (CLI) * [client Fisherman EditStake](client_Fisherman_EditStake.md) - EditStake -* [client Fisherman Stake](client_Fisherman_Stake.md) - Stake an actor (Fisherman) in the network. +* [client Fisherman Stake](client_Fisherman_Stake.md) - Stake a node in the network. Custodial stake uses the same address as operator/output for rewards/return of staked funds. * [client Fisherman Unpause](client_Fisherman_Unpause.md) - Unpause * [client Fisherman Unstake](client_Fisherman_Unstake.md) - Unstake -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Fisherman_EditStake.md b/app/client/cli/doc/commands/client_Fisherman_EditStake.md index d4114486b..c7cee878e 100644 --- a/app/client/cli/doc/commands/client_Fisherman_EditStake.md +++ b/app/client/cli/doc/commands/client_Fisherman_EditStake.md @@ -28,4 +28,4 @@ client Fisherman EditStake [fla * [client Fisherman](client_Fisherman.md) - Fisherman actor specific commands -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Fisherman_Stake.md b/app/client/cli/doc/commands/client_Fisherman_Stake.md index dc9a3bf6f..0b6d339aa 100644 --- a/app/client/cli/doc/commands/client_Fisherman_Stake.md +++ b/app/client/cli/doc/commands/client_Fisherman_Stake.md @@ -1,10 +1,22 @@ ## client Fisherman Stake -Stake an actor (Fisherman) in the network. +Stake a node in the network. Custodial stake uses the same address as operator/output for rewards/return of staked funds. ### Synopsis -Stake the Fisherman actor into the network, making it available for service. +Stake the node into the network, making it available for service. + +Will prompt the user for the *fromAddr* account passphrase. If the node is already staked, this transaction acts as an *update* transaction. + +A node can update relayChainIDs, serviceURI, and raise the stake amount with this transaction. + +If the node is currently staked at X and you submit an update with new stake Y. Only Y-X will be subtracted from an account. + +If no changes are desired for the parameter, just enter the current param value just as before. + +``` +client Fisherman Stake [flags] +``` ### Options @@ -23,6 +35,5 @@ Stake the Fisherman actor into the network, making it available for service. ### SEE ALSO * [client Fisherman](client_Fisherman.md) - Fisherman actor specific commands -* [client Fisherman Stake Custodial](client_Fisherman_Stake_Custodial.md) - Stake a node in the network. Custodial stake uses the same address as operator/output for rewards/return of staked funds. -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Fisherman_Stake_Custodial.md b/app/client/cli/doc/commands/client_Fisherman_Stake_Custodial.md deleted file mode 100644 index b80f274da..000000000 --- a/app/client/cli/doc/commands/client_Fisherman_Stake_Custodial.md +++ /dev/null @@ -1,35 +0,0 @@ -## client Fisherman Stake Custodial - -Stake a node in the network. Custodial stake uses the same address as operator/output for rewards/return of staked funds. - -### Synopsis - -Stake the node into the network, making it available for service. -Will prompt the user for the account passphrase. If the node is already staked, this transaction acts as an *update* transaction. -A node can update relayChainIDs, serviceURI, and raise the stake amount with this transaction. -If the node is currently staked at X and you submit an update with new stake Y. Only Y-X will be subtracted from an account -If no changes are desired for the parameter, just enter the current param value just as before. - -``` -client Fisherman Stake Custodial [flags] -``` - -### Options - -``` - -h, --help help for Custodial - --pwd string passphrase used by the cmd, non empty usage bypass interactive prompt -``` - -### Options inherited from parent commands - -``` - --path_to_private_key_file string Path to private key to use when signing (default "./pk.json") - --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") -``` - -### SEE ALSO - -* [client Fisherman Stake](client_Fisherman_Stake.md) - Stake an actor (Fisherman) in the network. - -###### Auto generated by spf13/cobra on 19-Oct-2022 diff --git a/app/client/cli/doc/commands/client_Fisherman_Unpause.md b/app/client/cli/doc/commands/client_Fisherman_Unpause.md index 6f77c2b62..cd3d341c8 100644 --- a/app/client/cli/doc/commands/client_Fisherman_Unpause.md +++ b/app/client/cli/doc/commands/client_Fisherman_Unpause.md @@ -28,4 +28,4 @@ client Fisherman Unpause [flags] * [client Fisherman](client_Fisherman.md) - Fisherman actor specific commands -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Fisherman_Unstake.md b/app/client/cli/doc/commands/client_Fisherman_Unstake.md index 179e1e314..ca077a01b 100644 --- a/app/client/cli/doc/commands/client_Fisherman_Unstake.md +++ b/app/client/cli/doc/commands/client_Fisherman_Unstake.md @@ -28,4 +28,4 @@ client Fisherman Unstake [flags] * [client Fisherman](client_Fisherman.md) - Fisherman actor specific commands -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Governance.md b/app/client/cli/doc/commands/client_Governance.md index d3dce12c9..fa8396701 100644 --- a/app/client/cli/doc/commands/client_Governance.md +++ b/app/client/cli/doc/commands/client_Governance.md @@ -20,4 +20,4 @@ Governance specific commands * [client](client.md) - Pocket Network Command Line Interface (CLI) * [client Governance ChangeParameter](client_Governance_ChangeParameter.md) - ChangeParameter -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Governance_ChangeParameter.md b/app/client/cli/doc/commands/client_Governance_ChangeParameter.md index 246cf98bd..a3fdfe398 100644 --- a/app/client/cli/doc/commands/client_Governance_ChangeParameter.md +++ b/app/client/cli/doc/commands/client_Governance_ChangeParameter.md @@ -27,4 +27,4 @@ client Governance ChangeParameter [flags] * [client Governance](client_Governance.md) - Governance specific commands -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Node.md b/app/client/cli/doc/commands/client_Node.md index 17ada4ecd..d09f91b14 100644 --- a/app/client/cli/doc/commands/client_Node.md +++ b/app/client/cli/doc/commands/client_Node.md @@ -19,8 +19,8 @@ Node actor specific commands * [client](client.md) - Pocket Network Command Line Interface (CLI) * [client Node EditStake](client_Node_EditStake.md) - EditStake -* [client Node Stake](client_Node_Stake.md) - Stake an actor (Node) in the network. +* [client Node Stake](client_Node_Stake.md) - Stake a node in the network. Custodial stake uses the same address as operator/output for rewards/return of staked funds. * [client Node Unpause](client_Node_Unpause.md) - Unpause * [client Node Unstake](client_Node_Unstake.md) - Unstake -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Node_EditStake.md b/app/client/cli/doc/commands/client_Node_EditStake.md index ae023c5c0..60150b78b 100644 --- a/app/client/cli/doc/commands/client_Node_EditStake.md +++ b/app/client/cli/doc/commands/client_Node_EditStake.md @@ -28,4 +28,4 @@ client Node EditStake [flags] * [client Node](client_Node.md) - Node actor specific commands -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Node_Stake.md b/app/client/cli/doc/commands/client_Node_Stake.md index 743d15892..bc6e448c8 100644 --- a/app/client/cli/doc/commands/client_Node_Stake.md +++ b/app/client/cli/doc/commands/client_Node_Stake.md @@ -1,10 +1,22 @@ ## client Node Stake -Stake an actor (Node) in the network. +Stake a node in the network. Custodial stake uses the same address as operator/output for rewards/return of staked funds. ### Synopsis -Stake the Node actor into the network, making it available for service. +Stake the node into the network, making it available for service. + +Will prompt the user for the *fromAddr* account passphrase. If the node is already staked, this transaction acts as an *update* transaction. + +A node can update relayChainIDs, serviceURI, and raise the stake amount with this transaction. + +If the node is currently staked at X and you submit an update with new stake Y. Only Y-X will be subtracted from an account. + +If no changes are desired for the parameter, just enter the current param value just as before. + +``` +client Node Stake [flags] +``` ### Options @@ -23,6 +35,5 @@ Stake the Node actor into the network, making it available for service. ### SEE ALSO * [client Node](client_Node.md) - Node actor specific commands -* [client Node Stake Custodial](client_Node_Stake_Custodial.md) - Stake a node in the network. Custodial stake uses the same address as operator/output for rewards/return of staked funds. -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Node_Stake_Custodial.md b/app/client/cli/doc/commands/client_Node_Stake_Custodial.md deleted file mode 100644 index bbb309489..000000000 --- a/app/client/cli/doc/commands/client_Node_Stake_Custodial.md +++ /dev/null @@ -1,35 +0,0 @@ -## client Node Stake Custodial - -Stake a node in the network. Custodial stake uses the same address as operator/output for rewards/return of staked funds. - -### Synopsis - -Stake the node into the network, making it available for service. -Will prompt the user for the account passphrase. If the node is already staked, this transaction acts as an *update* transaction. -A node can update relayChainIDs, serviceURI, and raise the stake amount with this transaction. -If the node is currently staked at X and you submit an update with new stake Y. Only Y-X will be subtracted from an account -If no changes are desired for the parameter, just enter the current param value just as before. - -``` -client Node Stake Custodial [flags] -``` - -### Options - -``` - -h, --help help for Custodial - --pwd string passphrase used by the cmd, non empty usage bypass interactive prompt -``` - -### Options inherited from parent commands - -``` - --path_to_private_key_file string Path to private key to use when signing (default "./pk.json") - --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") -``` - -### SEE ALSO - -* [client Node Stake](client_Node_Stake.md) - Stake an actor (Node) in the network. - -###### Auto generated by spf13/cobra on 19-Oct-2022 diff --git a/app/client/cli/doc/commands/client_Node_Unpause.md b/app/client/cli/doc/commands/client_Node_Unpause.md index 3482556c9..7f500df6a 100644 --- a/app/client/cli/doc/commands/client_Node_Unpause.md +++ b/app/client/cli/doc/commands/client_Node_Unpause.md @@ -28,4 +28,4 @@ client Node Unpause [flags] * [client Node](client_Node.md) - Node actor specific commands -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Node_Unstake.md b/app/client/cli/doc/commands/client_Node_Unstake.md index c2d458d20..82d1b14be 100644 --- a/app/client/cli/doc/commands/client_Node_Unstake.md +++ b/app/client/cli/doc/commands/client_Node_Unstake.md @@ -28,4 +28,4 @@ client Node Unstake [flags] * [client Node](client_Node.md) - Node actor specific commands -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_System.md b/app/client/cli/doc/commands/client_System.md new file mode 100644 index 000000000..05fd26896 --- /dev/null +++ b/app/client/cli/doc/commands/client_System.md @@ -0,0 +1,24 @@ +## client System + +Commands related to health and troubleshooting of the node instance + +### Options + +``` + -h, --help help for System +``` + +### Options inherited from parent commands + +``` + --path_to_private_key_file string Path to private key to use when signing (default "./pk.json") + --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") +``` + +### SEE ALSO + +* [client](client.md) - Pocket Network Command Line Interface (CLI) +* [client System Health](client_System_Health.md) - RPC endpoint liveness +* [client System Version](client_System_Version.md) - Advertised node software version + +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_System_Health.md b/app/client/cli/doc/commands/client_System_Health.md new file mode 100644 index 000000000..4bf141e9f --- /dev/null +++ b/app/client/cli/doc/commands/client_System_Health.md @@ -0,0 +1,30 @@ +## client System Health + +RPC endpoint liveness + +### Synopsis + +Performs a simple liveness check on the node RPC endpoint + +``` +client System Health [flags] +``` + +### Options + +``` + -h, --help help for Health +``` + +### Options inherited from parent commands + +``` + --path_to_private_key_file string Path to private key to use when signing (default "./pk.json") + --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") +``` + +### SEE ALSO + +* [client System](client_System.md) - Commands related to health and troubleshooting of the node instance + +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_System_Version.md b/app/client/cli/doc/commands/client_System_Version.md new file mode 100644 index 000000000..e3f22e4a0 --- /dev/null +++ b/app/client/cli/doc/commands/client_System_Version.md @@ -0,0 +1,30 @@ +## client System Version + +Advertised node software version + +### Synopsis + +Queries the node RPC to obtain the version of the software currently running + +``` +client System Version [flags] +``` + +### Options + +``` + -h, --help help for Version +``` + +### Options inherited from parent commands + +``` + --path_to_private_key_file string Path to private key to use when signing (default "./pk.json") + --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") +``` + +### SEE ALSO + +* [client System](client_System.md) - Commands related to health and troubleshooting of the node instance + +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Validator.md b/app/client/cli/doc/commands/client_Validator.md index 369c11480..10b206138 100644 --- a/app/client/cli/doc/commands/client_Validator.md +++ b/app/client/cli/doc/commands/client_Validator.md @@ -19,8 +19,8 @@ Validator actor specific commands * [client](client.md) - Pocket Network Command Line Interface (CLI) * [client Validator EditStake](client_Validator_EditStake.md) - EditStake -* [client Validator Stake](client_Validator_Stake.md) - Stake an actor (Validator) in the network. +* [client Validator Stake](client_Validator_Stake.md) - Stake a node in the network. Custodial stake uses the same address as operator/output for rewards/return of staked funds. * [client Validator Unpause](client_Validator_Unpause.md) - Unpause * [client Validator Unstake](client_Validator_Unstake.md) - Unstake -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Validator_EditStake.md b/app/client/cli/doc/commands/client_Validator_EditStake.md index 45913437a..6b48b6e00 100644 --- a/app/client/cli/doc/commands/client_Validator_EditStake.md +++ b/app/client/cli/doc/commands/client_Validator_EditStake.md @@ -28,4 +28,4 @@ client Validator EditStake [fla * [client Validator](client_Validator.md) - Validator actor specific commands -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Validator_Stake.md b/app/client/cli/doc/commands/client_Validator_Stake.md index 31de3323f..01bc5fa8e 100644 --- a/app/client/cli/doc/commands/client_Validator_Stake.md +++ b/app/client/cli/doc/commands/client_Validator_Stake.md @@ -1,10 +1,22 @@ ## client Validator Stake -Stake an actor (Validator) in the network. +Stake a node in the network. Custodial stake uses the same address as operator/output for rewards/return of staked funds. ### Synopsis -Stake the Validator actor into the network, making it available for service. +Stake the node into the network, making it available for service. + +Will prompt the user for the *fromAddr* account passphrase. If the node is already staked, this transaction acts as an *update* transaction. + +A node can update relayChainIDs, serviceURI, and raise the stake amount with this transaction. + +If the node is currently staked at X and you submit an update with new stake Y. Only Y-X will be subtracted from an account. + +If no changes are desired for the parameter, just enter the current param value just as before. + +``` +client Validator Stake [flags] +``` ### Options @@ -23,6 +35,5 @@ Stake the Validator actor into the network, making it available for service. ### SEE ALSO * [client Validator](client_Validator.md) - Validator actor specific commands -* [client Validator Stake Custodial](client_Validator_Stake_Custodial.md) - Stake a node in the network. Custodial stake uses the same address as operator/output for rewards/return of staked funds. -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Validator_Stake_Custodial.md b/app/client/cli/doc/commands/client_Validator_Stake_Custodial.md deleted file mode 100644 index 813281a3c..000000000 --- a/app/client/cli/doc/commands/client_Validator_Stake_Custodial.md +++ /dev/null @@ -1,35 +0,0 @@ -## client Validator Stake Custodial - -Stake a node in the network. Custodial stake uses the same address as operator/output for rewards/return of staked funds. - -### Synopsis - -Stake the node into the network, making it available for service. -Will prompt the user for the account passphrase. If the node is already staked, this transaction acts as an *update* transaction. -A node can update relayChainIDs, serviceURI, and raise the stake amount with this transaction. -If the node is currently staked at X and you submit an update with new stake Y. Only Y-X will be subtracted from an account -If no changes are desired for the parameter, just enter the current param value just as before. - -``` -client Validator Stake Custodial [flags] -``` - -### Options - -``` - -h, --help help for Custodial - --pwd string passphrase used by the cmd, non empty usage bypass interactive prompt -``` - -### Options inherited from parent commands - -``` - --path_to_private_key_file string Path to private key to use when signing (default "./pk.json") - --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") -``` - -### SEE ALSO - -* [client Validator Stake](client_Validator_Stake.md) - Stake an actor (Validator) in the network. - -###### Auto generated by spf13/cobra on 19-Oct-2022 diff --git a/app/client/cli/doc/commands/client_Validator_Unpause.md b/app/client/cli/doc/commands/client_Validator_Unpause.md index b4fee2c1c..fd442d393 100644 --- a/app/client/cli/doc/commands/client_Validator_Unpause.md +++ b/app/client/cli/doc/commands/client_Validator_Unpause.md @@ -28,4 +28,4 @@ client Validator Unpause [flags] * [client Validator](client_Validator.md) - Validator actor specific commands -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/doc/commands/client_Validator_Unstake.md b/app/client/cli/doc/commands/client_Validator_Unstake.md index e95079694..dc0b2b9b2 100644 --- a/app/client/cli/doc/commands/client_Validator_Unstake.md +++ b/app/client/cli/doc/commands/client_Validator_Unstake.md @@ -28,4 +28,4 @@ client Validator Unstake [flags] * [client Validator](client_Validator.md) - Validator actor specific commands -###### Auto generated by spf13/cobra on 19-Oct-2022 +###### Auto generated by spf13/cobra on 9-Nov-2022 diff --git a/app/client/cli/gov.go b/app/client/cli/gov.go index f74c15a6e..6e72b2087 100644 --- a/app/client/cli/gov.go +++ b/app/client/cli/gov.go @@ -59,7 +59,7 @@ func govCommands() []*cobra.Command { ParameterValue: pbValue, } - tx, err := prepareTxJson(msg, pk) + tx, err := prepareTxBytes(msg, pk) if err != nil { return err } diff --git a/app/client/cli/system.go b/app/client/cli/system.go new file mode 100644 index 000000000..2bcce8e24 --- /dev/null +++ b/app/client/cli/system.go @@ -0,0 +1,79 @@ +package cli + +import ( + "fmt" + "net/http" + + "github.com/pokt-network/pocket/rpc" + "github.com/spf13/cobra" +) + +func init() { + systemCmd := NewSystemCommand() + rootCmd.AddCommand(systemCmd) +} + +func NewSystemCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "System", + Short: "Commands related to health and troubleshooting of the node instance", + Aliases: []string{"sys"}, + Args: cobra.ExactArgs(0), + } + + cmd.AddCommand(systemCommands()...) + + return cmd +} + +func systemCommands() []*cobra.Command { + cmds := []*cobra.Command{ + { + Use: "Health", + Short: "RPC endpoint liveness", + Long: "Performs a simple liveness check on the node RPC endpoint", + Aliases: []string{"health"}, + RunE: func(cmd *cobra.Command, args []string) error { + client, err := rpc.NewClientWithResponses(remoteCLIURL) + if err != nil { + return nil + } + response, err := client.GetV1HealthWithResponse(cmd.Context()) + if err != nil { + return unableToConnectToRpc(err) + } + statusCode := response.StatusCode() + if statusCode == http.StatusOK { + fmt.Printf("✅ RPC reporting healthy status for node @ %s\n\n%s", boldText(remoteCLIURL), response.Body) + return nil + } + + return rpcResponseCodeUnhealthy(statusCode, response.Body) + }, + }, + { + Use: "Version", + Short: "Advertised node software version", + Long: "Queries the node RPC to obtain the version of the software currently running", + Aliases: []string{"version"}, + RunE: func(cmd *cobra.Command, args []string) error { + client, err := rpc.NewClientWithResponses(remoteCLIURL) + if err != nil { + return err + } + response, err := client.GetV1VersionWithResponse(cmd.Context()) + if err != nil { + return unableToConnectToRpc(err) + } + statusCode := response.StatusCode() + if statusCode == http.StatusOK { + fmt.Printf("Node @ %s reports that it's running version: \n%s\n", boldText(remoteCLIURL), boldText(response.Body)) + return nil + } + + return rpcResponseCodeUnhealthy(statusCode, response.Body) + }, + }, + } + return cmds +} diff --git a/app/client/cli/utils.go b/app/client/cli/utils.go index 58d1aa3c8..ec03639af 100644 --- a/app/client/cli/utils.go +++ b/app/client/cli/utils.go @@ -91,10 +91,10 @@ func confirmation(pwd string) bool { } } -// prepareTxJson wraps a Message into a Transaction and signs it with the provided pk +// prepareTxBytes wraps a Message into a Transaction and signs it with the provided pk // -// returns the JSON bytes of the signed transaction -func prepareTxJson(msg typesUtil.Message, pk crypto.Ed25519PrivateKey) ([]byte, error) { +// returns the raw protobuf bytes of the signed transaction +func prepareTxBytes(msg typesUtil.Message, pk crypto.Ed25519PrivateKey) ([]byte, error) { var err error anyMsg, err := codec.GetCodec().ToAny(msg) if err != nil { @@ -121,11 +121,11 @@ func prepareTxJson(msg typesUtil.Message, pk crypto.Ed25519PrivateKey) ([]byte, PublicKey: pk.PublicKey().Bytes(), } - j, err := codec.GetCodec().Marshal(tx) + bz, err := codec.GetCodec().Marshal(tx) if err != nil { return nil, err } - return j, nil + return bz, nil } // postRawTx posts a signed transaction @@ -190,3 +190,17 @@ func attachPwdFlagToSubcommands() []cmdOption { c.Flags().StringVar(&pwd, "pwd", "", "passphrase used by the cmd, non empty usage bypass interactive prompt") }} } + +func unableToConnectToRpc(err error) error { + fmt.Printf("❌ Unable to connect to the RPC @ %s\n\nError: %s", boldText(remoteCLIURL), err) + return nil +} + +func rpcResponseCodeUnhealthy(statusCode int, response []byte) error { + fmt.Printf("❌ RPC reporting unhealthy status HTTP %d @ %s\n\n%s", statusCode, boldText(remoteCLIURL), response) + return nil +} + +func boldText[T string | []byte](s T) string { + return fmt.Sprintf("\033[1m%s\033[0m", s) +} diff --git a/build/config/config1.json b/build/config/config1.json index a81a73bf7..d4db38c05 100755 --- a/build/config/config1.json +++ b/build/config/config1.json @@ -35,6 +35,7 @@ "rpc": { "enabled": true, "port": "50832", - "timeout": 30000 + "timeout": 30000, + "use_cors": false } } diff --git a/build/config/config2.json b/build/config/config2.json index 0583a094e..9d7054c25 100755 --- a/build/config/config2.json +++ b/build/config/config2.json @@ -35,6 +35,7 @@ "rpc": { "enabled": true, "port": "50832", - "timeout": 30000 + "timeout": 30000, + "use_cors": false } } diff --git a/build/config/config3.json b/build/config/config3.json index 37229ef36..2903ad0b6 100755 --- a/build/config/config3.json +++ b/build/config/config3.json @@ -35,6 +35,7 @@ "rpc": { "enabled": true, "port": "50832", - "timeout": 30000 + "timeout": 30000, + "use_cors": false } } diff --git a/build/config/config4.json b/build/config/config4.json index 839c37d00..744220822 100755 --- a/build/config/config4.json +++ b/build/config/config4.json @@ -35,6 +35,7 @@ "rpc": { "enabled": true, "port": "50832", - "timeout": 30000 + "timeout": 30000, + "use_cors": false } } diff --git a/build/deployments/docker-compose.yaml b/build/deployments/docker-compose.yaml index d740a2bb9..92ca33920 100755 --- a/build/deployments/docker-compose.yaml +++ b/build/deployments/docker-compose.yaml @@ -46,8 +46,9 @@ services: # Needed for DLV debugging security_opt: - "seccomp:unconfined" + environment: + - POCKET_RPC_USE_CORS=true # Uncomment to enable DLV debugging - # environment: # - DEBUG_PORT=7081 node2.consensus: diff --git a/build/scripts/watch_build.sh b/build/scripts/watch_build.sh index ced2e143a..89f72ccac 100755 --- a/build/scripts/watch_build.sh +++ b/build/scripts/watch_build.sh @@ -1,6 +1,6 @@ #!/bin/bash -if builtin type -P "reflex" +if command -v reflex >/dev/null then reflex -r '\.go$' -s -- sh -c "go build -v app/pocket/main.go" else diff --git a/go.mod b/go.mod index 6d7599fd0..943fd2a61 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( github.com/ProtonMail/go-ecvrf v0.0.1 github.com/golang/mock v1.6.0 github.com/jackc/pgx/v4 v4.17.2 - github.com/manifoldco/promptui v0.9.0 github.com/ory/dockertest v3.3.5+incompatible github.com/stretchr/testify v1.8.0 golang.org/x/crypto v0.0.0-20221012134737-56aed061732a @@ -26,6 +25,7 @@ require ( github.com/jackc/pgconn v1.13.0 github.com/jordanorelli/lexnum v0.0.0-20141216151731-460eeb125754 github.com/labstack/echo/v4 v4.9.1 + github.com/manifoldco/promptui v0.9.0 github.com/mitchellh/mapstructure v1.5.0 github.com/quasilyte/go-ruleguard/dsl v0.3.21 github.com/spf13/cobra v1.6.0 @@ -77,7 +77,7 @@ require ( require ( filippo.io/edwards25519 v1.0.0 // indirect - github.com/chzyer/readline v1.5.1 // indirect + github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect diff --git a/go.sum b/go.sum index 2425f509d..bd7095f2d 100644 --- a/go.sum +++ b/go.sum @@ -73,15 +73,12 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/checkpoint-restore/go-criu/v5 v5.3.0/go.mod h1:E/eQpaFtUKGOOSEBZgmKAcn+zUUwWxqcaKZlF54wK8E= +github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= -github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM= -github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= -github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI= -github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= -github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04= -github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8= github.com/cilium/ebpf v0.7.0/go.mod h1:/oI2+1shJiTGAMgl6/RgJr36Eo1jzrRcAWbcXO2usCA= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= @@ -689,7 +686,6 @@ golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/p2p/module.go b/p2p/module.go index 7f6e768a9..c5ef1cb1f 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -140,7 +140,7 @@ func (m *p2pModule) Broadcast(msg *anypb.Any, topic debug.PocketTopic) error { Topic: topic, Data: msg, } - data, err := proto.Marshal(c) + data, err := proto.MarshalOptions{Deterministic: true}.Marshal(c) if err != nil { return err } @@ -154,7 +154,7 @@ func (m *p2pModule) Send(addr cryptoPocket.Address, msg *anypb.Any, topic debug. Topic: topic, Data: msg, } - data, err := proto.Marshal(c) + data, err := proto.MarshalOptions{Deterministic: true}.Marshal(c) if err != nil { return err } diff --git a/p2p/raintree/network.go b/p2p/raintree/network.go index 944dc4916..6e7d2c6f3 100644 --- a/p2p/raintree/network.go +++ b/p2p/raintree/network.go @@ -7,6 +7,7 @@ import ( "time" typesP2P "github.com/pokt-network/pocket/p2p/types" + "github.com/pokt-network/pocket/shared/codec" cryptoPocket "github.com/pokt-network/pocket/shared/crypto" "github.com/pokt-network/pocket/shared/debug" "github.com/pokt-network/pocket/shared/modules" @@ -57,7 +58,7 @@ func (n *rainTreeNetwork) networkBroadcastAtLevel(data []byte, level uint32, non Data: data, Nonce: nonce, } - msgBz, err := proto.Marshal(msg) + msgBz, err := codec.GetCodec().Marshal(msg) if err != nil { return err } @@ -93,7 +94,7 @@ func (n *rainTreeNetwork) NetworkSend(data []byte, address cryptoPocket.Address) Nonce: getNonce(), } - bz, err := proto.Marshal(msg) + bz, err := codec.GetCodec().Marshal(msg) if err != nil { return err } diff --git a/rpc/doc/CHANGELOG.md b/rpc/doc/CHANGELOG.md index 50f3cf428..375eb32bb 100644 --- a/rpc/doc/CHANGELOG.md +++ b/rpc/doc/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Consensus RoundState endpoint +- Consensus State endpoint - Added CORS feature flag and config - Added dockerized swagger-ui diff --git a/rpc/doc/README.md b/rpc/doc/README.md index 647eb3bef..11eca4a09 100644 --- a/rpc/doc/README.md +++ b/rpc/doc/README.md @@ -25,7 +25,7 @@ This approach will allow us to focus on the features and less on the boilerpate The current implementation uses code generation for ease of development. -The source of truth is the the [OpenAPI3.0 yaml file](../v1/openapi.yaml). +The source of truth is the the [OpenAPI3.0 yaml file](../v1/openapi.yaml) (also conveniently visible [here](https://editor.swagger.io/?url=https://raw.githubusercontent.com/pokt-network/pocket/main/rpc/v1/openapi.yaml) via the Swagger Editor) Anytime we make changes to the yaml file, we need to regenerate the boilerplate code by running diff --git a/rpc/handlers.go b/rpc/handlers.go index 6bf16380e..548c3f3e8 100644 --- a/rpc/handlers.go +++ b/rpc/handlers.go @@ -39,9 +39,9 @@ func (s *rpcServer) PostV1ClientBroadcastTxSync(ctx echo.Context) error { return nil } -func (s *rpcServer) GetV1ConsensusRoundState(ctx echo.Context) error { +func (s *rpcServer) GetV1ConsensusState(ctx echo.Context) error { consensus := s.GetBus().GetConsensusModule() - return ctx.JSON(200, RoundState{ + return ctx.JSON(200, ConsensusState{ Height: int64(consensus.CurrentHeight()), Round: int64(consensus.CurrentRound()), Step: int64(consensus.CurrentStep()), diff --git a/rpc/server.go b/rpc/server.go index 90e69a617..807e92c49 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -28,14 +28,22 @@ func (s *rpcServer) StartRPC(port string, timeout uint64) { log.Printf("Starting RPC on port %s...\n", port) e := echo.New() - e.Use( + middlewares := []echo.MiddlewareFunc{ middleware.Logger(), middleware.TimeoutWithConfig(middleware.TimeoutConfig{ Skipper: middleware.DefaultSkipper, ErrorMessage: "Request timed out", Timeout: time.Duration(defaults.DefaultRpcTimeout) * time.Millisecond, }), + } + if s.bus.GetRuntimeMgr().GetConfig().GetRPCConfig().GetUseCors() { + log.Println("Enabling CORS middleware") + middlewares = append(middlewares, middleware.CORS()) + } + e.Use( + middlewares..., ) + RegisterHandlers(e, s) if err := e.Start(":" + port); err != http.ErrServerClosed { diff --git a/rpc/types/proto/rpc_config.proto b/rpc/types/proto/rpc_config.proto index 4d95b3e86..432fd1f67 100644 --- a/rpc/types/proto/rpc_config.proto +++ b/rpc/types/proto/rpc_config.proto @@ -8,4 +8,5 @@ message RPCConfig { bool enabled = 1; string port = 2; uint64 timeout = 3; + bool use_cors = 4; } diff --git a/rpc/types/types.go b/rpc/types/types.go new file mode 100644 index 000000000..08c6e87e8 --- /dev/null +++ b/rpc/types/types.go @@ -0,0 +1,3 @@ +package types + +// this file is only here to make sure that the go tooling is aware of this package ahead of code-generation diff --git a/rpc/v1/openapi.yaml b/rpc/v1/openapi.yaml index a8bce9d31..3183d561b 100644 --- a/rpc/v1/openapi.yaml +++ b/rpc/v1/openapi.yaml @@ -53,7 +53,7 @@ paths: schema: type: string example: 1.0.0 - /v1/consensus/round_state: + /v1/consensus/state: get: tags: - consensus @@ -64,7 +64,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/RoundState' + $ref: '#/components/schemas/ConsensusState' example: { "height": 75016, @@ -111,7 +111,7 @@ components: type: string raw_hex_bytes: type: string - RoundState: + ConsensusState: type: object required: - height diff --git a/shared/codec/codec.go b/shared/codec/codec.go index 0fc0db663..258858adc 100644 --- a/shared/codec/codec.go +++ b/shared/codec/codec.go @@ -21,7 +21,7 @@ var _ Codec = &ProtoCodec{} type ProtoCodec struct{} func (p *ProtoCodec) Marshal(message proto.Message) ([]byte, error) { - bz, err := proto.Marshal(message) + bz, err := proto.MarshalOptions{Deterministic: true}.Marshal(message) if err != nil { return nil, err } diff --git a/shared/modules/mocks/mocks.go b/shared/modules/mocks/mocks.go new file mode 100644 index 000000000..b11cd844d --- /dev/null +++ b/shared/modules/mocks/mocks.go @@ -0,0 +1 @@ +package mock_modules diff --git a/shared/modules/types.go b/shared/modules/types.go index c6e2738b4..ce6a3fd4a 100644 --- a/shared/modules/types.go +++ b/shared/modules/types.go @@ -70,6 +70,7 @@ type RPCConfig interface { GetEnabled() bool GetPort() string GetTimeout() uint64 + GetUseCors() bool } type PersistenceGenesisState interface {