diff --git a/app/app.go b/app/app.go index 252b748ca0..bf755bd277 100644 --- a/app/app.go +++ b/app/app.go @@ -11,6 +11,7 @@ import ( "strings" "github.com/CosmWasm/wasmd/x/wasm" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/gorilla/mux" "github.com/rakyll/statik/fs" "github.com/spf13/cast" @@ -194,6 +195,7 @@ var ( ica.AppModuleBasic{}, ibcfee.AppModuleBasic{}, intertxmodule.AppModule{}, + wasm.AppModuleBasic{}, ) // module account permissions @@ -320,6 +322,7 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest ibcexported.StoreKey, ibctransfertypes.StoreKey, icahosttypes.StoreKey, ibcfeetypes.StoreKey, icacontrollertypes.StoreKey, ecocredit.ModuleName, data.ModuleName, intertx.ModuleName, + wasmtypes.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) @@ -366,6 +369,9 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest app.ScopedICAControllerKeeper = app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName) app.ScopedInterTxKeeper = app.CapabilityKeeper.ScopeToModule(intertx.ModuleName) + // grant capabilities for wasm modules + app.ScopedWasmKeeper = app.CapabilityKeeper.ScopeToModule(wasmtypes.ModuleName) + // Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating // their scoped modules in `NewApp` with `ScopeToModule` app.CapabilityKeeper.Seal() @@ -557,6 +563,10 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest authtypes.NewModuleAddress(govtypes.ModuleName).String(), wasmOpts..., ) + // Create fee enabled wasm ibc Stack + var wasmStack porttypes.IBCModule + wasmStack = wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper, app.IBCFeeKeeper) + wasmStack = ibcfee.NewIBCMiddleware(wasmStack, app.IBCFeeKeeper) // Create IBC stacks to add to IBC router @@ -572,11 +582,6 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest ibcTransferModule := ibctransfer.NewIBCModule(app.IBCTransferKeeper) ibcTransferStack := ibcfee.NewIBCMiddleware(ibcTransferModule, app.IBCFeeKeeper) - // Create fee enabled wasm ibc Stack - var wasmStack porttypes.IBCModule - wasmStack = wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper, app.IBCFeeKeeper) - wasmStack = ibcfee.NewIBCMiddleware(wasmStack, app.IBCFeeKeeper) - // Create static IBC router ibcRouter := porttypes.NewRouter() ibcRouter. @@ -645,6 +650,7 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest params.NewAppModule(app.ParamsKeeper), authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), + // wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)), ibctransfer.NewAppModule(app.IBCTransferKeeper), ecocreditMod, @@ -805,10 +811,23 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest app.setAnteHandler(txConfig, wasmConfig, keys[wasmtypes.StoreKey]) app.setPostHandler() + // + if manager := app.SnapshotManager(); manager != nil { + err = manager.RegisterExtensions(wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.WasmKeeper)) + if err != nil { + panic("failed to register snapshot extension: " + err.Error()) + } + } + if loadLatest { if err := app.LoadLatestVersion(); err != nil { tmos.Exit(err.Error()) } + + ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{}) + if err := app.WasmKeeper.InitializePinnedCodes(ctx); err != nil { + tmos.Exit(fmt.Sprintf("WasmKeeper failed initialize pinned codes %s", err)) + } } return app diff --git a/app/client/cli/root.go b/app/client/cli/root.go index 86b83bd21d..6a2dc43f1f 100644 --- a/app/client/cli/root.go +++ b/app/client/cli/root.go @@ -5,9 +5,13 @@ import ( "io" "os" + "github.com/CosmWasm/wasmd/x/wasm" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" dbm "github.com/cometbft/cometbft-db" tmcfg "github.com/cometbft/cometbft/config" "github.com/cometbft/cometbft/libs/log" + "github.com/prometheus/client_golang/prometheus" "github.com/spf13/cast" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -41,7 +45,9 @@ import ( // main function. func NewRootCmd() *cobra.Command { // we "pre"-instantiate the application for getting the injected/configured encoding configuration - tempApp := app.NewRegenApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, 1, simtestutil.NewAppOptionsWithFlagHome(app.DefaultNodeHome)) + + emptyWasmOpts := []wasmkeeper.Option{} + tempApp := app.NewRegenApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, 1, simtestutil.NewAppOptionsWithFlagHome(app.DefaultNodeHome), emptyWasmOpts) encodingConfig := testutil.TestEncodingConfig{ InterfaceRegistry: tempApp.InterfaceRegistry(), Codec: tempApp.AppCodec(), @@ -110,6 +116,8 @@ func initTendermintConfig() *tmcfg.Config { func initAppConfig() (string, interface{}) { type CustomAppConfig struct { serverconfig.Config + + Wasm wasmtypes.WasmConfig `mapstructure:"wasm"` } // Optionally allow the chain developer to overwrite the SDK's default @@ -132,9 +140,12 @@ func initAppConfig() (string, interface{}) { customAppConfig := CustomAppConfig{ Config: *srvCfg, + Wasm: wasmtypes.DefaultWasmConfig(), } - return "", customAppConfig + defaultAppTemplate := serverconfig.DefaultConfigTemplate + wasmtypes.DefaultConfigTemplate() + + return defaultAppTemplate, customAppConfig } func initRootCmd(rootCmd *cobra.Command, encodingConfig testutil.TestEncodingConfig) { @@ -168,6 +179,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig testutil.TestEncodingCon func addModuleInitFlags(startCmd *cobra.Command) { crisis.AddModuleInitFlags(startCmd) + wasm.AddModuleInitFlags(startCmd) } // genesisCommand builds genesis-related `simd genesis` command. Users may provide application specific commands as a parameter @@ -233,10 +245,16 @@ func txCommand() *cobra.Command { func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application { baseappOptions := server.DefaultBaseappOptions(appOpts) + var wasmOpts []wasmkeeper.Option + if cast.ToBool(appOpts.Get("telemetry.enabled")) { + wasmOpts = append(wasmOpts, wasmkeeper.WithVMCacheMetrics(prometheus.DefaultRegisterer)) + } + return app.NewRegenApp( logger, db, traceStore, true, cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), appOpts, + wasmOpts, baseappOptions..., ) } @@ -270,14 +288,16 @@ func appExport( viperAppOpts.Set(server.FlagInvCheckPeriod, 1) appOpts = viperAppOpts + var emptyWasmOpts []wasmkeeper.Option + if height != -1 { - regenApp = app.NewRegenApp(logger, db, traceStore, false, 1, appOpts) + regenApp = app.NewRegenApp(logger, db, traceStore, false, 1, appOpts, emptyWasmOpts) if err := regenApp.LoadHeight(height); err != nil { return servertypes.ExportedApp{}, err } } else { - regenApp = app.NewRegenApp(logger, db, traceStore, true, 1, appOpts) + regenApp = app.NewRegenApp(logger, db, traceStore, true, 1, appOpts, emptyWasmOpts) } return regenApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport) diff --git a/app/testsuite/app_test.go b/app/testsuite/app_test.go index ec0d1bfb79..688ab9b7d8 100644 --- a/app/testsuite/app_test.go +++ b/app/testsuite/app_test.go @@ -31,7 +31,7 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) { regenApp.Commit() // Making a new app object with the db, so that initchain hasn't been called - app2 := app.NewRegenApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, setupOptions.InvCheckPeriod, EmptyAppOptions{}) + app2 := app.NewRegenApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, setupOptions.InvCheckPeriod, EmptyAppOptions{}, emptyWasmOption) _, err := app2.ExportAppStateAndValidators(false, []string{}, []string{}) require.NoError(t, err, "ExportAppStateAndValidators should not have an error") } diff --git a/app/testsuite/helpers.go b/app/testsuite/helpers.go index 407d1f4885..0bf4a2bdc4 100644 --- a/app/testsuite/helpers.go +++ b/app/testsuite/helpers.go @@ -4,6 +4,7 @@ import ( "testing" "time" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" dbm "github.com/cometbft/cometbft-db" "github.com/stretchr/testify/require" @@ -47,6 +48,9 @@ var DefaultConsensusParams = &tmproto.ConsensusParams{ }, } +// emptyWasmOption is an empty option for wasmKeeper +var emptyWasmOption []wasmkeeper.Option + // SetupOptions defines arguments that are passed into `Simapp` constructor. type SetupOptions struct { Logger log.Logger @@ -83,7 +87,7 @@ func NewAppWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptions) Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))), } - regenApp := app.NewRegenApp(options.Logger, options.DB, nil, true, options.InvCheckPeriod, options.AppOpts) + regenApp := app.NewRegenApp(options.Logger, options.DB, nil, true, options.InvCheckPeriod, options.AppOpts, emptyWasmOption) genesisState := app.NewDefaultGenesisState(regenApp.AppCodec()) genesisState = genesisStateWithValSet(t, regenApp, genesisState, valSet, []authtypes.GenesisAccount{acc}, balance) diff --git a/app/testsuite/network_config.go b/app/testsuite/network_config.go index 1489bc8c6b..7208f752a6 100644 --- a/app/testsuite/network_config.go +++ b/app/testsuite/network_config.go @@ -4,6 +4,7 @@ import ( "fmt" "os" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" dbm "github.com/cometbft/cometbft-db" "github.com/cometbft/cometbft/libs/log" "github.com/cosmos/cosmos-sdk/baseapp" @@ -17,6 +18,8 @@ import ( "github.com/regen-network/regen-ledger/v5/app" ) +var emptyWasmOpts = []wasmkeeper.Option{} + // NewTestNetworkFixture returns a new simapp AppConstructor for network simulation tests func NewTestNetworkFixture() network.TestFixture { dir, err := os.MkdirTemp("", "regen") @@ -26,7 +29,7 @@ func NewTestNetworkFixture() network.TestFixture { defer os.RemoveAll(dir) a := app.NewRegenApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, 0, - simtestutil.NewAppOptionsWithFlagHome(dir)) + simtestutil.NewAppOptionsWithFlagHome(dir), emptyWasmOption) appCtr := func(val network.ValidatorI) servertypes.Application { cfg := val.GetAppConfig() @@ -34,6 +37,7 @@ func NewTestNetworkFixture() network.TestFixture { return app.NewRegenApp( val.GetCtx().Logger, dbm.NewMemDB(), nil, true, 0, simtestutil.NewAppOptionsWithFlagHome(val.GetCtx().Config.RootDir), + emptyWasmOpts, baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(cfg.Pruning)), baseapp.SetMinGasPrices(cfg.MinGasPrices), baseapp.SetChainID(val.GetCtx().Viper.GetString(flags.FlagChainID)),