pub struct Scheduler<DL, V, M>where
DL: CellDataProvider,
M: DefaultMachineRunner,{ /* 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>where
DL: CellDataProvider + HeaderProvider + ExtensionProvider + Clone,
V: Clone,
M: DefaultMachineRunner,
impl<DL, V, M> Scheduler<DL, V, M>where
DL: CellDataProvider + HeaderProvider + ExtensionProvider + Clone,
V: Clone,
M: DefaultMachineRunner,
Sourcepub fn new(
sg_data: SgData<DL>,
syscall_generator: SyscallGenerator<DL, V, M::Inner>,
syscall_context: V,
) -> Self
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
Sourcepub fn consumed_cycles(&self) -> Cycle
pub fn consumed_cycles(&self) -> Cycle
Return total cycles.
Sourcepub fn peek<F, G, W>(&mut self, vm_id: &VmId, f: F, g: G) -> Result<W, Error>
pub fn peek<F, G, W>(&mut self, vm_id: &VmId, f: F, g: G) -> 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.
Sourcepub fn resume(
sg_data: SgData<DL>,
syscall_generator: SyscallGenerator<DL, V, M::Inner>,
syscall_context: V,
full: FullSuspendedState,
) -> Self
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
Sourcepub fn suspend(self) -> Result<FullSuspendedState, Error>
pub fn suspend(self) -> Result<FullSuspendedState, Error>
Suspend current scheduler into a serializable full state
Sourcepub fn run(&mut self, mode: RunMode) -> Result<TerminatedResult, Error>
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
Sourcepub fn iterate(&mut self) -> Result<IterationResult, Error>
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.
Sourcepub fn terminated(&self) -> bool
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>
impl<DL, V, M> Sync for Scheduler<DL, V, M>
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> 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
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