pub trait Runtime {
Show 23 methods // Required methods fn write_output(&mut self, from: &[u8]) -> Result<(), RuntimeError>; fn write_debug(&self, msg: &str); fn read_input(&mut self) -> Result<Option<Message>, RuntimeError>; fn store_has<T>(&self, path: &T) -> Result<Option<ValueType>, RuntimeError> where T: Path; fn store_read<T>( &self, path: &T, from_offset: usize, max_bytes: usize ) -> Result<Vec<u8, Global>, RuntimeError> where T: Path; fn store_read_slice<T>( &self, path: &T, from_offset: usize, buffer: &mut [u8] ) -> Result<usize, RuntimeError> where T: Path; fn store_read_all( &self, path: &impl Path ) -> Result<Vec<u8, Global>, RuntimeError>; fn store_write<T>( &mut self, path: &T, src: &[u8], at_offset: usize ) -> Result<(), RuntimeError> where T: Path; fn store_write_all<T>( &mut self, path: &T, src: &[u8] ) -> Result<(), RuntimeError> where T: Path; fn store_delete<T>(&mut self, path: &T) -> Result<(), RuntimeError> where T: Path; fn store_delete_value<T>(&mut self, path: &T) -> Result<(), RuntimeError> where T: Path; fn store_count_subkeys<T>(&self, prefix: &T) -> Result<u64, RuntimeError> where T: Path; fn store_move( &mut self, from_path: &impl Path, to_path: &impl Path ) -> Result<(), RuntimeError>; fn store_copy( &mut self, from_path: &impl Path, to_path: &impl Path ) -> Result<(), RuntimeError>; fn reveal_preimage( &self, hash: &[u8; 33], destination: &mut [u8] ) -> Result<usize, RuntimeError>; fn store_value_size(&self, path: &impl Path) -> Result<usize, RuntimeError>; fn mark_for_reboot(&mut self) -> Result<(), RuntimeError>; fn reveal_metadata(&self) -> RollupMetadata; fn last_run_aborted(&self) -> Result<bool, RuntimeError>; fn upgrade_failed(&self) -> Result<bool, RuntimeError>; fn restart_forced(&self) -> Result<bool, RuntimeError>; fn reboot_left(&self) -> Result<u32, RuntimeError>; fn runtime_version(&self) -> Result<String, RuntimeError>;
}
Expand description

Safe wrappers for host capabilities.

NB:

  • methods that take &self will not cause changes to the runtime state.
  • methods taking &mut self are expected to cause changes - either to input, output or durable storage.

Required Methods§

source

fn write_output(&mut self, from: &[u8]) -> Result<(), RuntimeError>

Write contents of the given slice to output.

source

fn write_debug(&self, msg: &str)

Write message to debug log.

source

fn read_input(&mut self) -> Result<Option<Message>, RuntimeError>

Read the next input from the global inbox.

Returns None if no message was available. This happens when the kernel has finished reading the inbox at the current level.

The kernel will need to yield to the next level to recieve more input.

source

fn store_has<T>(&self, path: &T) -> Result<Option<ValueType>, RuntimeError>where T: Path,

Returns whether a given path exists in storage.

source

fn store_read<T>( &self, path: &T, from_offset: usize, max_bytes: usize ) -> Result<Vec<u8, Global>, RuntimeError>where T: Path,

Read up to max_bytes from the given path in storage, starting from_offset.

source

fn store_read_slice<T>( &self, path: &T, from_offset: usize, buffer: &mut [u8] ) -> Result<usize, RuntimeError>where T: Path,

Read up to buffer.len() from the given path in storage.

Value is read starting from_offset.

The total bytes read is returned. If the returned value n is n < buffer.len(), then only the first n bytes of the buffer will have been written too.

source

fn store_read_all( &self, path: &impl Path ) -> Result<Vec<u8, Global>, RuntimeError>

Read an entire value from the given path in storage.

source

fn store_write<T>( &mut self, path: &T, src: &[u8], at_offset: usize ) -> Result<(), RuntimeError>where T: Path,

Write the bytes given by src to storage at path, starting at_offset.

Contrary to store_write_all, this does not replace the value (if any) previously stored under path. This allows for splicing/patching values directly in storage, without having to read the entire value from disk.

source

fn store_write_all<T>( &mut self, path: &T, src: &[u8] ) -> Result<(), RuntimeError>where T: Path,

Write the bytes given by src to storage at path.

Contrary to store_write, this replaces the value (if any) that was previously stored at path.

source

fn store_delete<T>(&mut self, path: &T) -> Result<(), RuntimeError>where T: Path,

Delete path from storage.

source

fn store_delete_value<T>(&mut self, path: &T) -> Result<(), RuntimeError>where T: Path,

Delete value under path from storage.

source

fn store_count_subkeys<T>(&self, prefix: &T) -> Result<u64, RuntimeError>where T: Path,

Count the number of subkeys under prefix.

See SmartRollupCore::store_list_size.

source

fn store_move( &mut self, from_path: &impl Path, to_path: &impl Path ) -> Result<(), RuntimeError>

Move one part of durable storage to a different location

See SmartRollupCore::store_move.

source

fn store_copy( &mut self, from_path: &impl Path, to_path: &impl Path ) -> Result<(), RuntimeError>

Copy one part of durable storage to a different location

See SmartRollupCore::store_copy.

source

fn reveal_preimage( &self, hash: &[u8; 33], destination: &mut [u8] ) -> Result<usize, RuntimeError>

Reveal pre-image from a hash of size PREIMAGE_HASH_SIZE in bytes.

N.B. in future, multiple hashing schemes will be supported, but for now the kernels only support hashes of type Reveal_hash, which is a 32-byte Blake2b hash with a prefix-byte of 0.

source

fn store_value_size(&self, path: &impl Path) -> Result<usize, RuntimeError>

Return the size of value stored at path

source

fn mark_for_reboot(&mut self) -> Result<(), RuntimeError>

Mark the kernel for reboot.

If the kernel is marked for reboot, it will continue reading inbox messages for the current level next time kernel_run runs. If the inbox contains no more messages, the kernel will still continue at the current inbox level until it is no longer marked for reboot.

If the kernel is not marked for reboot, it will skip the rest of the inbox for the current level and yield. It will then continue at the next inbox level.

The kernel is given a maximum number of reboots per level. The number of reboots remaining is written to /readonly/kernel/env/reboot_counter (little endian i32).

If the kernel exceeds this, it is forced to yield to the next level (and a flag is set at /readonly/kernel/env/too_many_reboot to indicate this happened.

source

fn reveal_metadata(&self) -> RollupMetadata

source

fn last_run_aborted(&self) -> Result<bool, RuntimeError>

True if the last kernel run was aborted.

source

fn upgrade_failed(&self) -> Result<bool, RuntimeError>

True if the kernel failed to upgrade.

source

fn restart_forced(&self) -> Result<bool, RuntimeError>

True if the kernel rebooted too many times.

source

fn reboot_left(&self) -> Result<u32, RuntimeError>

The number of reboot left for the kernel.

source

fn runtime_version(&self) -> Result<String, RuntimeError>

The runtime_version the kernel is using.

Implementors§

source§

impl<Host> Runtime for Hostwhere Host: SmartRollupCore,