Skip to content

Commit

Permalink
Merge pull request #154 from comdex-official/feature/permissionedCosm…
Browse files Browse the repository at this point in the history
…wasm

Feature/permissioned cosmwasm
  • Loading branch information
dheerajkd30 authored May 17, 2022
2 parents ef0032d + 418ce88 commit 11f5cce
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 14 deletions.
69 changes: 57 additions & 12 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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.
Expand All @@ -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{},
Expand Down Expand Up @@ -230,6 +263,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 @@ -480,17 +514,21 @@ 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)).
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.distrKeeper)).
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],
Expand Down Expand Up @@ -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()
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
1 change: 1 addition & 0 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 11f5cce

Please sign in to comment.