Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
/ cosmos-sdk Public archive
forked from cosmos/cosmos-sdk

Commit

Permalink
feat!: use gov v1 proposals in upgrade cli (cosmos#14880)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored and tsenart committed Apr 12, 2023
1 parent 866f6a0 commit 8dac08c
Show file tree
Hide file tree
Showing 14 changed files with 173 additions and 189 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -127,8 +126,6 @@ var (
gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
upgradeclient.LegacyProposalHandler,
upgradeclient.LegacyCancelProposalHandler,
},
),
params.AppModuleBasic{},
Expand Down
3 changes: 0 additions & 3 deletions simapp/app_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -91,8 +90,6 @@ var (
gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
upgradeclient.LegacyProposalHandler,
upgradeclient.LegacyCancelProposalHandler,
},
),
params.AppModuleBasic{},
Expand Down
26 changes: 20 additions & 6 deletions tools/cosmovisor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -293,9 +293,6 @@ cat <<< $(jq '.app_state.gov.voting_params.voting_period = "20s"' $HOME/.simapp/

Create a validator, and setup genesis transaction:

<!-- TODO: add-genesis-account does not read keyring-backend from config -->
<!-- TODO: gentx does not read chain-id from config -->

```shell
./build/simd keys add validator
./build/simd genesis add-genesis-account validator 1000000000stake --keyring-backend test
Expand Down Expand Up @@ -351,12 +348,29 @@ 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
./build/simd tx gov deposit 1 10000000stake --from validator --yes
./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.
82 changes: 26 additions & 56 deletions x/gov/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -1233,6 +1204,7 @@ simd tx gov cancel-proposal [proposal-id] [flags]
```

Example:

```bash
simd tx gov cancel-proposal 1 --from cosmos1...
```
Expand Down Expand Up @@ -1366,7 +1338,6 @@ Example Output:
}
```


#### Proposals

The `Proposals` endpoint allows users to query all proposals with optional filters.
Expand Down Expand Up @@ -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.
Expand Down
18 changes: 9 additions & 9 deletions x/gov/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions x/gov/types/v1/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down
3 changes: 2 additions & 1 deletion x/upgrade/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* [#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.
23 changes: 20 additions & 3 deletions x/upgrade/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
23 changes: 4 additions & 19 deletions x/upgrade/client/cli/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading

0 comments on commit 8dac08c

Please sign in to comment.