Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make supportedCapabilities a slice #492

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions cmd/demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (
)

const (
SUPPORTED_CAPABILITIES = "staking"
PRINT_DEBUG = true
MEMORY_LIMIT = 32 // MiB
CACHE_SIZE = 100 // MiB
PRINT_DEBUG = true
MEMORY_LIMIT = 32 // MiB
CACHE_SIZE = 100 // MiB
)

var SUPPORTED_CAPABILITIES = []string{"staking"}

// This is just a demo to ensure we can compile a static go binary
func main() {
file := os.Args[1]
Expand Down
2 changes: 2 additions & 0 deletions docs/MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
## 1.x -> 2.0

- `VM.Create` was removed. Use `VM.StoreCode` instead.
- The `supportedCapabilities` argument in `NewVM` changed from a comma separated
list to a list of type `[]string`.
5 changes: 3 additions & 2 deletions internal/api/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "C"
import (
"fmt"
"runtime"
"strings"
"syscall"

"github.com/CosmWasm/wasmvm/types"
Expand Down Expand Up @@ -36,9 +37,9 @@ type Cache struct {

type Querier = types.Querier

func InitCache(dataDir string, supportedCapabilities string, cacheSize uint32, instanceMemoryLimit uint32) (Cache, error) {
func InitCache(dataDir string, supportedCapabilities []string, cacheSize uint32, instanceMemoryLimit uint32) (Cache, error) {
dataDirBytes := []byte(dataDir)
supportedCapabilitiesBytes := []byte(supportedCapabilities)
supportedCapabilitiesBytes := []byte(strings.Join(supportedCapabilities, ","))

d := makeView(dataDirBytes)
defer runtime.KeepAlive(dataDirBytes)
Expand Down
5 changes: 3 additions & 2 deletions internal/api/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ import (
)

const (
TESTING_CAPABILITIES = "staking,stargate,iterator,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3"
TESTING_PRINT_DEBUG = false
TESTING_GAS_LIMIT = uint64(500_000_000_000) // ~0.5ms
TESTING_MEMORY_LIMIT = 32 // MiB
TESTING_CACHE_SIZE = 100 // MiB
)

var TESTING_CAPABILITIES = []string{"staking", "stargate", "iterator", "cosmwasm_1_1", "cosmwasm_1_2", "cosmwasm_1_3"}

func TestInitAndReleaseCache(t *testing.T) {
tmpdir, err := os.MkdirTemp("", "wasmvm-testing")
require.NoError(t, err)
Expand Down Expand Up @@ -61,7 +62,7 @@ func TestInitCacheEmptyCapabilities(t *testing.T) {
tmpdir, err := os.MkdirTemp("", "wasmvm-testing")
require.NoError(t, err)
defer os.RemoveAll(tmpdir)
cache, err := InitCache(tmpdir, "", TESTING_CACHE_SIZE, TESTING_MEMORY_LIMIT)
cache, err := InitCache(tmpdir, []string{}, TESTING_CACHE_SIZE, TESTING_MEMORY_LIMIT)
require.NoError(t, err)
ReleaseCache(cache)
}
Expand Down
4 changes: 2 additions & 2 deletions lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ type VM struct {
// NewVM creates a new VM.
//
// `dataDir` is a base directory for Wasm blobs and various caches.
// `supportedCapabilities` is a comma separated list of capabilities suppored by the chain.
// `supportedCapabilities` is a list of capabilities supported by the chain.
// `memoryLimit` is the memory limit of each contract execution (in MiB)
// `printDebug` is a flag to enable/disable printing debug logs from the contract to STDOUT. This should be false in production environments.
// `cacheSize` sets the size in MiB of an in-memory cache for e.g. module caching. Set to 0 to disable.
// `deserCost` sets the gas cost of deserializing one byte of data.
func NewVM(dataDir string, supportedCapabilities string, memoryLimit uint32, printDebug bool, cacheSize uint32) (*VM, error) {
func NewVM(dataDir string, supportedCapabilities []string, memoryLimit uint32, printDebug bool, cacheSize uint32) (*VM, error) {
cache, err := api.InitCache(dataDir, supportedCapabilities, cacheSize, memoryLimit)
if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import (
)

const (
TESTING_CAPABILITIES = "staking,stargate,iterator"
TESTING_PRINT_DEBUG = false
TESTING_GAS_LIMIT = uint64(500_000_000_000) // ~0.5ms
TESTING_MEMORY_LIMIT = 32 // MiB
TESTING_CACHE_SIZE = 100 // MiB
)

var TESTING_CAPABILITIES = []string{"staking", "stargate", "iterator"}

const (
CYBERPUNK_TEST_CONTRACT = "./testdata/cyberpunk.wasm"
HACKATOM_TEST_CONTRACT = "./testdata/hackatom.wasm"
Expand Down