Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove legacy gov proposal dependencies #1587

Merged
merged 6 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,6 @@ Available flags:

* `-X github.com/CosmWasm/wasmd/app.NodeDir=.corald` - set the config/data directory for the node (default `~/.wasmd`)
* `-X github.com/CosmWasm/wasmd/app.Bech32Prefix=coral` - set the bech32 prefix for all accounts (default `wasm`)
* `-X github.com/CosmWasm/wasmd/app.ProposalsEnabled=true` - enable all x/wasm governance proposals (default `false`)
alpe marked this conversation as resolved.
Show resolved Hide resolved
* `-X github.com/CosmWasm/wasmd/app.EnableSpecificProposals=MigrateContract,UpdateAdmin,ClearAdmin` -
enable a subset of the x/wasm governance proposal types (overrides `ProposalsEnabled`)

Examples:

Expand All @@ -228,8 +225,7 @@ We strongly suggest **to limit the max block gas in the genesis** and not use th
```

Tip: if you want to lock this down to a permisisoned network, the following script can edit the genesis file
to only allow permissioned use of code upload or instantiating. (Make sure you set `app.ProposalsEnabled=true`
in this binary):
to only allow permissioned use of code upload or instantiating:

`sed -i 's/permission": "Everybody"/permission": "Nobody"/' .../config/genesis.json`

Expand Down
74 changes: 74 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,80 @@ docker run --rm -it \
query gov votes 1
```

## Vote on the upgrade (Starting from wasmd v0.40.0)

Starting from `v0.40.0` of `wasmd`, which incorporates cosmos-sdk `v0.47.x`,
there have been changes in how upgrade proposals are handled. Below,
we provide an example of how to achieve the same outcome as described
in the preceding section.

Please be aware that some commands have been replaced by an interactive
Command Line Interface (CLI), and the process of submitting a proposal
is now divided into two distinct steps: `proposal creation` and `proposal submission`.

```sh
# create the proposal
docker run --rm -it \
--mount type=volume,source=musselnet_client,target=/root \
--network=host \
cosmwasm/wasmd:v0.40.0 wasmd \
tx gov draft-proposal \
--from validator --chain-id testing

# choose <software-upgrade> from the interactive CLI and fill all the fields
# of the generated json file draft_proposal.json
# example:
{
"messages": [
{
"@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade",
"authority": "wasm10d07y265gmmuvt4z0w9aw880jnsr700js7zslc",
"plan": {
"name": "Upgrade",
"time": "0001-01-01T00:00:00Z",
"height": "500",
"info": "",
"upgraded_client_state": null
}
}
],
"metadata": "ipfs://CID",
"deposit": "100000ustake",
"title": "Upgrade",
"summary": "summary"
}

# submit the proposal
docker run --rm -it \
--mount type=volume,source=musselnet_client,target=/root \
--network=host \
cosmwasm/wasmd:v0.40.0 wasmd \
tx gov submit-proposal draft_proposal.json \
--from validator --chain-id testing

# make sure it looks good
docker run --rm -it \
--mount type=volume,source=musselnet_client,target=/root \
--network=host \
cosmwasm/wasmd:v0.40.0 wasmd \
query gov proposal 1

# vote for it
docker run --rm -it \
--mount type=volume,source=musselnet_client,target=/root \
--network=host \
cosmwasm/wasmd:v0.40.0 wasmd \
tx gov vote 1 yes \
--from validator --chain-id testing

# ensure vote was counted
docker run --rm -it \
--mount type=volume,source=musselnet_client,target=/root \
--network=host \
cosmwasm/wasmd:v0.40.0 wasmd \
query gov votes 1
```

## Swap out binaries

Now, we just wait about 5 minutes for the vote to pass, and ensure it is passed:
Expand Down
35 changes: 6 additions & 29 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,33 +134,8 @@ const appName = "WasmApp"
var (
NodeDir = ".wasmd"
Bech32Prefix = "wasm"

// If EnabledSpecificProposals is "", and this is "true", then enable all x/wasm proposals.
// If EnabledSpecificProposals is "", and this is not "true", then disable all x/wasm proposals.
ProposalsEnabled = "false"
// If set to non-empty string it must be comma-separated list of values that are all a subset
// of "EnableAllProposals" (takes precedence over ProposalsEnabled)
// https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34
EnableSpecificProposals = ""
)

// GetEnabledProposals parses the ProposalsEnabled / EnableSpecificProposals values to
// produce a list of enabled proposals to pass into wasmd app.
func GetEnabledProposals() []wasmtypes.ProposalType {
if EnableSpecificProposals == "" {
if ProposalsEnabled == "true" {
return wasmtypes.EnableAllProposals
}
return wasmtypes.DisableAllProposals
}
chunks := strings.Split(EnableSpecificProposals, ",")
proposals, err := wasmtypes.ConvertToProposals(chunks)
if err != nil {
panic(err)
}
return proposals
}

// These constants are derived from the above variables.
// These are the ones we will want to use in the code, based on
// any overrides above
Expand Down Expand Up @@ -306,7 +281,6 @@ func NewWasmApp(
db dbm.DB,
traceStore io.Writer,
loadLatest bool,
enabledProposals []wasmtypes.ProposalType,
appOpts servertypes.AppOptions,
wasmOpts []wasmkeeper.Option,
baseAppOptions ...func(*baseapp.BaseApp),
Expand Down Expand Up @@ -605,10 +579,13 @@ func NewWasmApp(
wasmOpts...,
)

// DEPRECATED: DO NOT USE
//
// The gov proposal types can be individually enabled
if len(enabledProposals) != 0 {
govRouter.AddRoute(wasmtypes.RouterKey, wasmkeeper.NewWasmProposalHandler(app.WasmKeeper, enabledProposals)) //nolint:staticcheck // we still need this despite the deprecation of the gov handler
}
// if len(enabledProposals) != 0 {
// govRouter.AddRoute(wasmtypes.RouterKey, wasmkeeper.NewWasmProposalHandler(app.WasmKeeper, enabledProposals))
//}

// Set legacy router for backwards compatibility with gov v1beta1
app.GovKeeper.SetLegacyRouter(govRouter)

Expand Down
35 changes: 1 addition & 34 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import (

dbm "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
)

var emptyWasmOpts []wasmkeeper.Option
Expand All @@ -28,7 +26,7 @@ func TestWasmdExport(t *testing.T) {
gapp.Commit()

// Making a new app object with the db, so that initchain hasn't been called
newGapp := NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, wasmtypes.EnableAllProposals, simtestutil.NewAppOptionsWithFlagHome(t.TempDir()), emptyWasmOpts)
newGapp := NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, simtestutil.NewAppOptionsWithFlagHome(t.TempDir()), emptyWasmOpts)
_, err := newGapp.ExportAppStateAndValidators(false, []string{}, nil)
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
}
Expand All @@ -54,34 +52,3 @@ func TestGetMaccPerms(t *testing.T) {
dup := GetMaccPerms()
require.Equal(t, maccPerms, dup, "duplicated module account permissions differed from actual module account permissions")
}

func TestGetEnabledProposals(t *testing.T) {
cases := map[string]struct {
proposalsEnabled string
specificEnabled string
expected []wasmtypes.ProposalType
}{
"all disabled": {
proposalsEnabled: "false",
expected: wasmtypes.DisableAllProposals,
},
"all enabled": {
proposalsEnabled: "true",
expected: wasmtypes.EnableAllProposals,
},
"some enabled": {
proposalsEnabled: "okay",
specificEnabled: "StoreCode,InstantiateContract",
expected: []wasmtypes.ProposalType{wasmtypes.ProposalTypeStoreCode, wasmtypes.ProposalTypeInstantiateContract},
},
}

for name, tc := range cases {
t.Run(name, func(t *testing.T) {
ProposalsEnabled = tc.proposalsEnabled
EnableSpecificProposals = tc.specificEnabled
proposals := GetEnabledProposals()
assert.Equal(t, tc.expected, proposals)
})
}
}
8 changes: 4 additions & 4 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestAppImportExport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir))
}()

newApp := NewWasmApp(log.NewNopLogger(), newDB, nil, true, wasmtypes.EnableAllProposals, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
newApp := NewWasmApp(log.NewNopLogger(), newDB, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.Equal(t, "WasmApp", newApp.Name())

var genesisState GenesisState
Expand Down Expand Up @@ -233,7 +233,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir))
}()

newApp := NewWasmApp(log.NewNopLogger(), newDB, nil, true, wasmtypes.EnableAllProposals, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
newApp := NewWasmApp(log.NewNopLogger(), newDB, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.Equal(t, "WasmApp", newApp.Name())

newApp.InitChain(abci.RequestInitChain{
Expand Down Expand Up @@ -275,7 +275,7 @@ func setupSimulationApp(t *testing.T, msg string) (simtypes.Config, dbm.DB, simt
appOptions[flags.FlagHome] = dir // ensure a unique folder
appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue

app := NewWasmApp(logger, db, nil, true, wasmtypes.EnableAllProposals, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
app := NewWasmApp(logger, db, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.Equal(t, "WasmApp", app.Name())
return config, db, appOptions, app
}
Expand Down Expand Up @@ -314,7 +314,7 @@ func TestAppStateDeterminism(t *testing.T) {
}

db := dbm.NewMemDB()
app := NewWasmApp(logger, db, nil, true, wasmtypes.EnableAllProposals, appOptions, emptyWasmOpts, interBlockCacheOpt(), baseapp.SetChainID(SimAppChainID))
app := NewWasmApp(logger, db, nil, true, appOptions, emptyWasmOpts, interBlockCacheOpt(), baseapp.SetChainID(SimAppChainID))

fmt.Printf(
"running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
Expand Down
9 changes: 4 additions & 5 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
)

// SetupOptions defines arguments that are passed into `WasmApp` constructor.
Expand All @@ -70,7 +69,7 @@
appOptions := make(simtestutil.AppOptionsMap, 0)
appOptions[flags.FlagHome] = nodeHome // ensure unique folder
appOptions[server.FlagInvCheckPeriod] = invCheckPeriod
app := NewWasmApp(log.NewNopLogger(), db, nil, true, wasmtypes.EnableAllProposals, appOptions, opts, bam.SetChainID(chainID), bam.SetSnapshot(snapshotStore, snapshottypes.SnapshotOptions{KeepRecent: 2}))
app := NewWasmApp(log.NewNopLogger(), db, nil, true, appOptions, opts, bam.SetChainID(chainID), bam.SetSnapshot(snapshotStore, snapshottypes.SnapshotOptions{KeepRecent: 2}))
if withGenesis {
return app, NewDefaultGenesisState(app.AppCodec())
}
Expand All @@ -96,7 +95,7 @@
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))),
}

app := NewWasmApp(options.Logger, options.DB, nil, true, wasmtypes.EnableAllProposals, options.AppOpts, options.WasmOpts)
app := NewWasmApp(options.Logger, options.DB, nil, true, options.AppOpts, options.WasmOpts)
genesisState := NewDefaultGenesisState(app.appCodec)
genesisState, err = GenesisStateWithValSet(app.AppCodec(), genesisState, valSet, []authtypes.GenesisAccount{acc}, balance)
require.NoError(t, err)
Expand Down Expand Up @@ -282,10 +281,10 @@
}
defer os.RemoveAll(dir)

app := NewWasmApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, wasmtypes.EnableAllProposals, simtestutil.NewAppOptionsWithFlagHome(dir), emptyWasmOptions)
app := NewWasmApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(dir), emptyWasmOptions)

Check warning on line 284 in app/test_helpers.go

View check run for this annotation

Codecov / codecov/patch

app/test_helpers.go#L284

Added line #L284 was not covered by tests
appCtr := func(val network.ValidatorI) servertypes.Application {
return NewWasmApp(
val.GetCtx().Logger, dbm.NewMemDB(), nil, true, wasmtypes.EnableAllProposals,
val.GetCtx().Logger, dbm.NewMemDB(), nil, true,

Check warning on line 287 in app/test_helpers.go

View check run for this annotation

Codecov / codecov/patch

app/test_helpers.go#L287

Added line #L287 was not covered by tests
simtestutil.NewAppOptionsWithFlagHome(val.GetCtx().Config.RootDir),
emptyWasmOptions,
bam.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)),
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
)

func setup(db dbm.DB, withGenesis bool, invCheckPeriod uint, opts ...wasmkeeper.Option) (*app.WasmApp, app.GenesisState) { //nolint:unparam
wasmApp := app.NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, wasmtypes.EnableAllProposals, simtestutil.EmptyAppOptions{}, nil)
wasmApp := app.NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, simtestutil.EmptyAppOptions{}, nil)

if withGenesis {
return wasmApp, app.NewDefaultGenesisState(wasmApp.AppCodec())
Expand Down
2 changes: 0 additions & 2 deletions cmd/wasmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ func newApp(

return app.NewWasmApp(
logger, db, traceStore, true,
app.GetEnabledProposals(),
appOpts,
wasmOpts,
baseappOptions...,
Expand Down Expand Up @@ -292,7 +291,6 @@ func appExport(
db,
traceStore,
height == -1,
app.GetEnabledProposals(),
appOpts,
emptyWasmOpts,
)
Expand Down
1 change: 0 additions & 1 deletion contrib/local/04-gov.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ set -o errexit -o nounset -o pipefail

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

echo "Compile with buildflag ''-X github.com/CosmWasm/wasmd/app.ProposalsEnabled=true' to enable gov"
sleep 1
echo "## Submit a CosmWasm gov proposal"
RESP=$(wasmd tx wasm submit-proposal store-instantiate "$DIR/../../x/wasm/keeper/testdata/reflect.wasm" \
Expand Down
Loading