Struct ExecFuture

Source
pub struct ExecFuture<'a, S, OA, OG>
where S: StateRead,
{ /* private fields */ }
Expand description

A future that when polled attempts to make progress on VM execution.

This poll implementation steps forward the VM by the stored operations, handling synchronous and asynchronous operations differently:

  • For synchronous operations, it directly steps the VM to execute the operation.
  • For asynchronous operations, it creates a future that will complete the operation and temporarily takes ownership of the VM. This future is stored in pending_op until it’s ready.

This type should not be constructed directly. Instead, it is used as a part of the implementation of Vm::exec and exposed publicly for documentation of its behaviour.

§Yield Behavior

Execution yields in two scenarios:

  • Asynchronous Operations: When an async operation is encountered, the method yields until the operation’s future is ready. This allows other tasks to run while awaiting the asynchronous operation to complete.
  • Gas Yield Limit Reached: The method also yields based on a gas spending limit. If executing an operation causes gas.spent to exceed gas.next_yield_threshold, the method yields to allow the scheduler to run other tasks. This prevents long or complex sequences of operations from monopolizing CPU time.

Upon yielding, the method ensures that the state of the VM and the execution context (including gas counters and any pending operations) are preserved for when the poll method is called again.

§Error Handling

Errors encountered during operation execution result in an immediate return of Poll::Ready(Err(...)), encapsulating the error within a ExecError. This includes errors from:

  • Synchronous operations that fail during their execution.
  • Asynchronous operations, where errors are handled once the future resolves.

The VM’s program counter will remain on the operation that caused the error.

§Completion

The future completes (Poll::Ready(Ok(...))) when all operations have been executed and no more work remains. At this point, ownership over the VM is dropped and the total amount of gas spent during execution is returned. Attempting to poll the future after completion will panic.

Trait Implementations§

Source§

impl<'a, S, OA, OG> Future for ExecFuture<'a, S, OA, OG>
where S: StateRead, OA: OpAccess<Op = Op> + Unpin, OG: OpGasCost, OA::Error: Into<OpError<S::Error>>,

Source§

type Output = Result<u64, ExecError<<S as StateRead>::Error>>

Returns a result with the total gas spent.

Source§

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>

Attempts to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more

Auto Trait Implementations§

§

impl<'a, S, OA, OG> Freeze for ExecFuture<'a, S, OA, OG>
where OA: Freeze, <S as StateRead>::Future: Freeze,

§

impl<'a, S, OA, OG> RefUnwindSafe for ExecFuture<'a, S, OA, OG>

§

impl<'a, S, OA, OG> Send for ExecFuture<'a, S, OA, OG>
where OA: Send, S: Sync, OG: Sync, <S as StateRead>::Future: Send,

§

impl<'a, S, OA, OG> Sync for ExecFuture<'a, S, OA, OG>
where OA: Sync, S: Sync, OG: Sync, <S as StateRead>::Future: Sync,

§

impl<'a, S, OA, OG> Unpin for ExecFuture<'a, S, OA, OG>
where OA: Unpin,

§

impl<'a, S, OA, OG> !UnwindSafe for ExecFuture<'a, S, OA, OG>

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
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.

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<F> IntoFuture for F
where F: Future,

Source§

type Output = <F as Future>::Output

The output that the future will produce on completion.
Source§

type IntoFuture = F

Which kind of future are we turning this into?
Source§

fn into_future(self) -> <F as IntoFuture>::IntoFuture

Creates a future from a value. 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.