Skip to content

Commit

Permalink
fix(lib/runtime): stub v0.9.17 host API functions (#2420)
Browse files Browse the repository at this point in the history
  • Loading branch information
noot committed Mar 23, 2022
1 parent 30244a8 commit 6a7b223
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/runtime/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/ChainSafe/gossamer/lib/common"
)

var runtimes = []string{HOST_API_TEST_RUNTIME, POLKADOT_RUNTIME, NODE_RUNTIME, DEV_RUNTIME}
var runtimes = []string{HOST_API_TEST_RUNTIME, POLKADOT_RUNTIME, POLKADOT_RUNTIME_v0917, NODE_RUNTIME, DEV_RUNTIME}

//nolint:revive
const (
Expand All @@ -26,6 +26,11 @@ const (
POLKADOT_RUNTIME_FP_v0910 = "polkadot_runtime-v9100.compact.wasm"
POLKADOT_RUNTIME_URL_v0910 = "https://github.com/paritytech/polkadot/releases/download/v0.9.10/polkadot_runtime-v9100.compact.wasm?raw=true" //nolint:lll

// v0.9.17 polkadot runtime
POLKADOT_RUNTIME_v0917 = "polkadot_runtime-v917"
POLKADOT_RUNTIME_FP_v0917 = "polkadot_runtime-v917.compact.wasm"
POLKADOT_RUNTIME_URL_v0917 = "https://github.com/paritytech/polkadot/blob/c583355a599200d64e9202d05f47860d824b4dcf/target/release/wbuild/polkadot-runtime/polkadot_runtime.compact.wasm?raw=true" //nolint:lll

// v0.8 polkadot runtime
POLKADOT_RUNTIME = "polkadot_runtime"
POLKADOT_RUNTIME_FP = "polkadot_runtime.compact.wasm"
Expand Down
2 changes: 2 additions & 0 deletions lib/runtime/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func GetRuntimeVars(targetRuntime string) (string, string) {
return GetAbsolutePath(NODE_RUNTIME_FP), NODE_RUNTIME_URL
case NODE_RUNTIME_v098:
return GetAbsolutePath(NODE_RUNTIME_FP_v098), NODE_RUNTIME_URL_v098
case POLKADOT_RUNTIME_v0917:
return GetAbsolutePath(POLKADOT_RUNTIME_FP_v0917), POLKADOT_RUNTIME_URL_v0917
case POLKADOT_RUNTIME_v0910:
return GetAbsolutePath(POLKADOT_RUNTIME_FP_v0910), POLKADOT_RUNTIME_URL_v0910
case POLKADOT_RUNTIME:
Expand Down
40 changes: 40 additions & 0 deletions lib/runtime/wasmer/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/ChainSafe/gossamer/lib/utils"
"github.com/ChainSafe/gossamer/pkg/scale"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -88,6 +89,45 @@ func TestInstance_Version_PolkadotRuntime_v0910(t *testing.T) {
require.Equal(t, expected.TransactionVersion(), version.TransactionVersion())
}

func TestInstance_Version_PolkadotRuntime_v0917(t *testing.T) {
instance := NewTestInstance(t, runtime.POLKADOT_RUNTIME_v0917)
version, err := instance.Version()
require.NoError(t, err)

expectedSpecName := []byte("polkadot")
expectedImplName := []byte("parity-polkadot")
const (
expectedAuthoringVersion uint32 = 0
expectedSpecVersion uint32 = 9170
expectedImplVersion uint32 = 0
expectedTransactionVersion uint32 = 11
)
expectedAPIItems := []runtime.APIItem{
{Name: [8]uint8{0xdf, 0x6a, 0xcb, 0x68, 0x99, 0x7, 0x60, 0x9b}, Ver: 0x4},
{Name: [8]uint8{0x37, 0xe3, 0x97, 0xfc, 0x7c, 0x91, 0xf5, 0xe4}, Ver: 0x1},
{Name: [8]uint8{0x40, 0xfe, 0x3a, 0xd4, 0x1, 0xf8, 0x95, 0x9a}, Ver: 0x5},
{Name: [8]uint8{0xd2, 0xbc, 0x98, 0x97, 0xee, 0xd0, 0x8f, 0x15}, Ver: 0x3},
{Name: [8]uint8{0xf7, 0x8b, 0x27, 0x8b, 0xe5, 0x3f, 0x45, 0x4c}, Ver: 0x2},
{Name: [8]uint8{0xaf, 0x2c, 0x2, 0x97, 0xa2, 0x3e, 0x6d, 0x3d}, Ver: 0x2},
{Name: [8]uint8{0x49, 0xea, 0xaf, 0x1b, 0x54, 0x8a, 0xc, 0xb0}, Ver: 0x1},
{Name: [8]uint8{0x91, 0xd5, 0xdf, 0x18, 0xb0, 0xd2, 0xcf, 0x58}, Ver: 0x1},
{Name: [8]uint8{0xed, 0x99, 0xc5, 0xac, 0xb2, 0x5e, 0xed, 0xf5}, Ver: 0x3},
{Name: [8]uint8{0xcb, 0xca, 0x25, 0xe3, 0x9f, 0x14, 0x23, 0x87}, Ver: 0x2},
{Name: [8]uint8{0x68, 0x7a, 0xd4, 0x4a, 0xd3, 0x7f, 0x3, 0xc2}, Ver: 0x1},
{Name: [8]uint8{0xab, 0x3c, 0x5, 0x72, 0x29, 0x1f, 0xeb, 0x8b}, Ver: 0x1},
{Name: [8]uint8{0xbc, 0x9d, 0x89, 0x90, 0x4f, 0x5b, 0x92, 0x3f}, Ver: 0x1},
{Name: [8]uint8{0x37, 0xc8, 0xbb, 0x13, 0x50, 0xa9, 0xa2, 0xa8}, Ver: 0x1},
}

assert.Equal(t, expectedAPIItems, version.APIItems())
assert.Equal(t, expectedSpecName, version.SpecName())
assert.Equal(t, expectedImplName, version.ImplName())
assert.Equal(t, expectedAuthoringVersion, version.AuthoringVersion())
assert.Equal(t, expectedSpecVersion, version.SpecVersion())
assert.Equal(t, expectedImplVersion, version.ImplVersion())
assert.Equal(t, expectedTransactionVersion, version.TransactionVersion())
}

func TestInstance_Version_PolkadotRuntime(t *testing.T) {
expected := runtime.NewVersionData(
[]byte("polkadot"),
Expand Down
22 changes: 22 additions & 0 deletions lib/runtime/wasmer/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ package wasmer
//
// extern int32_t ext_trie_blake2_256_root_version_1(void *context, int64_t a);
// extern int32_t ext_trie_blake2_256_ordered_root_version_1(void *context, int64_t a);
// extern int32_t ext_trie_blake2_256_ordered_root_version_2(void *context, int64_t a, int32_t b);
// extern int32_t ext_trie_blake2_256_verify_proof_version_1(void *context, int32_t a, int64_t b, int64_t c, int64_t d);
//
// extern int64_t ext_misc_runtime_version_version_1(void *context, int64_t a);
Expand Down Expand Up @@ -91,6 +92,7 @@ package wasmer
// extern int64_t ext_storage_read_version_1(void *context, int64_t a, int64_t b, int32_t c);
// extern void ext_storage_rollback_transaction_version_1(void *context);
// extern int64_t ext_storage_root_version_1(void *context);
// extern int64_t ext_storage_root_version_2(void *context, int32_t a);
// extern void ext_storage_set_version_1(void *context, int64_t a, int64_t b);
// extern void ext_storage_start_transaction_version_1(void *context);
//
Expand Down Expand Up @@ -871,6 +873,12 @@ func ext_trie_blake2_256_ordered_root_version_1(context unsafe.Pointer, dataSpan
return C.int32_t(ptr)
}

//export ext_trie_blake2_256_ordered_root_version_2
func ext_trie_blake2_256_ordered_root_version_2(context unsafe.Pointer, dataSpan C.int64_t, version C.int32_t) C.int32_t {
// TODO: update to use state trie version 1 (#2418)
return ext_trie_blake2_256_ordered_root_version_1(context, dataSpan)
}

//export ext_trie_blake2_256_verify_proof_version_1
func ext_trie_blake2_256_verify_proof_version_1(context unsafe.Pointer, rootSpan C.int32_t, proofSpan, keySpan, valueSpan C.int64_t) C.int32_t {
logger.Debug("executing...")
Expand Down Expand Up @@ -2055,6 +2063,12 @@ func ext_storage_root_version_1(context unsafe.Pointer) C.int64_t {
return C.int64_t(rootSpan)
}

//export ext_storage_root_version_2
func ext_storage_root_version_2(context unsafe.Pointer, version C.int32_t) C.int64_t {
// TODO: update to use state trie version 1 (#2418)
return ext_storage_root_version_1(context)
}

//export ext_storage_set_version_1
func ext_storage_set_version_1(context unsafe.Pointer, keySpan, valueSpan C.int64_t) {
logger.Trace("executing...")
Expand Down Expand Up @@ -2530,6 +2544,10 @@ func ImportsNodeRuntime() (*wasm.Imports, error) { //nolint:gocyclo
if err != nil {
return nil, err
}
_, err = imports.Append("ext_storage_root_version_2", ext_storage_root_version_2, C.ext_storage_root_version_2)
if err != nil {
return nil, err
}
_, err = imports.Append("ext_storage_set_version_1", ext_storage_set_version_1, C.ext_storage_set_version_1)
if err != nil {
return nil, err
Expand All @@ -2543,6 +2561,10 @@ func ImportsNodeRuntime() (*wasm.Imports, error) { //nolint:gocyclo
if err != nil {
return nil, err
}
_, err = imports.Append("ext_trie_blake2_256_ordered_root_version_2", ext_trie_blake2_256_ordered_root_version_2, C.ext_trie_blake2_256_ordered_root_version_2)
if err != nil {
return nil, err
}
_, err = imports.Append("ext_trie_blake2_256_root_version_1", ext_trie_blake2_256_root_version_1, C.ext_trie_blake2_256_root_version_1)
if err != nil {
return nil, err
Expand Down

0 comments on commit 6a7b223

Please sign in to comment.