Skip to content

Commit

Permalink
Remove legacy gov proposal dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
pinosu committed Aug 30, 2023
1 parent 78b5af2 commit a400aeb
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 107 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,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`)
* `-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 @@ -227,8 +224,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
47 changes: 0 additions & 47 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ import (
ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v7/modules/core"
ibcclient "github.com/cosmos/ibc-go/v7/modules/core/02-client"
ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
Expand Down Expand Up @@ -97,7 +95,6 @@ import (
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/cosmos/cosmos-sdk/x/group"
groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper"
groupmodule "github.com/cosmos/cosmos-sdk/x/group/module"
Expand All @@ -111,7 +108,6 @@ import (
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
Expand All @@ -134,33 +130,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 +277,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 @@ -483,16 +453,6 @@ func NewWasmApp(
scopedIBCKeeper,
)

// Register the proposal types
// Deprecated: Avoid adding new handlers, instead use the new proposal flow
// by granting the governance module the right to execute the message.
// See: https://docs.cosmos.network/main/modules/gov#proposal-messages
govRouter := govv1beta1.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)). // This should be removed. It is still in place to avoid failures of modules that have not yet been upgraded.
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper))

govConfig := govtypes.DefaultConfig()
/*
Example of setting gov params:
Expand Down Expand Up @@ -605,13 +565,6 @@ func NewWasmApp(
wasmOpts...,
)

// 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
}
// Set legacy router for backwards compatibility with gov v1beta1
app.GovKeeper.SetLegacyRouter(govRouter)

// Create Transfer Stack
var transferStack porttypes.IBCModule
transferStack = transfer.NewIBCModule(app.TransferKeeper)
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 @@ import (
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 @@ func setup(tb testing.TB, chainID string, withGenesis bool, invCheckPeriod uint,
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 @@ func NewWasmAppWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOpti
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 @@ func NewTestNetworkFixture() network.TestFixture {
}
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)
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,
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
12 changes: 12 additions & 0 deletions x/wasm/keeper/proposal_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
const myTestLabel = "testing"

func TestStoreCodeProposal(t *testing.T) {
t.Skip("DEPRECATED")
parentCtx, keepers := CreateTestInput(t, false, "staking")
wasmKeeper := keepers.WasmKeeper
err := wasmKeeper.SetParams(parentCtx, types.Params{
Expand Down Expand Up @@ -122,6 +123,7 @@ func submitLegacyProposal(t *testing.T, ctx sdk.Context, content v1beta1.Content
}

func TestInstantiateProposal(t *testing.T) {
t.Skip("DEPRECATED")
ctx, keepers := CreateTestInput(t, false, "staking")
wasmKeeper := keepers.WasmKeeper
err := wasmKeeper.SetParams(ctx, types.Params{
Expand Down Expand Up @@ -180,6 +182,7 @@ func TestInstantiateProposal(t *testing.T) {
}

func TestInstantiate2Proposal(t *testing.T) {
t.Skip("DEPRECATED")
ctx, keepers := CreateTestInput(t, false, "staking")
wasmKeeper := keepers.WasmKeeper
err := wasmKeeper.SetParams(ctx, types.Params{
Expand Down Expand Up @@ -239,6 +242,7 @@ func TestInstantiate2Proposal(t *testing.T) {
}

func TestInstantiateProposal_NoAdmin(t *testing.T) {
t.Skip("DEPRECATED")
ctx, keepers := CreateTestInput(t, false, "staking")
wasmKeeper := keepers.WasmKeeper
err := wasmKeeper.SetParams(ctx, types.Params{
Expand Down Expand Up @@ -320,6 +324,7 @@ func TestInstantiateProposal_NoAdmin(t *testing.T) {
}

func TestStoreAndInstantiateContractProposal(t *testing.T) {
t.Skip("DEPRECATED")
ctx, keepers := CreateTestInput(t, false, "staking")
wasmKeeper := keepers.WasmKeeper
err := wasmKeeper.SetParams(ctx, types.Params{
Expand Down Expand Up @@ -379,6 +384,7 @@ func TestStoreAndInstantiateContractProposal(t *testing.T) {
}

func TestMigrateProposal(t *testing.T) {
t.Skip("DEPRECATED")
ctx, keepers := CreateTestInput(t, false, "staking")
wasmKeeper := keepers.WasmKeeper
err := wasmKeeper.SetParams(ctx, types.Params{
Expand Down Expand Up @@ -459,6 +465,7 @@ func TestMigrateProposal(t *testing.T) {
}

func TestExecuteProposal(t *testing.T) {
t.Skip("DEPRECATED")
ctx, keepers := CreateTestInput(t, false, "staking")
bankKeeper := keepers.BankKeeper

Expand Down Expand Up @@ -514,6 +521,7 @@ func TestExecuteProposal(t *testing.T) {
}

func TestSudoProposal(t *testing.T) {
t.Skip("DEPRECATED")
ctx, keepers := CreateTestInput(t, false, "staking")
bankKeeper := keepers.BankKeeper

Expand Down Expand Up @@ -561,6 +569,7 @@ func TestSudoProposal(t *testing.T) {
}

func TestAdminProposals(t *testing.T) {
t.Skip("DEPRECATED")
var (
otherAddress sdk.AccAddress = bytes.Repeat([]byte{0x2}, types.ContractAddrLen)
contractAddr = BuildContractAddressClassic(1, 1)
Expand Down Expand Up @@ -651,6 +660,7 @@ func TestAdminProposals(t *testing.T) {
}

func TestPinCodesProposal(t *testing.T) {
t.Skip("DEPRECATED")
ctx, keepers := CreateTestInput(t, false, "staking")
wasmKeeper := keepers.WasmKeeper

Expand Down Expand Up @@ -742,6 +752,7 @@ func TestPinCodesProposal(t *testing.T) {
}

func TestUnpinCodesProposal(t *testing.T) {
t.Skip("DEPRECATED")
ctx, keepers := CreateTestInput(t, false, "staking")
wasmKeeper := keepers.WasmKeeper

Expand Down Expand Up @@ -832,6 +843,7 @@ func TestUnpinCodesProposal(t *testing.T) {
}

func TestUpdateInstantiateConfigProposal(t *testing.T) {
t.Skip("DEPRECATED")
ctx, keepers := CreateTestInput(t, false, "staking")
wasmKeeper := keepers.WasmKeeper

Expand Down
Loading

0 comments on commit a400aeb

Please sign in to comment.