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

permission of cosmwasm #95

Merged
merged 12 commits into from
Mar 23, 2022
88 changes: 67 additions & 21 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"os"
"path/filepath"
"strings"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -98,6 +99,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"
)

Expand All @@ -106,6 +108,35 @@ const (
Name = "comdex"
)

var (
// 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
Expand All @@ -122,10 +153,12 @@ var (
mint.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(
paramsclient.ProposalHandler,
distrclient.ProposalHandler,
upgradeclient.ProposalHandler,
upgradeclient.CancelProposalHandler,
append(
wasmclient.ProposalHandlers,
paramsclient.ProposalHandler,
distrclient.ProposalHandler,
upgradeclient.ProposalHandler,
upgradeclient.CancelProposalHandler)...,
),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
Expand Down Expand Up @@ -220,6 +253,7 @@ func New(
invCheckPeriod uint,
encoding EncodingConfig,
appOptions servertypes.AppOptions,
wasmEnabledProposals []wasm.ProposalType,
wasmOpts []wasm.Option,
baseAppOptions ...func(*baseapp.BaseApp),
) *App {
Expand Down Expand Up @@ -386,16 +420,6 @@ func New(
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.upgradeKeeper)).
AddRoute(ibchost.RouterKey, ibcclient.NewClientProposalHandler(app.ibcKeeper.ClientKeeper))

app.govKeeper = govkeeper.NewKeeper(
app.cdc,
app.keys[govtypes.StoreKey],
app.GetSubspace(govtypes.ModuleName),
app.accountKeeper,
app.bankKeeper,
&stakingKeeper,
govRouter,
)

// Create Transfer Keepers
app.ibcTransferKeeper = ibctransferkeeper.NewKeeper(
app.cdc,
Expand All @@ -415,7 +439,6 @@ func New(
)

ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferModule)
app.ibcKeeper.SetRouter(ibcRouter)

// Create evidence Keeper for to register the IBC light client misbehaviour evidence route
app.evidenceKeeper = *evidencekeeper.NewKeeper(
Expand Down Expand Up @@ -482,6 +505,23 @@ func New(
wasmOpts...,
)

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],
app.GetSubspace(govtypes.ModuleName),
app.accountKeeper,
app.bankKeeper,
&stakingKeeper,
govRouter,
)

/**** Module Options ****/

// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
Expand Down Expand Up @@ -746,7 +786,7 @@ func (a *App) ModuleAccountsPermissions() map[string][]string {
}
}
func (app *App) registerUpgradeHandlers() {
app.upgradeKeeper.SetUpgradeHandler("v0.1.0", func(ctx sdk.Context, plan upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) {
app.upgradeKeeper.SetUpgradeHandler("v0.1.2", func(ctx sdk.Context, plan upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) {
// 1st-time running in-store migrations, using 1 as fromVersion to
// avoid running InitGenesis.
fromVM := map[string]uint64{
Expand All @@ -769,17 +809,23 @@ func (app *App) registerUpgradeHandlers() {
assettypes.ModuleName: asset.AppModule{}.ConsensusVersion(),
vaulttypes.ModuleName: vault.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()
if err != nil {
panic(err)
}
if upgradeInfo.Name == "v0.1.0" && !app.upgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{wasmtypes.ModuleName},
}
if upgradeInfo.Name == "v0.1.2" && !app.upgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
Expand Down
5 changes: 3 additions & 2 deletions node/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))),
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ 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),
)
Expand Down