Skip to content

Commit

Permalink
wiring fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JeancarloBarrios committed Jul 22, 2024
1 parent ee2f7e9 commit e5c1b86
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 12 deletions.
29 changes: 24 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -194,6 +195,7 @@ var (
ica.AppModuleBasic{},
ibcfee.AppModuleBasic{},
intertxmodule.AppModule{},
wasm.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
28 changes: 24 additions & 4 deletions app/client/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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...,
)
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/testsuite/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
6 changes: 5 additions & 1 deletion app/testsuite/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 5 additions & 1 deletion app/testsuite/network_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand All @@ -26,14 +29,15 @@ 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()

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)),
Expand Down

0 comments on commit e5c1b86

Please sign in to comment.