Instance

Struct Instance 

pub struct Instance<E: RuntimeEnv + 'static> { /* private fields */ }
Expand description

An instance running Lyquor Virtual Machine (LVM) for a Lyquid.

Each Lyquid corresponds to an instance (it’s called “instance” because with LyteMemory, it’s like a tiny “VM instance” in cloud computing sense). Because the network state for a Lyquid is versioned, a LyquidNumber uniquely determines an execution environment for any function call.

In the implementation, crate::barrel::Barrel is the final execution unit that corresponds to a given version. All instance calls will try to grab a Barrel from the cached pool of Barrels, whereas the sequencing part keeps its single, dedicated Barrel for efficient sequencing.

Implementations§

§

impl<E: RuntimeEnv + 'static> Instance<E>

pub fn builder( versioned_store: Arc<dyn VersionedStateStore<LyquidNumber>>, simple_store: Arc<dyn SimpleStateStore>, log: LyquidLog, env: E, id: LyquidID, ) -> Result<InstanceBuilder<E>, Error>

Create a builder for Instance.

pub async fn call_instance_func_decoded<'b, O: for<'a> Deserialize<'a>>( &mut self, version: LyquidNumber, params: CallParams, ) -> impl Future<Output = Result<O, Error>> + 'b

Returns a standalone task that will execute instance opearations in an environment where the network state is sandboxed (any changes made by WASM execution will be discarded after the run).

This method is used to implement Lyquid instance function calls by external events other than the sequencer event. You should first await for this function call to obtain the returned future (and release the lock of the Instance if applicable). Then await the future for the actual call execution (resolving the returned future does not require any lock/access to the instance).

pub async fn call_instance_func<'a>( &mut self, version: LyquidNumber, params: CallParams, ) -> impl Future<Output = Result<Vec<u8>, Error>> + 'a

Similar to Self::call_instance_func but without encoding/decoding. This is useful for handling Ethereum API calls and remote calls (such as UPC) through the network/IPC.

pub fn flush_instance_state(&self) -> Result<(), Error>

Flush the changes made to the instance state in a bundled write to the storage backend.

pub async fn new_sequenced_batch( &mut self, image: Option<Bytes>, ) -> Result<(), Error>

Start a new batch of sequenced calls which update the network state.

The invariant is that each batch only contains calls for the same image version. Upon an image update, image parameter will carry the new image and the LyquidNumber will be bumped up properly. It is required that the invocation of this function should be paired with either Self::commit_sequenced_batch or Self::abort_sequenced_batch, otherwise it returns an error.

pub async fn commit_sequenced_batch(&mut self) -> Result<LyquidNumber, Error>

Commit the current batch of updates induced by sequenced calls.

Upon failure in writing to storage backend, all changes made by this batch are reverted.

pub fn abort_sequenced_batch(&mut self)

Revert all changes since the beginning of this batch (and start a new, empty batch).

pub async fn sequence_call( &mut self, call: SeqCall, pos: ChainPos, ) -> Result<Option<Vec<u8>>, ExecutionError>

Append (and execute) a sequenced call to the current batch. If the call updates the image, the existing batch will be committed and a new batch will be created.

pub fn latest_number(&self) -> &LyquidNumber

Obtain the lastest committed LyquidNumber (which could be upon startup for re-execution).

pub fn max_number(&self) -> Option<LyquidNumber>

Obtain the max LyquidNumber available in the store.

pub async fn reset_last_committed( &mut self, v: LyquidNumber, ) -> Result<(), Error>

pub fn check_version(&self, number: LyquidNumber) -> bool

Check if the provided LyquidNumber exists

pub fn get_deps(&self)

pub fn functions(&self) -> Vec<LyquidFunc>

Get the list of functions from the sequenced barrel.

Auto Trait Implementations§

§

impl<E> !Freeze for Instance<E>

§

impl<E> !RefUnwindSafe for Instance<E>

§

impl<E> Send for Instance<E>

§

impl<E> Sync for Instance<E>

§

impl<E> Unpin for Instance<E>
where E: Unpin,

§

impl<E> !UnwindSafe for Instance<E>

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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> MaybeSend for T
where T: Send,