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<'b, O: for<'a> Deserialize<'a>>(
&mut self,
version: LyquidNumber,
params: CallParams,
) -> impl Future<Output = Result<O, Error>> + 'b
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
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>
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>
pub async fn new_sequenced_batch( &mut self, image: Option<Bytes>, ) -> Result<(), Error>
Start a new batch of sequenced events which update the network state.
The invariant is that each batch only contains events 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>
pub async fn commit_sequenced_batch(&mut self) -> Result<LyquidNumber, Error>
Commit the current batch of updates induced by sequenced events.
Upon failure in writing to storage backend, all changes made by this batch are reverted.
pub fn abort_sequenced_batch(&mut self)
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_event(
&mut self,
event: SeqEvent,
pos: ChainPos,
) -> Result<Option<Vec<u8>>, ExecutionError>
pub async fn sequence_event( &mut self, event: SeqEvent, pos: ChainPos, ) -> Result<Option<Vec<u8>>, ExecutionError>
Append (and execute) a sequenced event to the current batch. If the event updates the image, the existing batch will be committed and a new batch will be created.
pub fn latest_number(&self) -> &LyquidNumber
pub fn latest_number(&self) -> &LyquidNumber
Obtain the lastest committed LyquidNumber.
pub async fn reset_last_committed( &mut self, v: LyquidNumber, ) -> Result<(), Error>
pub fn get_deps(&self)
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<'de, F, T> Deserialize<'de, As<F>> for Twhere
F: BareFormula + ?Sized,
T: Deserialize<'de, F>,
impl<'de, F, T> Deserialize<'de, As<F>> for Twhere
F: BareFormula + ?Sized,
T: Deserialize<'de, F>,
§fn deserialize(deserializer: Deserializer<'de>) -> Result<T, DeserializeError>
fn deserialize(deserializer: Deserializer<'de>) -> Result<T, DeserializeError>
§fn deserialize_in_place(
&mut self,
deserializer: Deserializer<'de>,
) -> Result<(), DeserializeError>
fn deserialize_in_place( &mut self, deserializer: Deserializer<'de>, ) -> Result<(), DeserializeError>
self with data from the input. Read more§impl<'de, F, T> Deserialize<'de, Ref<F>> for T
impl<'de, F, T> Deserialize<'de, Ref<F>> for T
§fn deserialize(de: Deserializer<'de>) -> Result<T, DeserializeError>
fn deserialize(de: Deserializer<'de>) -> Result<T, DeserializeError>
§fn deserialize_in_place(
&mut self,
de: Deserializer<'de>,
) -> Result<(), DeserializeError>
fn deserialize_in_place( &mut self, de: Deserializer<'de>, ) -> Result<(), DeserializeError>
self with data from the input. Read more§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