From 49792713f0a1b8acd526e2352e95ca8e6ff19c24 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 2 Feb 2023 09:48:06 +0100 Subject: [PATCH 1/5] feat: use gov v1 proposals in upgrade cli --- simapp/app.go | 3 - simapp/app_v2.go | 3 - x/gov/client/cli/tx.go | 18 ++-- x/gov/types/v1/msgs.go | 12 +++ x/upgrade/CHANGELOG.md | 3 +- x/upgrade/client/cli/parse.go | 23 +----- x/upgrade/client/cli/parse_test.go | 25 ++---- x/upgrade/client/cli/tx.go | 118 +++++++++++++-------------- x/upgrade/client/proposal_handler.go | 12 --- x/upgrade/keeper/msg_server_test.go | 5 +- 10 files changed, 95 insertions(+), 127 deletions(-) delete mode 100644 x/upgrade/client/proposal_handler.go diff --git a/simapp/app.go b/simapp/app.go index 754a96993172..2d299807ab3c 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -26,7 +26,6 @@ import ( nftmodule "cosmossdk.io/x/nft/module" "cosmossdk.io/x/upgrade" - upgradeclient "cosmossdk.io/x/upgrade/client" upgradekeeper "cosmossdk.io/x/upgrade/keeper" upgradetypes "cosmossdk.io/x/upgrade/types" @@ -127,8 +126,6 @@ var ( gov.NewAppModuleBasic( []govclient.ProposalHandler{ paramsclient.ProposalHandler, - upgradeclient.LegacyProposalHandler, - upgradeclient.LegacyCancelProposalHandler, }, ), params.AppModuleBasic{}, diff --git a/simapp/app_v2.go b/simapp/app_v2.go index 9924011ad7c5..20093e78188f 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -22,7 +22,6 @@ import ( feegrantkeeper "cosmossdk.io/x/feegrant/keeper" feegrantmodule "cosmossdk.io/x/feegrant/module" "cosmossdk.io/x/upgrade" - upgradeclient "cosmossdk.io/x/upgrade/client" upgradekeeper "cosmossdk.io/x/upgrade/keeper" "github.com/cosmos/cosmos-sdk/baseapp" @@ -91,8 +90,6 @@ var ( gov.NewAppModuleBasic( []govclient.ProposalHandler{ paramsclient.ProposalHandler, - upgradeclient.LegacyProposalHandler, - upgradeclient.LegacyCancelProposalHandler, }, ), params.AppModuleBasic{}, diff --git a/x/gov/client/cli/tx.go b/x/gov/client/cli/tx.go index b383cccfbcc1..7c7868efa19c 100644 --- a/x/gov/client/cli/tx.go +++ b/x/gov/client/cli/tx.go @@ -20,19 +20,19 @@ import ( // Proposal flags const ( - FlagTitle = "title" + FlagTitle = "title" + FlagDeposit = "deposit" + flagVoter = "voter" + flagDepositor = "depositor" + flagStatus = "status" + FlagMetadata = "metadata" + FlagSummary = "summary" + // Deprecated: only used for v1beta1 legacy proposals. + FlagProposal = "proposal" // Deprecated: only used for v1beta1 legacy proposals. FlagDescription = "description" // Deprecated: only used for v1beta1 legacy proposals. FlagProposalType = "type" - FlagDeposit = "deposit" - flagVoter = "voter" - flagDepositor = "depositor" - flagStatus = "status" - FlagMetadata = "metadata" - FlagSummary = "summary" - // Deprecated: only used for v1beta1 legacy proposals. - FlagProposal = "proposal" ) // ProposalFlags defines the core required fields of a legacy proposal. It is used to diff --git a/x/gov/types/v1/msgs.go b/x/gov/types/v1/msgs.go index a40df3a7b8fd..ea2d295df7a8 100644 --- a/x/gov/types/v1/msgs.go +++ b/x/gov/types/v1/msgs.go @@ -48,6 +48,18 @@ func (m *MsgSubmitProposal) GetMsgs() ([]sdk.Msg, error) { return sdktx.GetMsgs(m.Messages, "sdk.MsgProposal") } +// SetMsgs packs sdk.Msg's into m.Messages Any's +// NOTE: this will overwrite any existing messages +func (m *MsgSubmitProposal) SetMsgs(msgs []sdk.Msg) error { + anys, err := sdktx.SetMsgs(msgs) + if err != nil { + return err + } + + m.Messages = anys + return nil +} + // ValidateBasic implements the sdk.Msg interface. func (m MsgSubmitProposal) ValidateBasic() error { if m.Title == "" { diff --git a/x/upgrade/CHANGELOG.md b/x/upgrade/CHANGELOG.md index dae7cfe38430..ab6630081511 100644 --- a/x/upgrade/CHANGELOG.md +++ b/x/upgrade/CHANGELOG.md @@ -27,4 +27,5 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features -* (x/upgrade) [14764](https://github.com/cosmos/cosmos-sdk/pull/14764) The `x/upgrade` module is extracted to have a separate go.mod file which allows it be a standalone module. \ No newline at end of file +* [#](https://github.com/cosmos/cosmos-sdk/pull/) Remove deprecated `NewCmdSubmitLegacyUpgradeProposal` command replace it by its gov v1 equivalent. +* [#14764](https://github.com/cosmos/cosmos-sdk/pull/14764) The `x/upgrade` module is extracted to have a separate go.mod file which allows it be a standalone module. diff --git a/x/upgrade/client/cli/parse.go b/x/upgrade/client/cli/parse.go index 83568e7fca36..9cb0f3eccde1 100644 --- a/x/upgrade/client/cli/parse.go +++ b/x/upgrade/client/cli/parse.go @@ -3,33 +3,18 @@ package cli import ( "cosmossdk.io/x/upgrade/types" "github.com/spf13/pflag" - - "github.com/cosmos/cosmos-sdk/x/gov/client/cli" - gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) -func parseArgsToContent(fs *pflag.FlagSet, name string) (gov.Content, error) { - title, err := fs.GetString(cli.FlagTitle) - if err != nil { - return nil, err - } - - description, err := fs.GetString(cli.FlagDescription) //nolint:staticcheck // we are intentionally using a deprecated flag here. - if err != nil { - return nil, err - } - +func parsePlan(fs *pflag.FlagSet, name string) (types.Plan, error) { height, err := fs.GetInt64(FlagUpgradeHeight) if err != nil { - return nil, err + return types.Plan{}, err } info, err := fs.GetString(FlagUpgradeInfo) if err != nil { - return nil, err + return types.Plan{}, err } - plan := types.Plan{Name: name, Height: height, Info: info} - content := types.NewSoftwareUpgradeProposal(title, description, plan) - return content, nil + return types.Plan{Name: name, Height: height, Info: info}, nil } diff --git a/x/upgrade/client/cli/parse_test.go b/x/upgrade/client/cli/parse_test.go index 9286f18862c6..c9ef3946b59c 100644 --- a/x/upgrade/client/cli/parse_test.go +++ b/x/upgrade/client/cli/parse_test.go @@ -6,16 +6,12 @@ import ( "cosmossdk.io/x/upgrade/types" "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/x/gov/client/cli" ) -func TestParseArgsToContent(t *testing.T) { - fs := NewCmdSubmitLegacyUpgradeProposal().Flags() +func TestParsePlan(t *testing.T) { + fs := NewCmdSubmitUpgradeProposal().Flags() - proposal := types.SoftwareUpgradeProposal{ //nolint:staticcheck // SA1019: types.SoftwareUpgradeProposal is deprecated: use types.Content instead - Title: "proposal title", - Description: "proposal description", + proposal := types.MsgSoftwareUpgrade{ Plan: types.Plan{ Name: "plan name", Height: 123456, @@ -23,19 +19,12 @@ func TestParseArgsToContent(t *testing.T) { }, } - fs.Set(cli.FlagTitle, proposal.Title) - fs.Set(cli.FlagDescription, proposal.Description) //nolint:staticcheck // SA1019: cli.FlagDescription is deprecated: use cli.FlagProposalDescription instead fs.Set(FlagUpgradeHeight, strconv.FormatInt(proposal.Plan.Height, 10)) fs.Set(FlagUpgradeInfo, proposal.Plan.Info) - content, err := parseArgsToContent(fs, proposal.Plan.Name) + p, err := parsePlan(fs, proposal.Plan.Name) require.NoError(t, err) - - p, ok := content.(*types.SoftwareUpgradeProposal) //nolint:staticcheck // SA1019: types.SoftwareUpgradeProposal is deprecated: use types.Content instead - require.Equal(t, ok, true) - require.Equal(t, p.Title, proposal.Title) - require.Equal(t, p.Description, proposal.Description) - require.Equal(t, p.Plan.Name, proposal.Plan.Name) - require.Equal(t, p.Plan.Height, proposal.Plan.Height) - require.Equal(t, p.Plan.Info, proposal.Plan.Info) + require.Equal(t, p.Name, proposal.Plan.Name) + require.Equal(t, p.Height, proposal.Plan.Height) + require.Equal(t, p.Info, proposal.Plan.Info) } diff --git a/x/upgrade/client/cli/tx.go b/x/upgrade/client/cli/tx.go index 184bb966e0d2..0b07f3564ba3 100644 --- a/x/upgrade/client/cli/tx.go +++ b/x/upgrade/client/cli/tx.go @@ -1,6 +1,7 @@ package cli import ( + "fmt" "os" "path/filepath" @@ -12,17 +13,16 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/x/gov/client/cli" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) const ( - // Deprecated: only used for v1beta1 legacy proposals. FlagUpgradeHeight = "upgrade-height" - // Deprecated: only used for v1beta1 legacy proposals. - FlagUpgradeInfo = "upgrade-info" - FlagNoValidate = "no-validate" - FlagDaemonName = "daemon-name" + FlagUpgradeInfo = "upgrade-info" + FlagNoValidate = "no-validate" + FlagDaemonName = "daemon-name" + FlagAuthority = "authority" ) // GetTxCmd returns the transaction commands for this module @@ -35,38 +35,45 @@ func GetTxCmd() *cobra.Command { return cmd } -// NewCmdSubmitLegacyUpgradeProposal implements a command handler for submitting a software upgrade proposal transaction. -// Deprecated: please use NewCmdSubmitUpgradeProposal instead. -func NewCmdSubmitLegacyUpgradeProposal() *cobra.Command { +// NewCmdSubmitUpgradeProposal implements a command handler for submitting a software upgrade proposal transaction. +func NewCmdSubmitUpgradeProposal() *cobra.Command { cmd := &cobra.Command{ Use: "software-upgrade [name] (--upgrade-height [height]) (--upgrade-info [info]) [flags]", Args: cobra.ExactArgs(1), Short: "Submit a software upgrade proposal", Long: "Submit a software upgrade along with an initial deposit.\n" + "Please specify a unique name and height for the upgrade to take effect.\n" + - "You may include info to reference a binary download link, in a format compatible with: https://github.com/cosmos/cosmos-sdk/tree/main/cosmovisor", + "You may include info to reference a binary download link, in a format compatible with: https://docs.cosmos.network/main/tooling/cosmovisor", RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } + + proposal, err := cli.ReadGovPropFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } + name := args[0] - content, err := parseArgsToContent(cmd.Flags(), name) + p, err := parsePlan(cmd.Flags(), name) if err != nil { return err } + noValidate, err := cmd.Flags().GetBool(FlagNoValidate) if err != nil { return err } + if !noValidate { - prop := content.(*types.SoftwareUpgradeProposal) //nolint:staticcheck // we are intentionally using a deprecated proposal type. var daemonName string if daemonName, err = cmd.Flags().GetString(FlagDaemonName); err != nil { return err } + var planInfo *plan.Info - if planInfo, err = plan.ParseInfo(prop.Plan.Info); err != nil { + if planInfo, err = plan.ParseInfo(p.Info); err != nil { return err } if err = planInfo.ValidateFull(daemonName); err != nil { @@ -74,40 +81,40 @@ func NewCmdSubmitLegacyUpgradeProposal() *cobra.Command { } } - from := clientCtx.GetFromAddress() - - depositStr, err := cmd.Flags().GetString(cli.FlagDeposit) - if err != nil { - return err - } - deposit, err := sdk.ParseCoinsNormalized(depositStr) - if err != nil { - return err + authority, _ := cmd.Flags().GetString(FlagAuthority) + if authority != "" { + if _, err = sdk.AccAddressFromBech32(authority); err != nil { + return fmt.Errorf("invalid authority address: %w", err) + } + } else { + authority = sdk.AccAddress(address.Module("gov")).String() } - msg, err := v1beta1.NewMsgSubmitProposal(content, deposit, from) - if err != nil { - return err - } + proposal.SetMsgs([]sdk.Msg{ + &types.MsgSoftwareUpgrade{ + Authority: authority, + Plan: p, + }, + }) - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), proposal) }, } - cmd.Flags().String(cli.FlagTitle, "", "title of proposal") - cmd.Flags().String(cli.FlagDescription, "", "description of proposal") //nolint:staticcheck // we are intentionally using a deprecated flag here. - cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal") cmd.Flags().Int64(FlagUpgradeHeight, 0, "The height at which the upgrade must happen") cmd.Flags().String(FlagUpgradeInfo, "", "Info for the upgrade plan such as new version download urls, etc.") cmd.Flags().Bool(FlagNoValidate, false, "Skip validation of the upgrade info") cmd.Flags().String(FlagDaemonName, getDefaultDaemonName(), "The name of the executable being upgraded (for upgrade-info validation). Default is the DAEMON_NAME env var if set, or else this executable") + cmd.Flags().String(FlagAuthority, "", "The address of the upgrade module authority (defaults to gov)") + + // add common proposal flags + cli.AddGovPropFlagsToCmd(cmd) return cmd } -// NewCmdSubmitLegacyCancelUpgradeProposal implements a command handler for submitting a software upgrade cancel proposal transaction. -// Deprecated: please use NewCmdSubmitCancelUpgradeProposal instead. -func NewCmdSubmitLegacyCancelUpgradeProposal() *cobra.Command { +// NewCmdSubmitCancelUpgradeProposal implements a command handler for submitting a software upgrade cancel proposal transaction. +func NewCmdSubmitCancelUpgradeProposal() *cobra.Command { cmd := &cobra.Command{ Use: "cancel-software-upgrade [flags]", Args: cobra.ExactArgs(0), @@ -118,44 +125,35 @@ func NewCmdSubmitLegacyCancelUpgradeProposal() *cobra.Command { if err != nil { return err } - from := clientCtx.GetFromAddress() - - depositStr, err := cmd.Flags().GetString(cli.FlagDeposit) - if err != nil { - return err - } - - deposit, err := sdk.ParseCoinsNormalized(depositStr) - if err != nil { - return err - } - title, err := cmd.Flags().GetString(cli.FlagTitle) + proposal, err := cli.ReadGovPropFlags(clientCtx, cmd.Flags()) if err != nil { return err } - description, err := cmd.Flags().GetString(cli.FlagDescription) //nolint:staticcheck // we are intentionally using a deprecated flag here. - if err != nil { - return err + authority, _ := cmd.Flags().GetString(FlagAuthority) + if authority != "" { + if _, err = sdk.AccAddressFromBech32(authority); err != nil { + return fmt.Errorf("invalid authority address: %w", err) + } + } else { + authority = sdk.AccAddress(address.Module("gov")).String() } - content := types.NewCancelSoftwareUpgradeProposal(title, description) - - msg, err := v1beta1.NewMsgSubmitProposal(content, deposit, from) - if err != nil { - return err - } + proposal.SetMsgs([]sdk.Msg{ + &types.MsgCancelUpgrade{ + Authority: authority, + }, + }) - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), proposal) }, } - cmd.Flags().String(cli.FlagTitle, "", "title of proposal") - cmd.Flags().String(cli.FlagDescription, "", "description of proposal") //nolint:staticcheck // we are intentionally using a deprecated flag here. - cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal") - cmd.MarkFlagRequired(cli.FlagTitle) - cmd.MarkFlagRequired(cli.FlagDescription) //nolint:staticcheck // we are intentionally using a deprecated flag here. + // add common proposal flags + cli.AddGovPropFlagsToCmd(cmd) + + cmd.Flags().String(FlagAuthority, "", "The address of the upgrade module authority (defaults to gov)") return cmd } diff --git a/x/upgrade/client/proposal_handler.go b/x/upgrade/client/proposal_handler.go deleted file mode 100644 index ce4f5797c1c3..000000000000 --- a/x/upgrade/client/proposal_handler.go +++ /dev/null @@ -1,12 +0,0 @@ -package client - -import ( - "cosmossdk.io/x/upgrade/client/cli" - - govclient "github.com/cosmos/cosmos-sdk/x/gov/client" -) - -var ( - LegacyProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitLegacyUpgradeProposal) - LegacyCancelProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitLegacyCancelUpgradeProposal) -) diff --git a/x/upgrade/keeper/msg_server_test.go b/x/upgrade/keeper/msg_server_test.go index 8f9ccb76c178..6833d7e3c580 100644 --- a/x/upgrade/keeper/msg_server_test.go +++ b/x/upgrade/keeper/msg_server_test.go @@ -2,11 +2,12 @@ package keeper_test import ( "cosmossdk.io/x/upgrade/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" ) func (s *KeeperTestSuite) TestSoftwareUpgrade() { - govAccAddr := "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn" // TODO - // govAccAddr := s.govKeeper.GetGovernanceAccount(s.ctx).GetAddress().String() + govAccAddr := sdk.AccAddress(address.Module("gov")).String() testCases := []struct { name string From 6c927dc0a8510585c5e6f935c46e1cd26adf12c5 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 2 Feb 2023 09:54:21 +0100 Subject: [PATCH 2/5] add changelog --- x/upgrade/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/upgrade/CHANGELOG.md b/x/upgrade/CHANGELOG.md index ab6630081511..f3968a0a6a4f 100644 --- a/x/upgrade/CHANGELOG.md +++ b/x/upgrade/CHANGELOG.md @@ -27,5 +27,5 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features -* [#](https://github.com/cosmos/cosmos-sdk/pull/) Remove deprecated `NewCmdSubmitLegacyUpgradeProposal` command replace it by its gov v1 equivalent. +* [#14880](https://github.com/cosmos/cosmos-sdk/pull/14880) Switch from using gov v1beta1 to gov v1 in upgrade CLIs. * [#14764](https://github.com/cosmos/cosmos-sdk/pull/14764) The `x/upgrade` module is extracted to have a separate go.mod file which allows it be a standalone module. From 477eccf3160dc8fced4821e402dcb3e796e22cd0 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 2 Feb 2023 09:55:42 +0100 Subject: [PATCH 3/5] updates --- x/upgrade/client/cli/tx.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/x/upgrade/client/cli/tx.go b/x/upgrade/client/cli/tx.go index 0b07f3564ba3..8a38eb79799e 100644 --- a/x/upgrade/client/cli/tx.go +++ b/x/upgrade/client/cli/tx.go @@ -32,6 +32,11 @@ func GetTxCmd() *cobra.Command { Short: "Upgrade transaction subcommands", } + cmd.AddCommand( + NewCmdSubmitUpgradeProposal(), + NewCmdSubmitCancelUpgradeProposal(), + ) + return cmd } From c44e43b6120849548c1b4ef995bb2a24c6424f29 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 2 Feb 2023 09:59:48 +0100 Subject: [PATCH 4/5] updates --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94e5f8d85fc3..7688c0beaa84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -250,6 +250,7 @@ extension interfaces. `module.Manager.Modules` is now of type `map[string]interf ### CLI Breaking Changes +* (x/gov) [#14880](https://github.com/cosmos/cosmos-sdk/pull/14880) Remove `simd tx gov submit-legacy-proposal cancel-software-upgrade` and `software-upgrade` commands. These commands are now in the `x/upgrade` module and using gov v1. Use `tx upgrade software-upgrade` instead. * (grpc-web) [#14652](https://github.com/cosmos/cosmos-sdk/pull/14652) Remove `grpc-web.address` flag. * (client) [#14342](https://github.com/cosmos/cosmos-sdk/pull/14342) `simd config` command is now a sub-command. Use `simd config --help` to learn more. * (x/genutil) [#13535](https://github.com/cosmos/cosmos-sdk/pull/13535) Replace in `simd init`, the `--staking-bond-denom` flag with `--default-denom` which is used for all default denomination in the genesis, instead of only staking. From 59dee7468e9e57975f6e7997d58df46a27a8dc6d Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 2 Feb 2023 10:23:13 +0100 Subject: [PATCH 5/5] update docs --- tools/cosmovisor/README.md | 26 +++++++++--- x/gov/README.md | 82 ++++++++++++-------------------------- x/upgrade/README.md | 23 +++++++++-- x/upgrade/client/cli/tx.go | 21 +++++++--- 4 files changed, 81 insertions(+), 71 deletions(-) diff --git a/tools/cosmovisor/README.md b/tools/cosmovisor/README.md index 45f48e28bae1..19f1706375be 100644 --- a/tools/cosmovisor/README.md +++ b/tools/cosmovisor/README.md @@ -210,12 +210,12 @@ If `DAEMON_ALLOW_DOWNLOAD_BINARIES` is set to `true`, and no local binary can be When submitting this as a proposal ensure there are no spaces. An example command using `gaiad` could look like: ```shell - > gaiad tx gov submit-proposal software-upgrade Vega \ + > gaiad tx upgrade software-upgrade Vega \ --title Vega \ --deposit 100uatom \ --upgrade-height 7368420 \ --upgrade-info '{"binaries":{"linux/amd64":"https://github.com/cosmos/gaia/releases/download/v6.0.0-rc1/gaiad-v6.0.0-rc1-linux-amd64","linux/arm64":"https://github.com/cosmos/gaia/releases/download/v6.0.0-rc1/gaiad-v6.0.0-rc1-linux-arm64","darwin/amd64":"https://github.com/cosmos/gaia/releases/download/v6.0.0-rc1/gaiad-v6.0.0-rc1-darwin-amd64"}}' \ - --description "upgrade to Vega" \ + --summary "upgrade to Vega" \ --gas 400000 \ --from user \ --chain-id test \ @@ -293,9 +293,6 @@ cat <<< $(jq '.app_state.gov.voting_params.voting_period = "20s"' $HOME/.simapp/ Create a validator, and setup genesis transaction: - - - ```shell ./build/simd keys add validator ./build/simd genesis add-genesis-account validator 1000000000stake --keyring-backend test @@ -351,7 +348,8 @@ cp ./build/simd $DAEMON_HOME/cosmovisor/upgrades/test1/bin ``` Open a new terminal window and submit an upgrade proposal along with a deposit and a vote (these commands must be run within 20 seconds of each other): -Note, when using a `v0.46+` chain, replace `submit-proposal` by `submit-legacy-proposal`. + +**<= v0.45**: ```shell ./build/simd tx gov submit-proposal software-upgrade test1 --title upgrade --description upgrade --upgrade-height 200 --from validator --yes @@ -359,4 +357,20 @@ Note, when using a `v0.46+` chain, replace `submit-proposal` by `submit-legacy-p ./build/simd tx gov vote 1 yes --from validator --yes ``` +**v0.46, v0.47**: + +```shell +./build/simd tx gov submit-legacy-proposal software-upgrade test1 --title upgrade --description upgrade --upgrade-height 200 --from validator --yes +./build/simd tx gov deposit 1 10000000stake --from validator --yes +./build/simd tx gov vote 1 yes --from validator --yes +``` + +**>= v0.48+**: + +```shell +./build/simd tx upgrade software-upgrade test1 --title upgrade --summary upgrade --upgrade-height 200 --from validator --yes +./build/simd tx gov deposit 1 10000000stake --from validator --yes +./build/simd tx gov vote 1 yes --from validator --yes +``` + The upgrade will occur automatically at height 200. Note: you may need to change the upgrade height in the snippet above if your test play takes more time. diff --git a/x/gov/README.md b/x/gov/README.md index 803a1e7b5d34..7dae06bade9e 100644 --- a/x/gov/README.md +++ b/x/gov/README.md @@ -32,36 +32,35 @@ The following specification uses *ATOM* as the native staking token. The module can be adapted to any Proof-Of-Stake blockchain by replacing *ATOM* with the native staking token of the chain. - * [Concepts](#concepts) - * [Proposal submission](#proposal-submission) - * [Deposit](#deposit) - * [Vote](#vote) - * [Software Upgrade](#software-upgrade) + * [Proposal submission](#proposal-submission) + * [Deposit](#deposit) + * [Vote](#vote) + * [Software Upgrade](#software-upgrade) * [State](#state) - * [Proposals](#proposals) - * [Parameters and base types](#parameters-and-base-types) - * [Deposit](#deposit-1) - * [ValidatorGovInfo](#validatorgovinfo) - * [Stores](#stores) - * [Proposal Processing Queue](#proposal-processing-queue) - * [Legacy Proposal](#legacy-proposal) + * [Proposals](#proposals) + * [Parameters and base types](#parameters-and-base-types) + * [Deposit](#deposit-1) + * [ValidatorGovInfo](#validatorgovinfo) + * [Stores](#stores) + * [Proposal Processing Queue](#proposal-processing-queue) + * [Legacy Proposal](#legacy-proposal) * [Messages](#messages) - * [Proposal Submission](#proposal-submission-1) - * [Deposit](#deposit-2) - * [Vote](#vote-1) + * [Proposal Submission](#proposal-submission-1) + * [Deposit](#deposit-2) + * [Vote](#vote-1) * [Events](#events) - * [EndBlocker](#endblocker) - * [Handlers](#handlers) + * [EndBlocker](#endblocker) + * [Handlers](#handlers) * [Parameters](#parameters) - * [SubKeys](#subkeys) + * [SubKeys](#subkeys) * [Client](#client) - * [CLI](#cli) - * [gRPC](#grpc) - * [REST](#rest) + * [CLI](#cli) + * [gRPC](#grpc) + * [REST](#rest) * [Metadata](#metadata) - * [Proposal](#proposal-3) - * [Vote](#vote-5) + * [Proposal](#proposal-3) + * [Vote](#vote-5) * [Future Improvements](#future-improvements) ## Concepts @@ -392,7 +391,7 @@ We will use one KVStore `Governance` to store four mappings: * A mapping from `proposalID|'addresses'|address` to `Vote`. This mapping allows us to query all addresses that voted on the proposal along with their vote by doing a range query on `proposalID:addresses`. -* A mapping from `ParamsKey|'Params'` to `Params`. This map allows to query all +* A mapping from `ParamsKey|'Params'` to `Params`. This map allows to query all x/gov params. * A mapping from `VotingPeriodProposalKeyPrefix|proposalID` to a single byte. This allows us to know if a proposal is in the voting period or not with very low gas cost. @@ -507,7 +506,7 @@ must not be larger than the `maxMetadataLen` config passed into the gov keeper. * Initialise `Proposal`'s attributes * Decrease balance of sender by `InitialDeposit` * If `MinDeposit` is reached: - * Push `proposalID` in `ProposalProcessingQueue` + * Push `proposalID` in `ProposalProcessingQueue` * Transfer `InitialDeposit` from the `Proposer` to the governance `ModuleAccount` A `MsgSubmitProposal` transaction can be handled according to the following @@ -572,7 +571,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/gov/v1/tx.pro * Add `deposit` of sender in `proposal.Deposits` * Increase `proposal.TotalDeposit` by sender's `deposit` * If `MinDeposit` is reached: - * Push `proposalID` in `ProposalProcessingQueueEnd` + * Push `proposalID` in `ProposalProcessingQueueEnd` * Transfer `Deposit` from the `proposer` to the governance `ModuleAccount` A `MsgDeposit` transaction has to go through a number of checks to be valid. @@ -1175,28 +1174,6 @@ Example: simd tx gov submit-legacy-proposal --title="Test Proposal" --description="testing" --type="Text" --deposit="100000000stake" --from cosmos1.. ``` -Example (`cancel-software-upgrade`): - -```bash -simd tx gov submit-legacy-proposal cancel-software-upgrade --title="Test Proposal" --description="testing" --deposit="100000000stake" --from cosmos1.. -``` - -Example (`community-pool-spend`): - -```bash -simd tx gov submit-legacy-proposal community-pool-spend proposal.json --from cosmos1.. -``` - -```json -{ - "title": "Test Proposal", - "description": "testing, 1, 2, 3", - "recipient": "cosmos1..", - "amount": "10000000stake", - "deposit": "10000000stake" -} -``` - Example (`param-change`): ```bash @@ -1218,12 +1195,6 @@ simd tx gov submit-legacy-proposal param-change proposal.json --from cosmos1.. } ``` -Example (`software-upgrade`): - -```bash -simd tx gov submit-legacy-proposal software-upgrade v2 --title="Test Proposal" --description="testing, testing, 1, 2, 3" --upgrade-height 1000000 --from cosmos1.. -``` - #### cancel-proposal Once proposal is canceled, from the deposits of proposal `deposits * proposal_cancel_ratio` will be burned or sent to `ProposalCancelDest` address , if `ProposalCancelDest` is empty then deposits will be burned. The `remaining deposits` will be sent to depositers. @@ -1233,6 +1204,7 @@ simd tx gov cancel-proposal [proposal-id] [flags] ``` Example: + ```bash simd tx gov cancel-proposal 1 --from cosmos1... ``` @@ -1366,7 +1338,6 @@ Example Output: } ``` - #### Proposals The `Proposals` endpoint allows users to query all proposals with optional filters. @@ -2603,7 +2574,6 @@ Example Output: } ``` - ## Metadata The gov module has two locations for metadata where users can provide further context about the on-chain actions they are taking. By default all metadata fields have a 255 character length field where metadata can be stored in json format, either on-chain or off-chain depending on the amount of data required. Here we provide a recommendation for the json structure and where the data should be stored. There are two important factors in making these recommendations. First, that the gov and group modules are consistent with one another, note the number of proposals made by all groups may be quite large. Second, that client applications such as block explorers and governance interfaces have confidence in the consistency of metadata structure accross chains. diff --git a/x/upgrade/README.md b/x/upgrade/README.md index b482c6672011..03ebfa7c8cdb 100644 --- a/x/upgrade/README.md +++ b/x/upgrade/README.md @@ -22,9 +22,9 @@ recover from. * [State](#state) * [Events](#events) * [Client](#client) - * [CLI](#cli) - * [REST](#rest) - * [gRPC](#grpc) + * [CLI](#cli) + * [REST](#rest) + * [gRPC](#grpc) * [Resources](#resources) ## Concepts @@ -316,6 +316,23 @@ time: "0001-01-01T00:00:00Z" upgraded_client_state: null ``` +#### Transactions + +The upgrade module supports the following transactions: + +* `software-proposal` - submits an upgrade proposal: + +```bash +simd tx upgrade software-upgrade v2 --title="Test Proposal" --summary="testing" --deposit="100000000stake" --upgrade-height 1000000 \ +--upgrade-info '{ "binaries": { "linux/amd64":"https://example.com/simd.zip?checksum=sha256:aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f" } }' --from cosmos1.. +``` + +* `cancel-software-upgrade` - cancels a previously submitted upgrade proposal: + +```bash +simd tx upgrade cancel-software-upgrade --title="Test Proposal" --summary="testing" --deposit="100000000stake" --from cosmos1.. +``` + ### REST A user can query the `upgrade` module using REST endpoints. diff --git a/x/upgrade/client/cli/tx.go b/x/upgrade/client/cli/tx.go index 8a38eb79799e..8ecf9c8df0f0 100644 --- a/x/upgrade/client/cli/tx.go +++ b/x/upgrade/client/cli/tx.go @@ -11,6 +11,7 @@ import ( "cosmossdk.io/x/upgrade/types" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" @@ -95,12 +96,14 @@ func NewCmdSubmitUpgradeProposal() *cobra.Command { authority = sdk.AccAddress(address.Module("gov")).String() } - proposal.SetMsgs([]sdk.Msg{ + if err := proposal.SetMsgs([]sdk.Msg{ &types.MsgSoftwareUpgrade{ Authority: authority, Plan: p, }, - }) + }); err != nil { + return fmt.Errorf("failed to create cancel upgrade message: %w", err) + } return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), proposal) }, @@ -113,7 +116,9 @@ func NewCmdSubmitUpgradeProposal() *cobra.Command { cmd.Flags().String(FlagAuthority, "", "The address of the upgrade module authority (defaults to gov)") // add common proposal flags + flags.AddTxFlagsToCmd(cmd) cli.AddGovPropFlagsToCmd(cmd) + cmd.MarkFlagRequired(cli.FlagTitle) return cmd } @@ -145,20 +150,24 @@ func NewCmdSubmitCancelUpgradeProposal() *cobra.Command { authority = sdk.AccAddress(address.Module("gov")).String() } - proposal.SetMsgs([]sdk.Msg{ + if err := proposal.SetMsgs([]sdk.Msg{ &types.MsgCancelUpgrade{ Authority: authority, }, - }) + }); err != nil { + return fmt.Errorf("failed to create cancel upgrade message: %w", err) + } return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), proposal) }, } + cmd.Flags().String(FlagAuthority, "", "The address of the upgrade module authority (defaults to gov)") + // add common proposal flags + flags.AddTxFlagsToCmd(cmd) cli.AddGovPropFlagsToCmd(cmd) - - cmd.Flags().String(FlagAuthority, "", "The address of the upgrade module authority (defaults to gov)") + cmd.MarkFlagRequired(cli.FlagTitle) return cmd }