Skip to main content

VirtT

Trait VirtT 

Source
pub trait VirtT: Sized {
    type Memory: MemoryT;

    // Required methods
    fn instantiate(program: &[u8]) -> Result<Self, InstantiateError>;
    fn run(
        &mut self,
        gas_left: i64,
        action: ExecAction<'_>,
    ) -> Result<ExecOutcome, ExecError>;
    fn memory(&self) -> Self::Memory;
}
Expand description

A virtualization instance that can be called into multiple times.

There are only two implementations of this trait. One which is used within runtime builds. We call this the forwarder since it only forwards the calls to host functions. The other one is the native implementation which is used to implement said host functions and is also used by the pallet’s test code.

A trait is not strictly necessary but makes sure that both implementations do not diverge.

§⚠️ Unstable — Do Not Use in Production

This trait and its implementations are unstable. The virtualization host functions are not available on Polkadot until the API is stabilized. Using them in a production runtime will cause breakage when the API changes. Only use for testing and experimentation.

Required Associated Types§

Source

type Memory: MemoryT

The memory implementation of this instance.

Required Methods§

Source

fn instantiate(program: &[u8]) -> Result<Self, InstantiateError>

Compile and instantiate the passed program.

The passed program has to be a valid PolkaVM program.

Source

fn run( &mut self, gas_left: i64, action: ExecAction<'_>, ) -> Result<ExecOutcome, ExecError>

Execute or resume a virtualization instance.

When action is ExecAction::Execute, starts executing the named exported function. The function must not take any arguments nor return any results. When action is ExecAction::Resume, resumes after a syscall with the given return value (written into register a0).

Returns ExecOutcome::Finished when execution completes or ExecOutcome::Syscall when a host function is called. In the latter case, the caller should handle the syscall and call this method again with ExecAction::Resume to continue.

  • gas_left: How much gas the execution is allowed to consume.
  • action: Whether to start a new execution or resume an existing one.
Source

fn memory(&self) -> Self::Memory

Get a reference to the instances memory.

Memory access will fail with an error when this instance was destroyed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl VirtT for Virt

Source§

type Memory = Memory