Skip to main content

RuntimeBlob

Struct RuntimeBlob 

Source
pub struct RuntimeBlob(/* private fields */);
Expand description

A program blob containing a Substrate runtime.

Implementations§

Source§

impl RuntimeBlob

Source

pub fn uncompress_if_needed(wasm_code: &[u8]) -> Result<Self, WasmError>

Create RuntimeBlob from the given WASM or PolkaVM compressed program blob.

See sp_maybe_compressed_blob for details about decompression.

Source

pub fn new(raw_blob: &[u8]) -> Result<Self, WasmError>

Create RuntimeBlob from the given WASM or PolkaVM program blob.

Returns Err if the blob cannot be deserialized.

Will only accept a PolkaVM program if the SUBSTRATE_ENABLE_POLKAVM environment variable is set to 1.

Source

pub fn inject_stack_depth_metering( self, stack_depth_limit: u32, ) -> Result<Self, WasmError>

Run a pass that instrument this module so as to introduce a deterministic stack height limit.

It will introduce a global mutable counter. The instrumentation will increase the counter according to the “cost” of the callee. If the cost exceeds the stack_depth_limit constant, the instrumentation will trap. The counter will be decreased as soon as the the callee returns.

The stack cost of a function is computed based on how much locals there are and the maximum depth of the wasm operand stack.

Only valid for WASM programs; will return an error if the blob is a PolkaVM program.

Source

pub fn convert_memory_import_into_export(&mut self) -> Result<(), WasmError>

Converts a WASM memory import into a memory section and exports it.

Does nothing if there’s no memory import.

May return an error in case the WASM module is invalid.

Only valid for WASM programs; will return an error if the blob is a PolkaVM program.

Source

pub fn setup_memory_according_to_heap_alloc_strategy( &mut self, heap_alloc_strategy: HeapAllocStrategy, ) -> Result<(), WasmError>

Modifies the blob’s memory section according to the given heap_alloc_strategy.

Will return an error in case there is no memory section present, or if the memory section is empty.

Only valid for WASM programs; will return an error if the blob is a PolkaVM program.

Source

pub fn custom_section_contents(&self, section_name: &str) -> Option<&[u8]>

Scans the wasm blob for the first section with the name that matches the given. Returns the contents of the custom section if found or None otherwise.

Only valid for WASM programs; will return an error if the blob is a PolkaVM program.

Source

pub fn serialize(self) -> Vec<u8>

Consumes this runtime blob and serializes it.

Source

pub fn as_polkavm_blob(&self) -> Option<&ProgramBlob<'_>>

Gets a reference to the inner PolkaVM program blob, if this is a PolkaVM program.

Trait Implementations§

Source§

impl Clone for RuntimeBlob

Source§

fn clone(&self) -> RuntimeBlob

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MaybeRefUnwindSafe for T
where T: RefUnwindSafe,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.