executor: Migrate wasmtime backend to a high-level API (#4686)

* Migrate wasmtime backend to wasmtime-api

* Port to a newer version of wasmtime

* Update to the latest changes.

* Rejig the sandbox module a bit

* Materialze

* Fixes.

* executor wasm_runtime fix

* Refactor everything

* More refactoring

* Even more refactorings

* More cleaning.

* Update to the latest wasmtime

* Reformat

* Renames

* Refactoring and comments.

* Docs

* Rename FunctionExecutor to host.

* Imrpove docs.

* fmt

* Remove panic

* Assert the number of arguments are equal between wasmtime and hostfunc.

* Comment a possible panic if there is no corresponding value variant.

* Check signature of the entrypoint.

* Use git version of wasmtime

* Refine and doc the sandbox code.

* Comment RefCells.

* Update wasmtime to the latest-ish master.

This may solve a problem with segfaults.

* Apply suggestions from code review

Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* Use full SHA1 hash of wasmtime commit.

* Add a panic message.

* Add some documentation

* Update wasmtime version to include SIGSEGV fix

* Update to crates.io version of wasmtime

* Make it work.

* Move the creation of memory into `InstanceWrapper::new`

* Make `InstanceWrapper` !Send & !Sync

* Avoid using `take_mut`

* Update client/executor/wasmtime/Cargo.toml

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Limit maximum size of memory.

* Rename `init_state` to `with_initialized_state`

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Sergei Pepyakin
2020-02-13 14:54:19 +01:00
committed by GitHub
parent c871eaacbc
commit 49af986ad4
15 changed files with 1220 additions and 1376 deletions
+105 -53
View File
@@ -723,24 +723,25 @@ checksum = "e7ca8a5221364ef15ce201e8ed2f609fc312682a8f4e0e3d4aa5879764e0fa3b"
[[package]]
name = "cranelift-bforest"
version = "0.50.0"
version = "0.58.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd05aac8cefcde54ce26178df8f36cb1f518ac691db650e7d2440c2b6b41c4dc"
checksum = "fd0f53d59dc9ab1c8ab68c991d8406b52b7a0aab0b15b05a3a6895579c4e5dd9"
dependencies = [
"cranelift-entity",
]
[[package]]
name = "cranelift-codegen"
version = "0.50.0"
version = "0.58.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c63d9b6ff8a94f98deabab21880d7fd54996e0e16be687b6f80a3b6bdd9c188d"
checksum = "0381a794836fb994c47006465d46d46be072483b667f36013d993b9895117fee"
dependencies = [
"byteorder 1.3.4",
"cranelift-bforest",
"cranelift-codegen-meta",
"cranelift-codegen-shared",
"cranelift-entity",
"gimli 0.20.0",
"log 0.4.8",
"serde",
"smallvec 1.2.0",
@@ -750,9 +751,9 @@ dependencies = [
[[package]]
name = "cranelift-codegen-meta"
version = "0.50.0"
version = "0.58.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cb3df51c2c07d719d02869bfac6cabd8d82ee308d5b29ca62e6528723cc33a4"
checksum = "208c3c8d82bfef32a534c5020c6cfc3bc92f41388f1246b7bb98cf543331abaa"
dependencies = [
"cranelift-codegen-shared",
"cranelift-entity",
@@ -760,24 +761,24 @@ dependencies = [
[[package]]
name = "cranelift-codegen-shared"
version = "0.50.0"
version = "0.58.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "758f9426b2e22bf83fc1a6b231a9d53cd4830751883c7f0e196ebb3c210467b3"
checksum = "ea048c456a517e56fd6df8f0e3947922897e6e6f61fbc5eb557a36c7b8ff6394"
[[package]]
name = "cranelift-entity"
version = "0.50.0"
version = "0.58.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff064733df8b98f453060264a8790393d1e807aca6942706b42f79a4f7aae9ed"
checksum = "0c8c7ed50812194c9e9de1fa39c77b39fc9ab48173d5e7ee88b25b6a8953e9b8"
dependencies = [
"serde",
]
[[package]]
name = "cranelift-frontend"
version = "0.50.0"
version = "0.58.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1eaafb5fa623dcbe19a28084a8226d7a1b17184a949c1a1f29a46b479867998d"
checksum = "21ceb931d9f919731df1b1ecdc716b5c66384b413a7f95909d1f45441ab9bef5"
dependencies = [
"cranelift-codegen",
"log 0.4.8",
@@ -787,9 +788,9 @@ dependencies = [
[[package]]
name = "cranelift-native"
version = "0.50.0"
version = "0.58.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90033dbd7293f6fad4cf9dcd769cd621d60df22b1c5a11799e86359b7447a51d"
checksum = "564ee82268bc25b914fcf331edfc2452f2d9ca34f976b187b4ca668beba250c8"
dependencies = [
"cranelift-codegen",
"raw-cpuid",
@@ -798,9 +799,9 @@ dependencies = [
[[package]]
name = "cranelift-wasm"
version = "0.50.0"
version = "0.58.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54cb82a1071f88822763a583ec1a8688ffe5e2cda02c111d4483dd4376ed14d8"
checksum = "de63e2271b374be5b07f359184e2126a08fb24d24a740cbc178b7e0107ddafa5"
dependencies = [
"cranelift-codegen",
"cranelift-entity",
@@ -808,7 +809,7 @@ dependencies = [
"log 0.4.8",
"serde",
"thiserror",
"wasmparser",
"wasmparser 0.48.2",
]
[[package]]
@@ -1289,9 +1290,9 @@ dependencies = [
[[package]]
name = "faerie"
version = "0.13.0"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f902f2af041f6c7177a2a04f805687cdc71e69c7cbef059a2755d8923f4cd7a8"
checksum = "74b9ed6159e4a6212c61d9c6a86bee01876b192a64accecf58d5b5ae3b667b52"
dependencies = [
"anyhow",
"goblin",
@@ -1858,6 +1859,16 @@ dependencies = [
"stable_deref_trait",
]
[[package]]
name = "gimli"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81dd6190aad0f05ddbbf3245c54ed14ca4aa6dd32f22312b70d8f168c3e3e633"
dependencies = [
"byteorder 1.3.4",
"indexmap",
]
[[package]]
name = "glob"
version = "0.2.11"
@@ -2599,6 +2610,12 @@ version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"
[[package]]
name = "leb128"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a"
[[package]]
name = "libc"
version = "0.2.66"
@@ -5960,11 +5977,6 @@ name = "sc-executor-wasmtime"
version = "0.8.0"
dependencies = [
"assert_matches",
"cranelift-codegen",
"cranelift-entity",
"cranelift-frontend",
"cranelift-native",
"cranelift-wasm",
"log 0.4.8",
"parity-scale-codec",
"parity-wasm 0.41.0",
@@ -5974,9 +5986,7 @@ dependencies = [
"sp-runtime-interface",
"sp-wasm-interface",
"wasmi",
"wasmtime-environ",
"wasmtime-jit",
"wasmtime-runtime",
"wasmtime",
]
[[package]]
@@ -7726,9 +7736,9 @@ checksum = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60"
[[package]]
name = "target-lexicon"
version = "0.9.0"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f4c118a7a38378f305a9e111fcb2f7f838c0be324bfb31a77ea04f7f6e684b4"
checksum = "ab0e7238dcc7b40a7be719a25365910f6807bd864f4cce6b2e6b873658e2b19d"
[[package]]
name = "target_info"
@@ -8310,7 +8320,7 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bfd5b7557925ce778ff9b9ef90e3ade34c524b5ff10e239c69a42d546d2af56"
dependencies = [
"rand 0.3.23",
"rand 0.7.3",
]
[[package]]
@@ -8673,35 +8683,61 @@ dependencies = [
[[package]]
name = "wasmparser"
version = "0.39.3"
version = "0.48.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c702914acda5feeeffbc29e4d953e5b9ce79d8b98da4dbf18a77086e116c5470"
checksum = "073da89bf1c84db000dd68ce660c1b4a08e3a2d28fd1e3394ab9e7abdde4a0f8"
[[package]]
name = "wasmparser"
version = "0.51.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e41b27a1677fe28c115de49efca55dabb14f7fece2c32947ffb9b1064fe5bd4"
[[package]]
name = "wasmtime"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5614d964c3e7d07a13b59aca66103c52656bd80430f0d86dc7eeb3af4f03d4a2"
dependencies = [
"anyhow",
"backtrace",
"cfg-if",
"lazy_static",
"libc",
"region",
"rustc-demangle",
"target-lexicon",
"wasmparser 0.51.1",
"wasmtime-environ",
"wasmtime-jit",
"wasmtime-runtime",
"wat",
"winapi 0.3.8",
]
[[package]]
name = "wasmtime-debug"
version = "0.8.0"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5008729ad53f75020f28fa0d682269335d6f0eac0b3ffafe31f185b2f33aca74"
checksum = "feb5900275b4ef0b621ce725b9d5660b12825d7f7d79b392b97baf089ffab8c0"
dependencies = [
"anyhow",
"cranelift-codegen",
"cranelift-entity",
"cranelift-wasm",
"faerie",
"gimli",
"gimli 0.19.0",
"more-asserts",
"target-lexicon",
"thiserror",
"wasmparser",
"wasmparser 0.51.1",
"wasmtime-environ",
]
[[package]]
name = "wasmtime-environ"
version = "0.8.0"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3947662a0b8e05b1418465e64f16de9114f9fec18cc3f56e0ed5aa7737b89d0"
checksum = "f04661851e133fb11691c4a0f92a705766b4bbf7afc06811f949e295cc8414fc"
dependencies = [
"anyhow",
"base64 0.11.0",
"bincode",
"cranelift-codegen",
@@ -8711,37 +8747,37 @@ dependencies = [
"errno",
"file-per-thread-logger",
"indexmap",
"lazy_static",
"libc",
"log 0.4.8",
"more-asserts",
"rayon",
"serde",
"sha2",
"spin",
"thiserror",
"toml",
"wasmparser",
"wasmparser 0.51.1",
"winapi 0.3.8",
"zstd",
]
[[package]]
name = "wasmtime-jit"
version = "0.8.0"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ed7922689461a7b5bd0d9c7350cac526c8a520a23b3ffd7f5b446ac51dfc51f"
checksum = "d451353764ce55c9bb6a8b260063cfc209b7adadd277a9a872ab4563a69e357c"
dependencies = [
"anyhow",
"cfg-if",
"cranelift-codegen",
"cranelift-entity",
"cranelift-frontend",
"cranelift-native",
"cranelift-wasm",
"more-asserts",
"region",
"target-lexicon",
"thiserror",
"wasmparser",
"wasmparser 0.51.1",
"wasmtime-debug",
"wasmtime-environ",
"wasmtime-runtime",
@@ -8750,16 +8786,14 @@ dependencies = [
[[package]]
name = "wasmtime-runtime"
version = "0.8.0"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "781d6bb8b346efaa3dc39746386957cd79b8d841e8652ed9b02d77bcf64fb514"
checksum = "7dbd4fc114b828cae3e405fed413df4b3814d87a92ea029640cec9ba41f0c162"
dependencies = [
"backtrace",
"cc",
"cranelift-codegen",
"cranelift-entity",
"cranelift-wasm",
"cfg-if",
"indexmap",
"lazy_static",
"libc",
"memoffset",
"more-asserts",
@@ -8769,6 +8803,24 @@ dependencies = [
"winapi 0.3.8",
]
[[package]]
name = "wast"
version = "7.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12a729d076deb29c8509fa71f2d427729f9394f9496844ed8fcab152f35d163d"
dependencies = [
"leb128",
]
[[package]]
name = "wat"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5795e34a4b39893653dec97e644fac85c31398e0ce1abecc48967aac83d9e8ce"
dependencies = [
"wast",
]
[[package]]
name = "web-sys"
version = "0.3.35"