mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-10 23:01:08 +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:
@@ -19,7 +19,6 @@
|
||||
//! Definitions for a wasm runtime.
|
||||
|
||||
use crate::error::Error;
|
||||
use sp_wasm_interface::Value;
|
||||
|
||||
pub use sc_allocator::AllocationStats;
|
||||
|
||||
@@ -30,46 +29,6 @@ pub const DEFAULT_HEAP_ALLOC_STRATEGY: HeapAllocStrategy =
|
||||
/// Default heap allocation pages.
|
||||
pub const DEFAULT_HEAP_ALLOC_PAGES: u32 = 2048;
|
||||
|
||||
/// A method to be used to find the entrypoint when calling into the runtime
|
||||
///
|
||||
/// Contains variants on how to resolve wasm function that will be invoked.
|
||||
pub enum InvokeMethod<'a> {
|
||||
/// Call function exported with this name.
|
||||
///
|
||||
/// Located function should have (u32, u32) -> u64 signature.
|
||||
Export(&'a str),
|
||||
/// Call a function found in the exported table found under the given index.
|
||||
///
|
||||
/// Located function should have (u32, u32) -> u64 signature.
|
||||
Table(u32),
|
||||
/// Call function by reference from table through a wrapper.
|
||||
///
|
||||
/// Invoked function (`dispatcher_ref`) function
|
||||
/// should have (u32, u32, u32) -> u64 signature.
|
||||
///
|
||||
/// `func` will be passed to the invoked function as a first argument.
|
||||
TableWithWrapper {
|
||||
/// Wrapper for the call.
|
||||
///
|
||||
/// Function pointer, index into runtime exported table.
|
||||
dispatcher_ref: u32,
|
||||
/// Extra argument for dispatch.
|
||||
///
|
||||
/// Common usage would be to use it as an actual wasm function pointer
|
||||
/// that should be invoked, but can be used as any extra argument on the
|
||||
/// callee side.
|
||||
///
|
||||
/// This is typically generated and invoked by the runtime itself.
|
||||
func: u32,
|
||||
},
|
||||
}
|
||||
|
||||
impl<'a> From<&'a str> for InvokeMethod<'a> {
|
||||
fn from(val: &'a str) -> InvokeMethod<'a> {
|
||||
InvokeMethod::Export(val)
|
||||
}
|
||||
}
|
||||
|
||||
/// A trait that defines an abstract WASM runtime module.
|
||||
///
|
||||
/// This can be implemented by an execution engine.
|
||||
@@ -87,7 +46,7 @@ pub trait WasmInstance: Send {
|
||||
/// Before execution, instance is reset.
|
||||
///
|
||||
/// Returns the encoded result on success.
|
||||
fn call(&mut self, method: InvokeMethod, data: &[u8]) -> Result<Vec<u8>, Error> {
|
||||
fn call(&mut self, method: &str, data: &[u8]) -> Result<Vec<u8>, Error> {
|
||||
self.call_with_allocation_stats(method, data).0
|
||||
}
|
||||
|
||||
@@ -98,7 +57,7 @@ pub trait WasmInstance: Send {
|
||||
/// Returns the encoded result on success.
|
||||
fn call_with_allocation_stats(
|
||||
&mut self,
|
||||
method: InvokeMethod,
|
||||
method: &str,
|
||||
data: &[u8],
|
||||
) -> (Result<Vec<u8>, Error>, Option<AllocationStats>);
|
||||
|
||||
@@ -110,11 +69,6 @@ pub trait WasmInstance: Send {
|
||||
fn call_export(&mut self, method: &str, data: &[u8]) -> Result<Vec<u8>, Error> {
|
||||
self.call(method.into(), data)
|
||||
}
|
||||
|
||||
/// Get the value from a global with the given `name`.
|
||||
///
|
||||
/// This method is only suitable for getting immutable globals.
|
||||
fn get_global_const(&mut self, name: &str) -> Result<Option<Value>, Error>;
|
||||
}
|
||||
|
||||
/// Defines the heap pages allocation strategy the wasm runtime should use.
|
||||
|
||||
Reference in New Issue
Block a user