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

feat(lib/runtime): wazero implementation of runtime.Instance #3279

Merged
merged 35 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1454dd1
remove wasmer specific interfaces, initial wazero impl
timwu20 May 24, 2023
ee4933e
remove local ref
timwu20 May 24, 2023
be25e72
revise Memory interface, refactor interfaces, fix allocator tests
timwu20 May 29, 2023
4e11d2b
cr feedback
timwu20 Jun 1, 2023
e84bddd
remove wasmer specific interfaces, initial wazero impl
timwu20 May 24, 2023
4be06fb
remove local ref
timwu20 May 24, 2023
3caec21
revise Memory interface, refactor interfaces, fix allocator tests
timwu20 May 29, 2023
222f195
wip
timwu20 Jun 2, 2023
2f9f413
ext_crypto_ed25519_generate_version_1 impl
timwu20 Jun 6, 2023
9d27f95
ext_crypto_ed25519_public_keys_version_1 impl
timwu20 Jun 7, 2023
9beca92
ext_crypto_ed25519_sign_version_1 and ext_crypto_ed25519_verify_versi…
timwu20 Jun 7, 2023
0687454
ext_crypto_secp256k1_ecdsa_recover_version_1, ext_crypto_ecdsa_verify…
timwu20 Jun 7, 2023
25cb0fb
wip
timwu20 Jun 13, 2023
e95008c
add more crypto impl
timwu20 Jun 13, 2023
e59f065
more crypto methods
timwu20 Jun 17, 2023
79e4c2c
ext_misc_print_* functions
timwu20 Jun 17, 2023
3668e6d
ext_misc_runtime_version_version_1 impl
timwu20 Jun 18, 2023
1d242de
child_storage impl
timwu20 Jun 18, 2023
f183ad1
hashing impl
timwu20 Jun 18, 2023
3fd0172
ext_offchain_* impl
timwu20 Jun 19, 2023
e8ca4b3
storage imports
timwu20 Jun 19, 2023
7b845e2
update go.mod go.sum to wazero fork
timwu20 Jun 20, 2023
b1278c3
fulfill Instance interface
timwu20 Jun 20, 2023
5219e11
instance_tests, move genesis to runtime
timwu20 Jun 21, 2023
32a1f11
go mod tidy
timwu20 Jun 21, 2023
6e488e0
fix integration tests
timwu20 Jun 21, 2023
29c130c
remove test
timwu20 Jun 21, 2023
c6880b7
fix lint
timwu20 Jun 21, 2023
a9ac812
cr feedback
timwu20 Jun 21, 2023
57498d3
update to ChainSafe fork
timwu20 Jul 10, 2023
8ec345b
cr feedback
timwu20 Jul 18, 2023
98a1bdb
update ref
timwu20 Jul 18, 2023
0ef3df7
try not caching
timwu20 Jul 18, 2023
a56ccb0
try this
timwu20 Jul 18, 2023
0a87bba
uncomment cache modules
timwu20 Jul 19, 2023
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
6 changes: 3 additions & 3 deletions dot/core/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func createTestService(t *testing.T, genesisFilePath string,
gen, err := genesis.NewGenesisFromJSONRaw(genesisFilePath)
require.NoError(t, err)

genesisTrie, err := wasmer.NewTrieFromGenesis(*gen)
genesisTrie, err := runtime.NewTrieFromGenesis(*gen)
require.NoError(t, err)

// Extrinsic and context related stuff
Expand Down Expand Up @@ -266,7 +266,7 @@ func newWestendLocalWithTrieAndHeader(t *testing.T) (
require.NoError(t, err)
gen = *genPtr

genesisTrie, err = wasmer.NewTrieFromGenesis(gen)
genesisTrie, err = runtime.NewTrieFromGenesis(gen)
require.NoError(t, err)

parentHash := common.NewHash([]byte{0})
Expand All @@ -287,7 +287,7 @@ func getWestendDevRuntimeCode(t *testing.T) (code []byte) {
westendDevGenesis, err := genesis.NewGenesisFromJSONRaw(path)
require.NoError(t, err)

genesisTrie, err := wasmer.NewTrieFromGenesis(*westendDevGenesis)
genesisTrie, err := runtime.NewTrieFromGenesis(*westendDevGenesis)
require.NoError(t, err)

trieState := rtstorage.NewTrieState(&genesisTrie)
Expand Down
4 changes: 2 additions & 2 deletions dot/digest/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/genesis"
"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/trie"
"github.com/ChainSafe/gossamer/lib/utils"
"github.com/stretchr/testify/require"
Expand All @@ -24,7 +24,7 @@ func newWestendDevGenesisWithTrieAndHeader(t *testing.T) (
require.NoError(t, err)
gen = *genesisPtr

genesisTrie, err = wasmer.NewTrieFromGenesis(gen)
genesisTrie, err = runtime.NewTrieFromGenesis(gen)
require.NoError(t, err)

parentHash := common.NewHash([]byte{0})
Expand Down
4 changes: 2 additions & 2 deletions dot/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/genesis"
"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
runtime "github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/trie"
"github.com/ChainSafe/gossamer/lib/utils"
"github.com/stretchr/testify/require"
Expand All @@ -38,7 +38,7 @@ func newWestendDevGenesisWithTrieAndHeader(t *testing.T) (
require.NoError(t, err)
gen = *genPtr

genesisTrie, err = wasmer.NewTrieFromGenesis(gen)
genesisTrie, err = runtime.NewTrieFromGenesis(gen)
timwu20 marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(t, err)

parentHash := common.NewHash([]byte{0})
Expand Down
3 changes: 1 addition & 2 deletions dot/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/ChainSafe/gossamer/lib/grandpa"
"github.com/ChainSafe/gossamer/lib/keystore"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
"github.com/ChainSafe/gossamer/lib/services"
"github.com/ChainSafe/gossamer/lib/utils"
)
Expand Down Expand Up @@ -149,7 +148,7 @@ func (*nodeBuilder) initNode(config *cfg.Config) error {
}

// create trie from genesis
t, err := wasmer.NewTrieFromGenesis(*gen)
t, err := runtime.NewTrieFromGenesis(*gen)
if err != nil {
return fmt.Errorf("failed to create trie from genesis: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion dot/node_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestNewNode(t *testing.T) {
return nil, fmt.Errorf("failed to load genesis from file: %w", err)
}
// create trie from genesis
trie, err := wasmer.NewTrieFromGenesis(*gen)
trie, err := runtime.NewTrieFromGenesis(*gen)
if err != nil {
return nil, fmt.Errorf("failed to create trie from genesis: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions dot/rpc/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/genesis"
"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/trie"
"github.com/ChainSafe/gossamer/lib/utils"
"github.com/stretchr/testify/require"
Expand All @@ -24,7 +24,7 @@ func newWestendDevGenesisWithTrieAndHeader(t *testing.T) (
require.NoError(t, err)
gen = *genesisPtr

genesisTrie, err = wasmer.NewTrieFromGenesis(gen)
genesisTrie, err = runtime.NewTrieFromGenesis(gen)
require.NoError(t, err)

parentHash := common.NewHash([]byte{0})
Expand Down
4 changes: 2 additions & 2 deletions dot/rpc/modules/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/genesis"
"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/trie"
"github.com/ChainSafe/gossamer/lib/utils"
"github.com/stretchr/testify/require"
Expand All @@ -31,7 +31,7 @@ func newWestendLocalGenesisWithTrieAndHeader(t *testing.T) (
require.NoError(t, err)
gen = *genesisPtr

genesisTrie, err = wasmer.NewTrieFromGenesis(gen)
genesisTrie, err = runtime.NewTrieFromGenesis(gen)
require.NoError(t, err)

parentHash := common.NewHash([]byte{0})
Expand Down
4 changes: 2 additions & 2 deletions dot/state/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/genesis"
"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/trie"
"github.com/ChainSafe/gossamer/lib/utils"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -98,7 +98,7 @@ func newWestendDevGenesisWithTrieAndHeader(t *testing.T) (
require.NoError(t, err)
gen = *genesisPtr

genesisTrie, err = wasmer.NewTrieFromGenesis(gen)
genesisTrie, err = runtime.NewTrieFromGenesis(gen)
require.NoError(t, err)

parentHash := common.NewHash([]byte{0})
Expand Down
3 changes: 2 additions & 1 deletion dot/sync/syncer_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ChainSafe/gossamer/internal/log"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/genesis"
runtime "github.com/ChainSafe/gossamer/lib/runtime"
rtstorage "github.com/ChainSafe/gossamer/lib/runtime/storage"
"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
"github.com/ChainSafe/gossamer/lib/trie"
Expand Down Expand Up @@ -131,7 +132,7 @@ func newWestendDevGenesisWithTrieAndHeader(t *testing.T) (
require.NoError(t, err)
gen = *genesisPtr

genesisTrie, err = wasmer.NewTrieFromGenesis(gen)
genesisTrie, err = runtime.NewTrieFromGenesis(gen)
require.NoError(t, err)

parentHash := common.NewHash([]byte{0})
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ require (
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
github.com/tetratelabs/wazero v1.1.0
github.com/wasmerio/go-ext-wasm v0.3.2-0.20200326095750-0a32be6068ec
github.com/whyrusleeping/mdns v0.0.0-20190826153040-b9b60ed33aa9
golang.org/x/crypto v0.11.0
Expand Down Expand Up @@ -197,3 +198,5 @@ require (
)

go 1.20

replace github.com/tetratelabs/wazero => github.com/ChainSafe/wazero v0.0.0-20230710171859-39a4c235ec1f
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ github.com/ChainSafe/go-schnorrkel v1.0.1-0.20220711122024-027d287d27bf h1:S195Z
github.com/ChainSafe/go-schnorrkel v1.0.1-0.20220711122024-027d287d27bf/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4=
github.com/ChainSafe/log15 v1.0.0 h1:vRDVtWtVwIH5uSCBvgTTZh6FA58UBJ6+QiiypaZfBf8=
github.com/ChainSafe/log15 v1.0.0/go.mod h1:5v1+ALHtdW0NfAeeoYyKmzCAMcAeqkdhIg4uxXWIgOg=
github.com/ChainSafe/wazero v0.0.0-20230710171859-39a4c235ec1f h1:/sI8TMJ77HL2UImQs7pY7khVN96EXQJGVOrX88dTpcY=
github.com/ChainSafe/wazero v0.0.0-20230710171859-39a4c235ec1f/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ=
github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8=
Expand Down
4 changes: 2 additions & 2 deletions lib/babe/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func newWestendLocalGenesisWithTrieAndHeader(t *testing.T) (
require.NoError(t, err)
gen = *genesisPtr

genesisTrie, err = wasmer.NewTrieFromGenesis(gen)
genesisTrie, err = runtime.NewTrieFromGenesis(gen)
require.NoError(t, err)

genesisHeader = *types.NewHeader(common.NewHash([]byte{0}),
Expand All @@ -388,7 +388,7 @@ func newWestendDevGenesisWithTrieAndHeader(t *testing.T) (
require.NoError(t, err)
gen = *genesisPtr

genesisTrie, err = wasmer.NewTrieFromGenesis(gen)
genesisTrie, err = runtime.NewTrieFromGenesis(gen)
require.NoError(t, err)

genesisHeader = *types.NewHeader(common.NewHash([]byte{0}),
Expand Down
3 changes: 2 additions & 1 deletion lib/grandpa/helpers_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/crypto/ed25519"
"github.com/ChainSafe/gossamer/lib/genesis"
runtime "github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/runtime/storage"
"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
"github.com/ChainSafe/gossamer/lib/trie"
Expand Down Expand Up @@ -194,7 +195,7 @@ func newWestendDevGenesisWithTrieAndHeader(t *testing.T) (
assert.NoError(t, err)
gen = *genesisPtr

genesisTrie, err = wasmer.NewTrieFromGenesis(gen)
genesisTrie, err = runtime.NewTrieFromGenesis(gen)
assert.NoError(t, err)

parentHash := common.NewHash([]byte{0})
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime/wasmer/genesis.go → lib/runtime/genesis.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2022 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

package wasmer
package runtime

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2022 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

package wasmer
package runtime

import (
"testing"
Expand Down
10 changes: 5 additions & 5 deletions lib/runtime/wasmer/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func Test_Instance_Version(t *testing.T) {
instanceBuilder: func(t *testing.T) instanceVersioner {
genesisPath := utils.GetKusamaGenesisPath(t)
kusamaGenesis := genesisFromRawJSON(t, genesisPath)
genesisTrie, err := NewTrieFromGenesis(kusamaGenesis)
genesisTrie, err := runtime.NewTrieFromGenesis(kusamaGenesis)
require.NoError(t, err)

cfg := Config{
Expand Down Expand Up @@ -170,7 +170,7 @@ func balanceKey(t *testing.T, pub []byte) []byte {
func TestWestendRuntime_ValidateTransaction(t *testing.T) {
genesisPath := utils.GetWestendDevRawGenesisPath(t)
gen := genesisFromRawJSON(t, genesisPath)
genTrie, err := NewTrieFromGenesis(gen)
genTrie, err := runtime.NewTrieFromGenesis(gen)
require.NoError(t, err)

// set state to genesis state
Expand Down Expand Up @@ -472,7 +472,7 @@ func TestInstance_ExecuteBlock_WestendRuntime(t *testing.T) {
func TestInstance_ApplyExtrinsic_WestendRuntime(t *testing.T) {
genesisPath := utils.GetWestendDevRawGenesisPath(t)
gen := genesisFromRawJSON(t, genesisPath)
genTrie, err := NewTrieFromGenesis(gen)
genTrie, err := runtime.NewTrieFromGenesis(gen)
require.NoError(t, err)

// set state to genesis state
Expand Down Expand Up @@ -529,7 +529,7 @@ func TestInstance_ExecuteBlock_PolkadotRuntime(t *testing.T) {
func TestInstance_ExecuteBlock_PolkadotRuntime_PolkadotBlock1(t *testing.T) {
genesisPath := utils.GetPolkadotGenesisPath(t)
gen := genesisFromRawJSON(t, genesisPath)
genTrie, err := NewTrieFromGenesis(gen)
genTrie, err := runtime.NewTrieFromGenesis(gen)
require.NoError(t, err)

expectedGenesisRoot := common.MustHexToHash("0x29d0d972cd27cbc511e9589fcb7a4506d5eb6a9e8df205f00472e5ab354a4e17")
Expand Down Expand Up @@ -579,7 +579,7 @@ func TestInstance_ExecuteBlock_PolkadotRuntime_PolkadotBlock1(t *testing.T) {
func TestInstance_ExecuteBlock_KusamaRuntime_KusamaBlock1(t *testing.T) {
genesisPath := utils.GetKusamaGenesisPath(t)
gen := genesisFromRawJSON(t, genesisPath)
genTrie, err := NewTrieFromGenesis(gen)
genTrie, err := runtime.NewTrieFromGenesis(gen)
require.NoError(t, err)

expectedGenesisRoot := common.MustHexToHash("0xb0006203c3a6e6bd2c6a17b1d4ae8ca49a31da0f4579da950b127774b44aef6b")
Expand Down
Loading