mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-10 21:51:04 +00:00
Add a PolkaVM-based executor (#3458)
This PR adds a new PolkaVM-based executor to Substrate. - The executor can now be used to actually run a PolkaVM-based runtime, and successfully produces blocks. - The executor is always compiled-in, but is disabled by default. - The `SUBSTRATE_ENABLE_POLKAVM` environment variable must be set to `1` to enable the executor, in which case the node will accept both WASM and PolkaVM program blobs (otherwise it'll default to WASM-only). This is deliberately undocumented and not explicitly exposed anywhere (e.g. in the command line arguments, or in the API) to disincentivize anyone from enabling it in production. If/when we'll move this into production usage I'll remove the environment variable and do it "properly". - I did not use our legacy runtime allocator for the PolkaVM executor, so currently every allocation inside of the runtime will leak guest memory until that particular instance is destroyed. The idea here is that I will work on the https://github.com/polkadot-fellows/RFCs/pull/4 which will remove the need for the legacy allocator under WASM, and that will also allow us to use a proper non-leaking allocator under PolkaVM. - I also did some minor cleanups of the WASM executor and deleted some dead code. No prdocs included since this is not intended to be an end-user feature, but an unofficial experiment, and shouldn't affect any current production user. Once this is production-ready a full Polkadot Fellowship RFC will be necessary anyway.
This commit is contained in:
@@ -30,10 +30,10 @@ use sc_executor_common::{
|
||||
error::{Error, Result, WasmError},
|
||||
runtime_blob::RuntimeBlob,
|
||||
util::checked_range,
|
||||
wasm_runtime::{HeapAllocStrategy, InvokeMethod, WasmInstance, WasmModule},
|
||||
wasm_runtime::{HeapAllocStrategy, WasmInstance, WasmModule},
|
||||
};
|
||||
use sp_runtime_interface::unpack_ptr_and_len;
|
||||
use sp_wasm_interface::{HostFunctions, Pointer, Value, WordSize};
|
||||
use sp_wasm_interface::{HostFunctions, Pointer, WordSize};
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
sync::{
|
||||
@@ -41,7 +41,7 @@ use std::{
|
||||
Arc,
|
||||
},
|
||||
};
|
||||
use wasmtime::{AsContext, Engine, Memory, Table};
|
||||
use wasmtime::{AsContext, Engine, Memory};
|
||||
|
||||
const MAX_INSTANCE_COUNT: u32 = 64;
|
||||
|
||||
@@ -51,8 +51,6 @@ pub(crate) struct StoreData {
|
||||
pub(crate) host_state: Option<HostState>,
|
||||
/// This will be always set once the store is initialized.
|
||||
pub(crate) memory: Option<Memory>,
|
||||
/// This will be set only if the runtime actually contains a table.
|
||||
pub(crate) table: Option<Table>,
|
||||
}
|
||||
|
||||
impl StoreData {
|
||||
@@ -164,7 +162,7 @@ pub struct WasmtimeInstance {
|
||||
impl WasmtimeInstance {
|
||||
fn call_impl(
|
||||
&mut self,
|
||||
method: InvokeMethod,
|
||||
method: &str,
|
||||
data: &[u8],
|
||||
allocation_stats: &mut Option<AllocationStats>,
|
||||
) -> Result<Vec<u8>> {
|
||||
@@ -184,20 +182,13 @@ impl WasmtimeInstance {
|
||||
impl WasmInstance for WasmtimeInstance {
|
||||
fn call_with_allocation_stats(
|
||||
&mut self,
|
||||
method: InvokeMethod,
|
||||
method: &str,
|
||||
data: &[u8],
|
||||
) -> (Result<Vec<u8>>, Option<AllocationStats>) {
|
||||
let mut allocation_stats = None;
|
||||
let result = self.call_impl(method, data, &mut allocation_stats);
|
||||
(result, allocation_stats)
|
||||
}
|
||||
|
||||
fn get_global_const(&mut self, name: &str) -> Result<Option<Value>> {
|
||||
match &mut self.strategy {
|
||||
Strategy::RecreateInstance(ref mut instance_creator) =>
|
||||
instance_creator.instantiate()?.get_global_val(name),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Prepare a directory structure and a config file to enable wasmtime caching.
|
||||
|
||||
Reference in New Issue
Block a user