Add wasmconfig and default config

This commit is contained in:
anilCSE 2020-01-18 14:03:03 +05:30
parent 2eff7112ea
commit 84f63203d1
5 changed files with 32 additions and 15 deletions

View File

@ -1,6 +1,7 @@
package app
import (
"fmt"
"io"
"os"
"path/filepath"
@ -38,8 +39,6 @@ import (
)
const appName = "WasmApp"
const flagLRUCacheSize = "lru_size"
const flagQueryGasLimit = "query_gas_limit"
var (
// DefaultCLIHome default home directories for wasmcli
@ -184,13 +183,13 @@ func NewWasmApp(
homeDir := viper.GetString(cli.HomeFlag)
wasmDir := filepath.Join(homeDir, "wasm")
// Read LRU cache size from config (app.toml), defaults to `0`
cacheSize := uint64(viper.GetInt64(flagLRUCacheSize))
// Read query gas limit from config
smartQueryGasLimit := uint64(viper.GetInt64(flagQueryGasLimit))
wasmConfig := wasm.DefaultWasmConfig()
err := viper.Unmarshal(&wasmConfig)
if err != nil {
fmt.Println("error while reading wasm config:", err.Error())
}
app.wasmKeeper = wasm.NewKeeper(app.cdc, keys[wasm.StoreKey], app.accountKeeper, app.bankKeeper, wasmRouter,
wasmDir, cacheSize, smartQueryGasLimit)
app.wasmKeeper = wasm.NewKeeper(app.cdc, keys[wasm.StoreKey], app.accountKeeper, app.bankKeeper, wasmRouter, wasmDir, wasmConfig)
// create evidence keeper with evidence router
app.evidenceKeeper = evidence.NewKeeper(

View File

@ -54,6 +54,7 @@ var (
NewWasmCoins = types.NewWasmCoins
NewContractInfo = types.NewContractInfo
CosmosResult = types.CosmosResult
DefaultWasmConfig = types.DefaultWasmConfig
// genesis aliases
ValidateGenesis = types.ValidateGenesis
@ -77,6 +78,7 @@ type (
MsgExecuteContract = types.MsgExecuteContract
CodeInfo = types.CodeInfo
ContractInfo = types.ContractInfo
WasmConfig = types.WasmConfig
GenesisState = types.GenesisState
)

View File

@ -43,8 +43,8 @@ type Keeper struct {
// NewKeeper creates a new contract Keeper instance
func NewKeeper(cdc *codec.Codec, storeKey sdk.StoreKey, accountKeeper auth.AccountKeeper, bankKeeper bank.Keeper,
router sdk.Router, homeDir string, cacheSize uint64, smartQueryGasLimit uint64) Keeper {
wasmer, err := wasm.NewWasmer(filepath.Join(homeDir, "wasm"), cacheSize)
router sdk.Router, homeDir string, wasmConfig types.WasmConfig) Keeper {
wasmer, err := wasm.NewWasmer(filepath.Join(homeDir, "wasm"), wasmConfig.CacheSize)
if err != nil {
panic(err)
}
@ -56,7 +56,7 @@ func NewKeeper(cdc *codec.Codec, storeKey sdk.StoreKey, accountKeeper auth.Accou
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
router: router,
queryGasLimit: smartQueryGasLimit,
queryGasLimit: wasmConfig.SmartQueryGasLimit,
}
}

View File

@ -16,6 +16,8 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"
wasmTypes "github.com/cosmwasm/wasmd/x/wasm/internal/types"
)
const flagLRUCacheSize = "lru_size"
@ -72,11 +74,10 @@ func CreateTestInput(t *testing.T, isCheckTx bool, tempDir string) (sdk.Context,
h := bank.NewHandler(bk)
router.AddRoute(bank.RouterKey, h)
// TODO Read LRU cache size, query gas limit from app.toml
cacheSize := uint64(3)
smartQueryGasLimit := uint64(3000000)
// Load default wasm config
wasmConfig := wasmTypes.DefaultWasmConfig()
keeper := NewKeeper(cdc, keyContract, accountKeeper, bk, router, tempDir, cacheSize, smartQueryGasLimit)
keeper := NewKeeper(cdc, keyContract, accountKeeper, bk, router, tempDir, wasmConfig)
return ctx, accountKeeper, keeper
}

View File

@ -6,6 +6,9 @@ import (
auth "github.com/cosmos/cosmos-sdk/x/auth/exported"
)
const defaultLRUCacheSize = uint64(0)
const defaultQueryGasLimit = uint64(3000000)
// Model is a struct that holds a KV pair
type Model struct {
Key string `json:"key"`
@ -81,3 +84,15 @@ func CosmosResult(wasmResult wasmTypes.Result) sdk.Result {
GasUsed: wasmResult.GasUsed,
}
}
type WasmConfig struct {
SmartQueryGasLimit uint64 `mapstructure:"query_gas_limit"`
CacheSize uint64 `mapstructure:"lru_size"`
}
func DefaultWasmConfig() WasmConfig {
return WasmConfig{
SmartQueryGasLimit: defaultQueryGasLimit,
CacheSize: defaultLRUCacheSize,
}
}