Struct Scheduler

Source
pub struct Scheduler<DL, V, M>{ /* private fields */ }
Expand description

A single Scheduler instance is used to verify a single script within a CKB transaction.

A scheduler holds & manipulates a core, the scheduler also holds all CKB-VM machines, each CKB-VM machine also gets a mutable reference of the core for IO operations.

Implementations§

Source§

impl<DL, V, M> Scheduler<DL, V, M>

Source

pub fn new( sg_data: SgData<DL>, syscall_generator: SyscallGenerator<DL, V, M::Inner>, syscall_context: V, ) -> Self

Create a new scheduler from empty state

Source

pub fn consumed_cycles(&self) -> Cycle

Return total cycles.

Source

pub fn state(&self, vm_id: &VmId) -> Option<VmState>

Fetch specified VM state

Source

pub fn sg_data(&self) -> &SgData<DL>

Access the SgData data structure

Source

pub fn peek<F, G, W>(&mut self, vm_id: &VmId, f: F, g: G) -> Result<W, Error>
where F: FnMut(&mut M) -> Result<W, Error>, G: FnMut(&Snapshot2<DataPieceId>, &SgData<DL>) -> Result<W, Error>,

This function provides a peek into one of the current created VM. Depending on the actual state, the VM might either be instantiated or suspended. As a result, 2 callback functions must be provided to handle both cases. The function only provides a peek, meaning the caller must not make any changes to an instantiated VMs. the VM is passed as a mutable reference only because memory load functions in CKB-VM require mutable references. It does not mean the caller can modify the VM in any sense. Even a slight tampering of the VM can result in non-determinism.

Source

pub fn resume( sg_data: SgData<DL>, syscall_generator: SyscallGenerator<DL, V, M::Inner>, syscall_context: V, full: FullSuspendedState, ) -> Self

Resume a previously suspended scheduler state

Source

pub fn suspend(self) -> Result<FullSuspendedState, Error>

Suspend current scheduler into a serializable full state

Source

pub fn run(&mut self, mode: RunMode) -> Result<TerminatedResult, Error>

This is the only entrypoint for running the scheduler, both newly created instance and resumed instance are supported. It accepts 2 run mode, one can either limit the cycles to execute, or use a pause signal to trigger termination.

Only when the execution terminates without VM errors, will this function return an exit code(could still be non-zero) and total consumed cycles.

Err would be returned in the following cases:

  • Cycle limit reached, the returned error would be ckb_vm::Error::CyclesExceeded,
  • Pause trigger, the returned error would be ckb_vm::Error::Pause,
  • Other terminating errors
Source

pub fn iterate(&mut self) -> Result<IterationResult, Error>

Public API that runs a single VM, processes all messages, then returns the executed VM ID(so caller can fetch later data). This can be used when more finer tweaks are required for a single VM.

Source

pub fn terminated(&self) -> bool

If current scheduler is terminated

Auto Trait Implementations§

§

impl<DL, V, M> Freeze for Scheduler<DL, V, M>
where V: Freeze,

§

impl<DL, V, M> RefUnwindSafe for Scheduler<DL, V, M>

§

impl<DL, V, M> Send for Scheduler<DL, V, M>
where V: Send, DL: Sync + Send, M: Send,

§

impl<DL, V, M> Sync for Scheduler<DL, V, M>
where V: Sync, DL: Sync + Send, M: Sync,

§

impl<DL, V, M> Unpin for Scheduler<DL, V, M>
where V: Unpin,

§

impl<DL, V, M> UnwindSafe for Scheduler<DL, V, M>

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> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Cast to trait Any
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<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
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.
Source§

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

Source§

fn vzip(self) -> V