pub struct Scheduler<DL>{Show 14 fields
pub tx_data: TxData<DL>,
pub script_version: ScriptVersion,
pub syscalls_generator: TransactionScriptsSyscallsGenerator<DL>,
pub total_cycles: Cycle,
pub current_iteration_cycles: Cycle,
pub next_vm_id: u64,
pub next_fd_slot: u64,
pub states: BTreeMap<u64, VmState>,
pub fds: BTreeMap<Fd, u64>,
pub inherited_fd: BTreeMap<u64, Vec<Fd>>,
pub instantiated: BTreeMap<u64, (MachineContext<DL>, AsmMachine)>,
pub suspended: BTreeMap<u64, Snapshot2<DataPieceId>>,
pub terminated_vms: BTreeMap<u64, i8>,
pub message_box: Arc<Mutex<Vec<Message>>>,
}
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.
Fields§
§tx_data: TxData<DL>
Context data for current running transaction & script.
script_version: ScriptVersion
In fact, Scheduler here has the potential to totally replace TransactionScriptsVerifier, nonetheless much of current syscall implementation is strictly tied to TransactionScriptsVerifier, we are using it here to save some extra code.
syscalls_generator: TransactionScriptsSyscallsGenerator<DL>
Generate system calls.
total_cycles: Cycle
Total cycles.
current_iteration_cycles: Cycle
Current iteration cycles. This value is periodically added to total_cycles and cleared
next_vm_id: u64
Next vm id used by spawn.
next_fd_slot: u64
Next fd used by pipe.
states: BTreeMap<u64, VmState>
Used to store VM state.
fds: BTreeMap<Fd, u64>
Used to confirm the owner of fd.
inherited_fd: BTreeMap<u64, Vec<Fd>>
Verify the VM’s inherited fd list.
instantiated: BTreeMap<u64, (MachineContext<DL>, AsmMachine)>
Instantiated vms.
suspended: BTreeMap<u64, Snapshot2<DataPieceId>>
Suspended vms.
terminated_vms: BTreeMap<u64, i8>
Terminated vms.
message_box: Arc<Mutex<Vec<Message>>>
MessageBox is expected to be empty before returning from run
function, there is no need to persist messages.
Implementations§
Source§impl<DL> Scheduler<DL>
impl<DL> Scheduler<DL>
Sourcepub fn new(
tx_data: TxData<DL>,
script_version: ScriptVersion,
syscalls_generator: TransactionScriptsSyscallsGenerator<DL>,
) -> Self
pub fn new( tx_data: TxData<DL>, script_version: ScriptVersion, syscalls_generator: TransactionScriptsSyscallsGenerator<DL>, ) -> 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 consumed_cycles_add(&mut self, cycles: Cycle) -> Result<(), Error>
pub fn consumed_cycles_add(&mut self, cycles: Cycle) -> Result<(), Error>
Add cycles to total cycles.
Sourcepub fn resume(
tx_data: TxData<DL>,
script_version: ScriptVersion,
syscalls_generator: TransactionScriptsSyscallsGenerator<DL>,
full: FullSuspendedState,
) -> Self
pub fn resume( tx_data: TxData<DL>, script_version: ScriptVersion, syscalls_generator: TransactionScriptsSyscallsGenerator<DL>, 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<(i8, Cycle), Error>
pub fn run(&mut self, mode: RunMode) -> Result<(i8, Cycle), 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_prepare_machine(
&mut self,
pause: Pause,
limit_cycles: Cycle,
) -> Result<(u64, &mut AsmMachine), Error>
pub fn iterate_prepare_machine( &mut self, pause: Pause, limit_cycles: Cycle, ) -> Result<(u64, &mut AsmMachine), Error>
Returns the machine that needs to be executed in the current iterate.
Auto Trait Implementations§
impl<DL> !Freeze for Scheduler<DL>
impl<DL> !RefUnwindSafe for Scheduler<DL>
impl<DL> Send for Scheduler<DL>
impl<DL> Sync for Scheduler<DL>
impl<DL> Unpin for Scheduler<DL>where
DL: Unpin,
impl<DL> !UnwindSafe for Scheduler<DL>
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