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>
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>
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<O: for<'a> Deserialize<'a> + Send + 'static>(
&self,
version: LyquidNumber,
params: CallParams,
options: RunOptions,
) -> impl Future<Output = Result<O, Error>> + Send + 'static
pub async fn call_instance_func_decoded<O: for<'a> Deserialize<'a> + Send + 'static>( &self, version: LyquidNumber, params: CallParams, options: RunOptions, ) -> impl Future<Output = Result<O, Error>> + Send + 'static
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. Call this method 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(
&self,
version: LyquidNumber,
params: CallParams,
options: RunOptions,
) -> impl Future<Output = Result<Vec<u8>, Error>> + Send + 'static
pub async fn call_instance_func( &self, version: LyquidNumber, params: CallParams, options: RunOptions, ) -> impl Future<Output = Result<Vec<u8>, Error>> + Send + 'static
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 async fn flush_instance_state(&self) -> Result<(), Error>
pub async fn new_sequenced_batch(
&self,
image: Option<Bytes>,
) -> Result<(), Error>
pub async fn new_sequenced_batch( &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(&self) -> Result<LyquidNumber, Error>
pub async fn commit_sequenced_batch(&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 async fn abort_sequenced_batch(&self)
pub async fn abort_sequenced_batch(&self)
Revert all changes since the beginning of this batch (and start a new, empty batch).
pub async fn sequence_call(
&self,
call: SeqCall,
pos: ChainPos,
) -> Result<Option<Vec<u8>>, ExecutionError>
pub async fn sequence_call( &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 async fn latest_number(&self) -> LyquidNumber
pub async 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>
pub fn max_number(&self) -> Option<LyquidNumber>
Obtain the max LyquidNumber available in the store.
pub async fn reset_last_committed(&self, v: LyquidNumber) -> Result<(), Error>
pub async fn check_version(&self, number: LyquidNumber) -> bool
pub async fn check_version(&self, number: LyquidNumber) -> bool
Check if the provided LyquidNumber exists
pub fn id(&self) -> LyquidID
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§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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