diff --git a/app/app.go b/app/app.go index 40a2d305d..066980310 100644 --- a/app/app.go +++ b/app/app.go @@ -44,6 +44,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" "github.com/cosmos/cosmos-sdk/x/gov" + 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" "github.com/cosmos/cosmos-sdk/x/mint" @@ -86,6 +87,7 @@ import ( "io" "os" "path/filepath" + "strings" "github.com/comdex-official/comdex/x/asset" assetclient "github.com/comdex-official/comdex/x/asset/client" @@ -99,6 +101,7 @@ import ( vaulttypes "github.com/comdex-official/comdex/x/vault/types" "github.com/CosmWasm/wasmd/x/wasm" + wasmclient "github.com/CosmWasm/wasmd/x/wasm/client" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" @@ -111,10 +114,38 @@ const ( ) var ( - // DefaultNodeHome default home directories for the application daemon - DefaultNodeHome string + // If EnableSpecificWasmProposals is "", and this is "true", then enable all x/wasm proposals. + // If EnableSpecificWasmProposals is "", and this is not "true", then disable all x/wasm proposals. + WasmProposalsEnabled = "true" + // If set to non-empty string it must be comma-separated list of values that are all a subset + // of "EnableAllProposals" (takes precedence over WasmProposalsEnabled) + // https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34 + EnableSpecificWasmProposals = "" // use this for clarity in argument list EmptyWasmOpts []wasm.Option +) + +// GetWasmEnabledProposals parses the WasmProposalsEnabled / EnableSpecificWasmProposals values to +// produce a list of enabled proposals to pass into wasmd app. +func GetWasmEnabledProposals() []wasm.ProposalType { + if EnableSpecificWasmProposals == "" { + if WasmProposalsEnabled == "true" { + return wasm.EnableAllProposals + } + return wasm.DisableAllProposals + } + chunks := strings.Split(EnableSpecificWasmProposals, ",") + proposals, err := wasm.ConvertToProposals(chunks) + if err != nil { + panic(err) + } + return proposals +} + +var ( + // DefaultNodeHome default home directories for the application daemon + DefaultNodeHome string + // ModuleBasics defines the module BasicManager is in charge of setting up basic, // non-dependant module elements, such as codec registration // and genesis verification. @@ -128,11 +159,13 @@ var ( distr.AppModuleBasic{}, gov.NewAppModuleBasic( append( - assetclient.AddAssetsHandler, - paramsclient.ProposalHandler, - distrclient.ProposalHandler, - upgradeclient.ProposalHandler, - upgradeclient.CancelProposalHandler, + []govclient.ProposalHandler{ + paramsclient.ProposalHandler, + distrclient.ProposalHandler, + upgradeclient.ProposalHandler, + upgradeclient.CancelProposalHandler}, + append(assetclient.AddAssetsHandler, + wasmclient.ProposalHandlers...)..., )..., ), params.AppModuleBasic{}, @@ -230,6 +263,7 @@ func New( invCheckPeriod uint, encoding EncodingConfig, appOptions servertypes.AppOptions, + wasmEnabledProposals []wasm.ProposalType, wasmOpts []wasm.Option, baseAppOptions ...func(*baseapp.BaseApp), ) *App { @@ -480,7 +514,7 @@ func New( wasmOpts..., ) - // register the proposal types + // register the proposal types govRouter := govtypes.NewRouter() govRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler). AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.paramsKeeper)). @@ -488,9 +522,13 @@ func New( AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.upgradeKeeper)). AddRoute(assettypes.RouterKey, asset.NewUpdateAssetProposalHandler(app.assetKeeper)). AddRoute(ibchost.RouterKey, ibcclient.NewClientProposalHandler(app.ibcKeeper.ClientKeeper)) - - + if len(wasmEnabledProposals) != 0 { + govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.wasmKeeper, wasmEnabledProposals)) + } + // wire up x/wasm to IBC + ibcRouter.AddRoute(wasm.ModuleName, wasm.NewIBCHandler(app.wasmKeeper, app.ibcKeeper.ChannelKeeper)) app.ibcKeeper.SetRouter(ibcRouter) + app.govKeeper = govkeeper.NewKeeper( app.cdc, app.keys[govtypes.StoreKey], @@ -788,9 +826,16 @@ func (app *App) registerUpgradeHandlers() { ibctransfertypes.ModuleName: ibctransfer.AppModule{}.ConsensusVersion(), assettypes.ModuleName: asset.AppModule{}.ConsensusVersion(), vaulttypes.ModuleName: vault.AppModule{}.ConsensusVersion(), - wasmtypes.ModuleName: wasm.AppModule{}.ConsensusVersion(), } - return app.mm.RunMigrations(ctx, app.configurator, fromVM) + newVM, err := app.mm.RunMigrations(ctx, app.configurator, fromVM) + if err != nil { + return newVM, err + } + //wasm + wasmParams := app.wasmKeeper.GetParams(ctx) + wasmParams.CodeUploadAccess = wasmtypes.AllowNobody + app.wasmKeeper.SetParams(ctx, wasmParams) + return newVM, err }) upgradeInfo, err := app.upgradeKeeper.ReadUpgradeInfoFromDisk() diff --git a/node/cmd/root.go b/node/cmd/root.go index b00bcf903..de11b50af 100644 --- a/node/cmd/root.go +++ b/node/cmd/root.go @@ -177,6 +177,7 @@ func appCreatorFunc(logger log.Logger, db tmdb.DB, tracer io.Writer, options ser cast.ToUint(options.Get(server.FlagInvCheckPeriod)), comdex.MakeEncodingConfig(), options, + comdex.GetWasmEnabledProposals(), wasmOpts, baseapp.SetPruning(pruningOptions), baseapp.SetMinGasPrices(cast.ToString(options.Get(server.FlagMinGasPrices))), @@ -203,13 +204,13 @@ func appExportFunc(logger log.Logger, db tmdb.DB, tracer io.Writer, height int64 var emptyWasmOpts []wasm.Option var app *comdex.App if height != -1 { - app = comdex.New(logger, db, tracer, false, map[int64]bool{}, homePath, cast.ToUint(options.Get(server.FlagInvCheckPeriod)), config, options, emptyWasmOpts) + app = comdex.New(logger, db, tracer, false, map[int64]bool{}, homePath, cast.ToUint(options.Get(server.FlagInvCheckPeriod)), config, options, comdex.GetWasmEnabledProposals(), emptyWasmOpts) if err := app.LoadHeight(height); err != nil { return servertypes.ExportedApp{}, err } } else { - app = comdex.New(logger, db, tracer, true, map[int64]bool{}, homePath, cast.ToUint(options.Get(server.FlagInvCheckPeriod)), config, options, emptyWasmOpts) + app = comdex.New(logger, db, tracer, true, map[int64]bool{}, homePath, cast.ToUint(options.Get(server.FlagInvCheckPeriod)), config, options, comdex.GetWasmEnabledProposals(), emptyWasmOpts) } return app.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs) diff --git a/testutil/network/network.go b/testutil/network/network.go index 4e30e9dc0..939fde5d2 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -57,6 +57,7 @@ func DefaultConfig() network.Config { val.Ctx.Logger, tmdb.NewMemDB(), nil, true, map[int64]bool{}, val.Ctx.Config.RootDir, 0, encoding, simapp.EmptyAppOptions{}, + comdex.GetWasmEnabledProposals(), comdex.EmptyWasmOpts, baseapp.SetPruning(storetypes.NewPruningOptionsFromString(val.AppConfig.Pruning)), baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),