Supporting WasmEdge as an alternative Substrate WebAssembly runtime. This project increases the Substrate ecosystem's node software diversity by supporting an alternative high-performance WebAssembly Runtime implementation.
Currently, Substrate runs on the wasmtime WebAssembly runtime created by the Mozilla and Fastly team. WasmEdge is another leading WebAssembly runtime hosted by the Linux Foundation / Cloud Native Computing Foundation (CNCF). It is fully compliant to the WebAssembly specification as well as standard WebAssembly extensions. It is supported across many OSes including Linux, Windows, Mac OS X, seL4, and CPU architectures including x86, aarch64, and Apple M1. WasmEdge is among the fastest WebAssembly runtimes available today.
Compared with wasmtime, WasmEdge features a completely different software architecture. It is written in C++ and depends on the LLVM for runtime code generation, while wasmtime is written in Rust and depends on Cranelift for dynamic compilation. That makes WasmEdge a compelling choice for improving Substrate software stack diversity.
In this project, we use WasmEdge as an alternative WebAssembly runtime for Substrate. We also create a software layer that allows users to choose between wasmtime and WasmEdge when they build Substrate from source.
Note: This project is still in a testing state, so don't use it in production!
This project contains several folders:
WasmEdge
: WasmEdge code included (version). In order to use the latest code, we specify thewasmedge-sys
crate on a local path incargo.toml
.substrate
: Substrate code included (version). The path of the WasmEdge Executor issubstrate/client/executor/wasmedge
.
-
Follow this document to install the packages and rust environment required for Substrate.
-
It is recommended to use the following command to install WasmEdge. However, you can also follow this document to install.
$ cd WasmEdge/utils $ ./install.sh
Using WasmEdge as the Executor:
$ cd substrate/bin/node-template
$ cargo run --release --bin node-template -- \
--dev \
--wasm-execution=compiledWasmedge \
--validator \
--execution=Wasm \
--tmp \
--unsafe-ws-external
If you see the following message, then you've run it successfully! Congratulations!
2022-08-21 05:43:42 ✨ Imported #1 (0xabc1…bd8e)
2022-08-21 05:43:42 💤 Idle (0 peers), best: #1 (0xabc1…bd8e), finalized #0 (0x5640…1677), ⬇ 0 ⬆ 0
2022-08-21 05:43:47 💤 Idle (0 peers), best: #1 (0xabc1…bd8e), finalized #0 (0x5640…1677), ⬇ 0 ⬆ 0
2022-08-21 05:43:48 🙌 Starting consensus session on top of parent 0xabc17a0827771aaf56e027cc176f15bfe5f7589722e790e313e219df75f1bd8e
2022-08-21 05:43:48 🎁 Prepared block for proposing at 2 (0 ms) [hash: 0x6014c89e774871a92ba729addd9e90fdc7290a0da1604f99f07b509286d5e500; parent_hash: 0xabc1…bd8e; extrinsics (1): [0xb1b9…5b5c]]
2022-08-21 05:43:48 🔖 Pre-sealed block for proposal at 2. Hash now 0xe2919bdfbca4c2811f36b02db687fa4d4d5640fcca9fd9f75125d2a101869038, previously 0x6014c89e774871a92ba729addd9e90fdc7290a0da1604f99f07b509286d5e500.
By the way, you can also use wasmtime as the Executor in the following way:
$ cd substrate/bin/node-template
$ cargo run --release --bin node-template -- --dev --wasm-execution=compiled
- Substrate Client (
/substrate/client/*
) is licensed under GPL v3.0 with a classpath linking exception. - Everything else is licensed under Apache v2.0