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

Rename features to capabilities #414

Merged
merged 2 commits into from
Apr 5, 2023
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
10 changes: 5 additions & 5 deletions cmd/demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
)

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

// This is just a demo to ensure we can compile a static go binary
Expand All @@ -26,7 +26,7 @@ func main() {
fmt.Println("Loaded!")

os.MkdirAll("tmp", 0o755)
vm, err := wasmvm.NewVM("tmp", SUPPORTED_FEATURES, MEMORY_LIMIT, PRINT_DEBUG, CACHE_SIZE)
vm, err := wasmvm.NewVM("tmp", SUPPORTED_CAPABILITIES, MEMORY_LIMIT, PRINT_DEBUG, CACHE_SIZE)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestIBCHandshake(t *testing.T) {
vm := withVM(t)
checksum := createTestContract(t, vm, IBC_TEST_CONTRACT)
gasMeter1 := api.NewMockGasMeter(TESTING_GAS_LIMIT)
deserCost := types.UFraction{1, 1}
deserCost := types.UFraction{Numerator: 1, Denominator: 1}
// instantiate it with this store
store := api.NewLookup(gasMeter1)
goapi := api.NewMockAPI()
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestIBCPacketDispatch(t *testing.T) {
vm := withVM(t)
checksum := createTestContract(t, vm, IBC_TEST_CONTRACT)
gasMeter1 := api.NewMockGasMeter(TESTING_GAS_LIMIT)
deserCost := types.UFraction{1, 1}
deserCost := types.UFraction{Numerator: 1, Denominator: 1}
// instantiate it with this store
store := api.NewLookup(gasMeter1)
goapi := api.NewMockAPI()
Expand Down
10 changes: 5 additions & 5 deletions internal/api/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ type Cache struct {

type Querier = types.Querier

func InitCache(dataDir string, supportedFeatures string, cacheSize uint32, instanceMemoryLimit uint32) (Cache, error) {
func InitCache(dataDir string, supportedCapabilities string, cacheSize uint32, instanceMemoryLimit uint32) (Cache, error) {
dataDirBytes := []byte(dataDir)
supportedFeaturesBytes := []byte(supportedFeatures)
supportedCapabilitiesBytes := []byte(supportedCapabilities)

d := makeView(dataDirBytes)
defer runtime.KeepAlive(dataDirBytes)
f := makeView(supportedFeaturesBytes)
defer runtime.KeepAlive(supportedFeaturesBytes)
capabilitiesView := makeView(supportedCapabilitiesBytes)
defer runtime.KeepAlive(supportedCapabilitiesBytes)

errmsg := uninitializedUnmanagedVector()

ptr, err := C.init_cache(d, f, cu32(cacheSize), cu32(instanceMemoryLimit), &errmsg)
ptr, err := C.init_cache(d, capabilitiesView, cu32(cacheSize), cu32(instanceMemoryLimit), &errmsg)
if err != nil {
return Cache{}, errorWithMessage(err, errmsg)
}
Expand Down
12 changes: 6 additions & 6 deletions internal/api/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

const (
TESTING_FEATURES = "staking,stargate,iterator,cosmwasm_1_1,cosmwasm_1_2"
TESTING_CAPABILITIES = "staking,stargate,iterator,cosmwasm_1_1,cosmwasm_1_2"
TESTING_PRINT_DEBUG = false
TESTING_GAS_LIMIT = uint64(500_000_000_000) // ~0.5ms
TESTING_MEMORY_LIMIT = 32 // MiB
Expand All @@ -28,7 +28,7 @@ func TestInitAndReleaseCache(t *testing.T) {
require.NoError(t, err)
defer os.RemoveAll(tmpdir)

cache, err := InitCache(tmpdir, TESTING_FEATURES, TESTING_CACHE_SIZE, TESTING_MEMORY_LIMIT)
cache, err := InitCache(tmpdir, TESTING_CAPABILITIES, TESTING_CACHE_SIZE, TESTING_MEMORY_LIMIT)
require.NoError(t, err)
ReleaseCache(cache)
}
Expand All @@ -41,7 +41,7 @@ func TestInitCacheWorksForNonExistentDir(t *testing.T) {
defer os.RemoveAll(tmpdir)

createMe := filepath.Join(tmpdir, "does-not-yet-exist")
cache, err := InitCache(createMe, TESTING_FEATURES, TESTING_CACHE_SIZE, TESTING_MEMORY_LIMIT)
cache, err := InitCache(createMe, TESTING_CAPABILITIES, TESTING_CACHE_SIZE, TESTING_MEMORY_LIMIT)
require.NoError(t, err)
ReleaseCache(cache)
}
Expand All @@ -51,11 +51,11 @@ func TestInitCacheErrorsForBrokenDir(t *testing.T) {
// https://gist.github.com/doctaphred/d01d05291546186941e1b7ddc02034d3
// On Unix we should not have permission to create this.
cannotBeCreated := "/foo:bar"
_, err := InitCache(cannotBeCreated, TESTING_FEATURES, TESTING_CACHE_SIZE, TESTING_MEMORY_LIMIT)
_, err := InitCache(cannotBeCreated, TESTING_CAPABILITIES, TESTING_CACHE_SIZE, TESTING_MEMORY_LIMIT)
require.ErrorContains(t, err, "Error creating state directory")
}

func TestInitCacheEmptyFeatures(t *testing.T) {
func TestInitCacheEmptyCapabilities(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "wasmvm-testing")
require.NoError(t, err)
defer os.RemoveAll(tmpdir)
Expand All @@ -66,7 +66,7 @@ func TestInitCacheEmptyFeatures(t *testing.T) {
func withCache(t *testing.T) (Cache, func()) {
tmpdir, err := ioutil.TempDir("", "wasmvm-testing")
require.NoError(t, err)
cache, err := InitCache(tmpdir, TESTING_FEATURES, TESTING_CACHE_SIZE, TESTING_MEMORY_LIMIT)
cache, err := InitCache(tmpdir, TESTING_CAPABILITIES, TESTING_CACHE_SIZE, TESTING_MEMORY_LIMIT)
require.NoError(t, err)

cleanup := func() {
Expand Down
6 changes: 3 additions & 3 deletions lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ type VM struct {
// NewVM creates a new VM.
//
// `dataDir` is a base directory for Wasm blobs and various caches.
// `supportedFeatures` is a comma separated list of features suppored by the chain.
// `supportedCapabilities` is a comma separated list of capabilities suppored 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, supportedFeatures string, memoryLimit uint32, printDebug bool, cacheSize uint32) (*VM, error) {
cache, err := api.InitCache(dataDir, supportedFeatures, cacheSize, memoryLimit)
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
10 changes: 5 additions & 5 deletions lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

const (
TESTING_FEATURES = "staking,stargate,iterator"
TESTING_CAPABILITIES = "staking,stargate,iterator"
TESTING_PRINT_DEBUG = false
TESTING_GAS_LIMIT = uint64(500_000_000_000) // ~0.5ms
TESTING_MEMORY_LIMIT = 32 // MiB
Expand All @@ -31,7 +31,7 @@ const (
func withVM(t *testing.T) *VM {
tmpdir, err := ioutil.TempDir("", "wasmvm-testing")
require.NoError(t, err)
vm, err := NewVM(tmpdir, TESTING_FEATURES, TESTING_MEMORY_LIMIT, TESTING_PRINT_DEBUG, TESTING_CACHE_SIZE)
vm, err := NewVM(tmpdir, TESTING_CAPABILITIES, TESTING_MEMORY_LIMIT, TESTING_PRINT_DEBUG, TESTING_CACHE_SIZE)
require.NoError(t, err)

t.Cleanup(func() {
Expand Down Expand Up @@ -134,7 +134,7 @@ func TestHappyPath(t *testing.T) {
vm := withVM(t)
checksum := createTestContract(t, vm, HACKATOM_TEST_CONTRACT)

deserCost := types.UFraction{1, 1}
deserCost := types.UFraction{Numerator: 1, Denominator: 1}
gasMeter1 := api.NewMockGasMeter(TESTING_GAS_LIMIT)
// instantiate it with this store
store := api.NewLookup(gasMeter1)
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestEnv(t *testing.T) {
vm := withVM(t)
checksum := createTestContract(t, vm, CYBERPUNK_TEST_CONTRACT)

deserCost := types.UFraction{1, 1}
deserCost := types.UFraction{Numerator: 1, Denominator: 1}
gasMeter1 := api.NewMockGasMeter(TESTING_GAS_LIMIT)
// instantiate it with this store
store := api.NewLookup(gasMeter1)
Expand Down Expand Up @@ -242,7 +242,7 @@ func TestGetMetrics(t *testing.T) {
// Create contract
checksum := createTestContract(t, vm, HACKATOM_TEST_CONTRACT)

deserCost := types.UFraction{1, 1}
deserCost := types.UFraction{Numerator: 1, Denominator: 1}

// GetMetrics 2
metrics, err = vm.GetMetrics()
Expand Down