Skip to content

Commit

Permalink
Allow setting wasmopts in binary, for eg. telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Jan 21, 2022
1 parent 8d46003 commit f0ea88b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
10 changes: 5 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ import (

const appName = "OsmosisApp"

// We pull these out so we can set them with LDFLAGS in the Makefile
var (
// If EnabledSpecificProposals is "", and this is "true", then enable all x/wasm proposals.
// If EnabledSpecificProposals is "", and this is not "true", then disable all x/wasm proposals.
Expand All @@ -140,6 +139,9 @@ var (
// of "EnableAllProposals" (takes precedence over ProposalsEnabled)
// https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34
EnableSpecificProposals = ""

// use this for clarity in argument list
EmptyWasmOpts []wasm.Option
)

// GetEnabledProposals parses the ProposalsEnabled / EnableSpecificProposals values to
Expand Down Expand Up @@ -303,12 +305,10 @@ func init() {
}

// NewOsmosis returns a reference to an initialized Osmosis.
// FIXME: @alpe do we add wasmOpts []wasm.Option here? Do we set that directly in InitNormalKeepers?
// I couldn't find any non-test code that used this. I am guessing we don't need to expose it here
func NewOsmosisApp(
logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool,
homePath string, invCheckPeriod uint, encodingConfig appparams.EncodingConfig, appOpts servertypes.AppOptions,
enabledProposals []wasm.ProposalType,
enabledProposals []wasm.ProposalType, wasmOpts []wasm.Option,
baseAppOptions ...func(*baseapp.BaseApp),
) *OsmosisApp {

Expand Down Expand Up @@ -348,7 +348,7 @@ func NewOsmosisApp(

app.InitSpecialKeepers(skipUpgradeHeights, homePath, invCheckPeriod)
app.setupUpgradeStoreLoaders()
app.InitNormalKeepers(homePath, appOpts, enabledProposals)
app.InitNormalKeepers(homePath, appOpts, enabledProposals, wasmOpts)
app.SetupHooks()
app.setupUpgradeHandlers()

Expand Down
1 change: 1 addition & 0 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func NewAppConstructor(encodingCfg params.EncodingConfig) network.AppConstructor
encodingCfg,
simapp.EmptyAppOptions{},
GetEnabledProposals(),
EmptyWasmOpts,
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),
)
}
Expand Down
4 changes: 2 additions & 2 deletions app/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (app *OsmosisApp) InitNormalKeepers(
homePath string,
appOpts servertypes.AppOptions,
enabledProposals []wasm.ProposalType,
wasmOpts []wasm.Option,
) {
appCodec := app.appCodec
bApp := app.BaseApp
Expand Down Expand Up @@ -294,8 +295,7 @@ func (app *OsmosisApp) InitNormalKeepers(
wasmDir,
wasmConfig,
supportedFeatures,
// TODO: input from caller or just hardcode here?
// wasmOpts...,
wasmOpts...,
)

// wire up x/wasm to IBC
Expand Down
4 changes: 2 additions & 2 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// Setup initializes a new OsmosisApp
func Setup(isCheckTx bool) *OsmosisApp {
db := dbm.NewMemDB()
app := NewOsmosisApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeEncodingConfig(), simapp.EmptyAppOptions{}, GetEnabledProposals())
app := NewOsmosisApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeEncodingConfig(), simapp.EmptyAppOptions{}, GetEnabledProposals(), EmptyWasmOpts)
if !isCheckTx {
genesisState := NewDefaultGenesisState()
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
Expand Down Expand Up @@ -42,7 +42,7 @@ func SetupTestingAppWithLevelDb(isCheckTx bool) (app *OsmosisApp, cleanupFn func
if err != nil {
panic(err)
}
app = NewOsmosisApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeEncodingConfig(), simapp.EmptyAppOptions{}, GetEnabledProposals())
app = NewOsmosisApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeEncodingConfig(), simapp.EmptyAppOptions{}, GetEnabledProposals(), EmptyWasmOpts)
if !isCheckTx {
genesisState := NewDefaultGenesisState()
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
Expand Down
7 changes: 3 additions & 4 deletions cmd/osmosisd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,6 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty
if cast.ToBool(appOpts.Get("telemetry.enabled")) {
wasmOpts = append(wasmOpts, wasmkeeper.WithVMCacheMetrics(prometheus.DefaultRegisterer))
}
// TODO: add this to NewOsmosis App
_ = wasmOpts

return osmosis.NewOsmosisApp(
logger, db, traceStore, true, skipUpgradeHeights,
Expand All @@ -256,6 +254,7 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty
osmosis.MakeEncodingConfig(), // Ideally, we would reuse the one created by NewRootCmd.
appOpts,
osmosis.GetEnabledProposals(),
wasmOpts,
baseapp.SetPruning(pruningOpts),
baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))),
baseapp.SetMinRetainBlocks(cast.ToUint64(appOpts.Get(server.FlagMinRetainBlocks))),
Expand All @@ -279,13 +278,13 @@ func createOsmosisAppAndExport(
encCfg.Marshaler = codec.NewProtoCodec(encCfg.InterfaceRegistry)
var app *osmosis.OsmosisApp
if height != -1 {
app = osmosis.NewOsmosisApp(logger, db, traceStore, false, map[int64]bool{}, "", uint(1), encCfg, appOpts, osmosis.GetEnabledProposals())
app = osmosis.NewOsmosisApp(logger, db, traceStore, false, map[int64]bool{}, "", uint(1), encCfg, appOpts, osmosis.GetEnabledProposals(), osmosis.EmptyWasmOpts)

if err := app.LoadHeight(height); err != nil {
return servertypes.ExportedApp{}, err
}
} else {
app = osmosis.NewOsmosisApp(logger, db, traceStore, true, map[int64]bool{}, "", uint(1), encCfg, appOpts, osmosis.GetEnabledProposals())
app = osmosis.NewOsmosisApp(logger, db, traceStore, true, map[int64]bool{}, "", uint(1), encCfg, appOpts, osmosis.GetEnabledProposals(), osmosis.EmptyWasmOpts)
}

return app.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
Expand Down
2 changes: 2 additions & 0 deletions simapp/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func fullAppSimulation(tb testing.TB, is_testing bool) {
app.MakeEncodingConfig(),
sdkSimapp.EmptyAppOptions{},
app.GetEnabledProposals(),
app.EmptyWasmOpts,
interBlockCacheOpt(),
fauxMerkleModeOpt)

Expand Down Expand Up @@ -156,6 +157,7 @@ func TestAppStateDeterminism(t *testing.T) {
app.MakeEncodingConfig(),
sdkSimapp.EmptyAppOptions{},
app.GetEnabledProposals(),
app.EmptyWasmOpts,
interBlockCacheOpt())

fmt.Printf(
Expand Down

0 comments on commit f0ea88b

Please sign in to comment.