Skip to content

Commit

Permalink
Add VMConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Oct 7, 2024
1 parent 9d6098b commit 630bde9
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 13 deletions.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ func NewWasmApp(
app.GRPCQueryRouter(),
wasmDir,
nodeConfig,
wasmtypes.VMConfig{},
wasmkeeper.BuiltInCapabilities(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
wasmOpts...,
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/keeper/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func BenchmarkInstantiationOverhead(b *testing.B) {
for name, spec := range specs {
b.Run(name, func(b *testing.B) {
nodeConfig := types.NodeConfig{MemoryCacheSize: 0}
ctx, keepers := createTestInput(b, false, AvailableCapabilities, nodeConfig, spec.db())
ctx, keepers := createTestInput(b, false, AvailableCapabilities, nodeConfig, types.VMConfig{}, spec.db())
example := InstantiateHackatomExampleContract(b, ctx, keepers)
if spec.pinned {
require.NoError(b, keepers.ContractKeeper.PinCode(ctx, example.CodeID))
Expand Down Expand Up @@ -87,7 +87,7 @@ func BenchmarkCompilation(b *testing.B) {
b.Run(name, func(b *testing.B) {
nodeConfig := types.NodeConfig{MemoryCacheSize: 0}
db := dbm.NewMemDB()
ctx, keepers := createTestInput(b, false, AvailableCapabilities, nodeConfig, db)
ctx, keepers := createTestInput(b, false, AvailableCapabilities, nodeConfig, types.VMConfig{}, db)

// print out code size for comparisons
code, err := os.ReadFile(spec.wasmFile)
Expand Down
2 changes: 2 additions & 0 deletions x/wasm/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"

"github.com/CosmWasm/wasmd/x/wasm/types"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
)

func TestGenesisExportImport(t *testing.T) {
Expand Down Expand Up @@ -698,6 +699,7 @@ func setupKeeper(t *testing.T) (*Keeper, sdk.Context) {
nil,
tempDir,
nodeConfig,
wasmtypes.VMConfig{},
AvailableCapabilities,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
Expand Down
5 changes: 3 additions & 2 deletions x/wasm/keeper/keeper_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func NewKeeper(
_ GRPCQueryRouter,
homeDir string,
nodeConfig types.NodeConfig,
vmConfig types.VMConfig,
availableCapabilities []string,
authority string,
opts ...Option,
Expand All @@ -58,7 +59,7 @@ func NewKeeper(
types.AuthZActionInstantiate: {},
},
authority: authority,
wasmLimits: nodeConfig.WasmLimits,
wasmLimits: vmConfig.WasmLimits,
}
keeper.messenger = NewDefaultMessageHandler(keeper, router, ics4Wrapper, channelKeeper, capabilityKeeper, bankKeeper, cdc, portSource)
keeper.wasmVMQueryHandler = DefaultQueryPlugins(bankKeeper, stakingKeeper, distrKeeper, channelKeeper, keeper)
Expand All @@ -79,7 +80,7 @@ func NewKeeper(
MemoryCacheSize: wasmvmtypes.NewSizeMebi(contractMemoryLimit),
InstanceMemoryLimit: wasmvmtypes.NewSizeMebi(nodeConfig.MemoryCacheSize),
},
WasmLimits: nodeConfig.WasmLimits,
WasmLimits: vmConfig.WasmLimits,
}, nodeConfig.ContractDebugMode)
if err != nil {
panic(err)
Expand Down
1 change: 1 addition & 0 deletions x/wasm/keeper/keeper_no_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func NewKeeper(
_ GRPCQueryRouter,
homeDir string,
nodeConfig types.NodeConfig,
vmConfig types.VMConfig,
availableCapabilities string,
authority string,
opts ...Option,
Expand Down
9 changes: 5 additions & 4 deletions x/wasm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ func TestCreateNilCreatorAddress(t *testing.T) {
func TestWasmLimits(t *testing.T) {
one := uint32(1)
cfg := types.DefaultNodeConfig()
cfg.WasmLimits = wasmvmtypes.WasmLimits{
MaxImports: &one, // very low limit that every contract will fail
}
ctx, keepers := createTestInput(t, false, AvailableCapabilities, cfg, dbm.NewMemDB())
ctx, keepers := createTestInput(t, false, AvailableCapabilities, cfg, types.VMConfig{
WasmLimits: wasmvmtypes.WasmLimits{
MaxImports: &one, // very low limit that every contract will fail
},
}, dbm.NewMemDB())
keeper := keepers.ContractKeeper

deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 1))
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/keeper/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func TestConstructorOptions(t *testing.T) {
opt := spec.srcOpt
_, gotPostOptMarker := opt.(postOptsFn)
require.Equal(t, spec.isPostOpt, gotPostOptMarker)
k := NewKeeper(codec, runtime.NewKVStoreService(storeKey), authkeeper.AccountKeeper{}, &bankkeeper.BaseKeeper{}, stakingkeeper.Keeper{}, nil, nil, nil, nil, nil, nil, nil, nil, tempDir, types.DefaultNodeConfig(), AvailableCapabilities, "", spec.srcOpt)
k := NewKeeper(codec, runtime.NewKVStoreService(storeKey), authkeeper.AccountKeeper{}, &bankkeeper.BaseKeeper{}, stakingkeeper.Keeper{}, nil, nil, nil, nil, nil, nil, nil, nil, tempDir, types.DefaultNodeConfig(), types.VMConfig{}, AvailableCapabilities, "", spec.srcOpt)
spec.verify(t, k)
})
}
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ func TestQueryContractInfo(t *testing.T) {
}

func TestQueryWasmLimitsConfig(t *testing.T) {
cfg := types.DefaultNodeConfig()
cfg := types.VMConfig{}

fifteen := uint32(15)

Expand Down Expand Up @@ -718,7 +718,7 @@ func TestQueryWasmLimitsConfig(t *testing.T) {
t.Run(name, func(t *testing.T) {
cfg.WasmLimits = spec.limits

ctx, keepers := createTestInput(t, false, AvailableCapabilities, cfg, dbm.NewMemDB())
ctx, keepers := createTestInput(t, false, AvailableCapabilities, types.DefaultNodeConfig(), cfg, dbm.NewMemDB())
keeper := keepers.WasmKeeper

q := Querier(keeper)
Expand Down
6 changes: 4 additions & 2 deletions x/wasm/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func CreateDefaultTestInput(t testing.TB) (sdk.Context, TestKeepers) {
// CreateTestInput encoders can be nil to accept the defaults, or set it to override some of the message handlers (like default)
func CreateTestInput(t testing.TB, isCheckTx bool, availableCapabilities []string, opts ...Option) (sdk.Context, TestKeepers) {
// Load default wasm config
return createTestInput(t, isCheckTx, availableCapabilities, types.DefaultNodeConfig(), dbm.NewMemDB(), opts...)
return createTestInput(t, isCheckTx, availableCapabilities, types.DefaultNodeConfig(), types.VMConfig{}, dbm.NewMemDB(), opts...)
}

// encoders can be nil to accept the defaults, or set it to override some of the message handlers (like default)
Expand All @@ -221,6 +221,7 @@ func createTestInput(
isCheckTx bool,
availableCapabilities []string,
nodeConfig types.NodeConfig,
vmConfig types.VMConfig,
db dbm.DB,
opts ...Option,
) (sdk.Context, TestKeepers) {
Expand Down Expand Up @@ -359,7 +360,7 @@ func createTestInput(

faucet := NewTestFaucet(t, ctx, bankKeeper, minttypes.ModuleName, sdk.NewCoin("stake", sdkmath.NewInt(100_000_000_000)))

// set some funds ot pay out validatores, based on code from:
// set some funds to pay out validators, based on code from:
// https://github.com/cosmos/cosmos-sdk/blob/fea231556aee4d549d7551a6190389c4328194eb/x/distribution/keeper/keeper_test.go#L50-L57
distrAcc := distKeeper.GetDistributionAccount(ctx)
faucet.Fund(ctx, distrAcc.GetAddress(), sdk.NewCoin("stake", sdkmath.NewInt(2000000)))
Expand Down Expand Up @@ -406,6 +407,7 @@ func createTestInput(
querier,
tempDir,
nodeConfig,
vmConfig,
availableCapabilities,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
opts...,
Expand Down
6 changes: 6 additions & 0 deletions x/wasm/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ func NewWasmCoins(cosmosCoins sdk.Coins) (wasmCoins []wasmvmtypes.Coin) {
return wasmCoins
}

// VMConfig contains configurations that are passed on to CosmWasm VM.
type VMConfig struct {
// WasmLimits are the limits that are used for static validation of Wasm binaries.
WasmLimits wasmvmtypes.WasmLimits
}

// NodeConfig is the extra config required for wasm
type NodeConfig struct {
// SimulationGasLimit is the max gas to be used in a tx simulation call.
Expand Down

0 comments on commit 630bde9

Please sign in to comment.