Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe committed Nov 17, 2020
1 parent 61c0374 commit da377d8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
10 changes: 8 additions & 2 deletions x/wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ This should be a brief overview of the functionality

## Configuration

You can add the following section to `config/app.toml`. Below is shown with defaults:
You can add the following section to `config/app.toml`:

```toml
[wasm]
# This is the maximum sdk gas (wasm and storage) that we allow for any x/wasm "smart" queries
query_gas_limit = 300000
# This defines the memory size for Wasm modules that we can keep cached to speed-up instantiation
# The value is in MiB not bytes
lru_cache_size = 0
memory_cache_size = 300
```

The values can also be set via CLI flags on with the `start` command:
```shell script
--wasm.memory_cache_size uint32 Sets the size in MiB (NOT bytes) of an in-memory cache for wasm modules. Set to 0 to disable. (default 100)
--wasm.query_gas_limit uint Set the max gas that can be spent on executing a query with a Wasm contract (default 3000000)
```

## Events
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/internal/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func NewKeeper(
customEncoders *MessageEncoders,
customPlugins *QueryPlugins,
) Keeper {
wasmer, err := wasmvm.NewVM(filepath.Join(homeDir, "wasm"), supportedFeatures, wasmConfig.ContractDebugMode, wasmConfig.LRUCacheSize)
wasmer, err := wasmvm.NewVM(filepath.Join(homeDir, "wasm"), supportedFeatures, wasmConfig.ContractDebugMode, wasmConfig.MemoryCacheSize)
if err != nil {
panic(err)
}
Expand Down
9 changes: 4 additions & 5 deletions x/wasm/internal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
)

const (
DisabledLRUCacheSize uint32 = 0
defaultLRUCacheSize uint32 = 100 // in MiB
defaultMemoryCacheSize uint32 = 100 // in MiB
defaultQueryGasLimit uint64 = 3000000
defaultContractDebugMode = false
)
Expand Down Expand Up @@ -208,8 +207,8 @@ func ParseEvents(logs []wasmvmtypes.EventAttribute, contractAddr sdk.AccAddress)
// WasmConfig is the extra config required for wasm
type WasmConfig struct {
SmartQueryGasLimit uint64
// LRUCacheSize in MiB not bytes
LRUCacheSize uint32
// MemoryCacheSize in MiB not bytes
MemoryCacheSize uint32
// ContractDebugMode log what contract print
ContractDebugMode bool
}
Expand All @@ -218,7 +217,7 @@ type WasmConfig struct {
func DefaultWasmConfig() WasmConfig {
return WasmConfig{
SmartQueryGasLimit: defaultQueryGasLimit,
LRUCacheSize: defaultLRUCacheSize,
MemoryCacheSize: defaultMemoryCacheSize,
ContractDebugMode: defaultContractDebugMode,
}
}
10 changes: 5 additions & 5 deletions x/wasm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ var (

// Module init related flags
const (
flagWasmLRUSize = "wasm.lru_cache_size"
flagWasmQueryGasLimit = "wasm.query_gas_limit"
flagWasmMemoryCacheSize = "wasm.memory_cache_size"
flagWasmQueryGasLimit = "wasm.query_gas_limit"
)

// AppModuleBasic defines the basic application module used by the wasm module.
Expand Down Expand Up @@ -185,16 +185,16 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp
// AddModuleInitFlags implements servertypes.ModuleInitFlags interface.
func AddModuleInitFlags(startCmd *cobra.Command) {
defaults := DefaultWasmConfig()
startCmd.Flags().Uint32(flagWasmLRUSize, defaults.LRUCacheSize, "Sets the size in MiB (NOT bytes) of an in-memory cache for wasm contract instances. Set to 0 to disable.")
startCmd.Flags().Uint32(flagWasmMemoryCacheSize, defaults.MemoryCacheSize, "Sets the size in MiB (NOT bytes) of an in-memory cache for Wasm modules. Set to 0 to disable.")
startCmd.Flags().Uint64(flagWasmQueryGasLimit, defaults.SmartQueryGasLimit, "Set the max gas that can be spent on executing a query with a Wasm contract")
}

// ReadWasmConfig reads the wasm specifig configuration
func ReadWasmConfig(opts servertypes.AppOptions) (types.WasmConfig, error) {
cfg := types.DefaultWasmConfig()
var err error
if v := opts.Get(flagWasmLRUSize); v != nil {
if cfg.LRUCacheSize, err = cast.ToUint32E(v); err != nil {
if v := opts.Get(flagWasmMemoryCacheSize); v != nil {
if cfg.MemoryCacheSize, err = cast.ToUint32E(v); err != nil {
return cfg, err
}
}
Expand Down
8 changes: 4 additions & 4 deletions x/wasm/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,15 @@ func TestReadWasmConfig(t *testing.T) {
},
exp: types.WasmConfig{
SmartQueryGasLimit: 1,
LRUCacheSize: defaults.LRUCacheSize,
MemoryCacheSize: defaults.MemoryCacheSize,
},
},
"set cache via opts": {
src: AppOptionsMock{
"wasm.lru_cache_size": 2,
"wasm.memory_cache_size": 2,
},
exp: types.WasmConfig{
LRUCacheSize: 2,
MemoryCacheSize: 2,
SmartQueryGasLimit: defaults.SmartQueryGasLimit,
},
},
Expand All @@ -400,7 +400,7 @@ func TestReadWasmConfig(t *testing.T) {
},
exp: types.WasmConfig{
SmartQueryGasLimit: defaults.SmartQueryGasLimit,
LRUCacheSize: defaults.LRUCacheSize,
MemoryCacheSize: defaults.MemoryCacheSize,
ContractDebugMode: true,
},
},
Expand Down

0 comments on commit da377d8

Please sign in to comment.