Skip to content

Commit 9d2f0f5

Browse files
authored
Merge branch 'develop' into exec/dep-upgrade
2 parents 68b69b0 + 02ade1b commit 9d2f0f5

File tree

9 files changed

+270
-146
lines changed

9 files changed

+270
-146
lines changed

script/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod error;
44
mod scheduler;
55
mod syscalls;
66
mod type_id;
7-
mod types;
7+
pub mod types;
88
mod verify;
99
mod verify_env;
1010

script/src/scheduler.rs

+23-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use crate::cost_model::transferred_byte_cycles;
22
use crate::syscalls::{
33
EXEC_LOAD_ELF_V2_CYCLES_BASE, INVALID_FD, MAX_FDS_CREATED, MAX_VMS_SPAWNED, OTHER_END_CLOSED,
4-
SPAWN_EXTRA_CYCLES_BASE, SUCCESS, WAIT_FAILURE, generator::generate_ckb_syscalls,
4+
SPAWN_EXTRA_CYCLES_BASE, SUCCESS, WAIT_FAILURE,
55
};
66

77
use crate::types::{
8-
CoreMachineType, DataLocation, DataPieceId, DebugContext, FIRST_FD_SLOT, FIRST_VM_ID, Fd,
9-
FdArgs, FullSuspendedState, Machine, Message, ReadState, RunMode, SgData, VmArgs, VmContext,
10-
VmId, VmState, WriteState,
8+
CoreMachineType, DataLocation, DataPieceId, FIRST_FD_SLOT, FIRST_VM_ID, Fd, FdArgs,
9+
FullSuspendedState, Machine, Message, ReadState, RunMode, SgData, SyscallGenerator, VmArgs,
10+
VmContext, VmId, VmState, WriteState,
1111
};
1212
use ckb_traits::{CellDataProvider, ExtensionProvider, HeaderProvider};
1313
use ckb_types::core::Cycle;
@@ -43,15 +43,17 @@ pub const MAX_FDS: u64 = 64;
4343
/// A scheduler holds & manipulates a core, the scheduler also holds
4444
/// all CKB-VM machines, each CKB-VM machine also gets a mutable reference
4545
/// of the core for IO operations.
46-
pub struct Scheduler<DL>
46+
pub struct Scheduler<DL, V>
4747
where
4848
DL: CellDataProvider,
4949
{
5050
/// Immutable context data for current running transaction & script.
5151
pub sg_data: SgData<DL>,
5252

53-
/// Mutable context data used by current scheduler
54-
pub debug_context: DebugContext,
53+
/// Syscall generator
54+
pub syscall_generator: SyscallGenerator<DL, V>,
55+
/// Syscall generator context
56+
pub syscall_context: V,
5557

5658
/// Total cycles. When a scheduler executes, there are 3 variables
5759
/// that might all contain charged cycles: +total_cycles+,
@@ -106,15 +108,21 @@ where
106108
pub message_box: Arc<Mutex<Vec<Message>>>,
107109
}
108110

109-
impl<DL> Scheduler<DL>
111+
impl<DL, V> Scheduler<DL, V>
110112
where
111113
DL: CellDataProvider + HeaderProvider + ExtensionProvider + Send + Sync + Clone + 'static,
114+
V: Send + Clone,
112115
{
113116
/// Create a new scheduler from empty state
114-
pub fn new(sg_data: SgData<DL>, debug_context: DebugContext) -> Self {
117+
pub fn new(
118+
sg_data: SgData<DL>,
119+
syscall_generator: SyscallGenerator<DL, V>,
120+
syscall_context: V,
121+
) -> Self {
115122
Self {
116123
sg_data,
117-
debug_context,
124+
syscall_generator,
125+
syscall_context,
118126
total_cycles: Arc::new(AtomicU64::new(0)),
119127
iteration_cycles: 0,
120128
next_vm_id: FIRST_VM_ID,
@@ -149,12 +157,14 @@ where
149157
/// Resume a previously suspended scheduler state
150158
pub fn resume(
151159
sg_data: SgData<DL>,
152-
debug_context: DebugContext,
160+
syscall_generator: SyscallGenerator<DL, V>,
161+
syscall_context: V,
153162
full: FullSuspendedState,
154163
) -> Self {
155164
let mut scheduler = Self {
156165
sg_data,
157-
debug_context,
166+
syscall_generator,
167+
syscall_context,
158168
total_cycles: Arc::new(AtomicU64::new(full.total_cycles)),
159169
iteration_cycles: 0,
160170
next_vm_id: full.next_vm_id,
@@ -898,7 +908,7 @@ where
898908
let machine_builder = DefaultMachineBuilder::new(core_machine)
899909
.instruction_cycle_func(Box::new(estimate_cycles));
900910
let machine_builder =
901-
generate_ckb_syscalls(id, &self.sg_data, &vm_context, &self.debug_context)
911+
(self.syscall_generator)(id, &self.sg_data, &vm_context, &self.syscall_context)
902912
.into_iter()
903913
.fold(machine_builder, |builder, syscall| builder.syscall(syscall));
904914
let default_machine = machine_builder.build();

script/src/syscalls/debugger.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::types::{
2-
DebugContext, DebugPrinter, {SgData, SgInfo},
2+
DebugPrinter, {SgData, SgInfo},
33
};
44
use crate::{cost_model::transferred_byte_cycles, syscalls::DEBUG_PRINT_SYSCALL_NUMBER};
55
use ckb_vm::{
@@ -14,10 +14,10 @@ pub struct Debugger {
1414
}
1515

1616
impl Debugger {
17-
pub fn new<DL>(sg_data: &SgData<DL>, debug_context: &DebugContext) -> Debugger {
17+
pub fn new<DL>(sg_data: &SgData<DL>, debug_printer: &DebugPrinter) -> Debugger {
1818
Debugger {
1919
sg_info: Arc::clone(&sg_data.sg_info),
20-
printer: Arc::clone(&debug_context.debug_printer),
20+
printer: Arc::clone(debug_printer),
2121
}
2222
}
2323
}

script/src/syscalls/generator.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
LoadCellData, LoadHeader, LoadInput, LoadScript, LoadScriptHash, LoadTx, LoadWitness, Pipe,
55
ProcessID, Read, Spawn, VMVersion, Wait, Write,
66
},
7-
types::{CoreMachine, DebugContext, ScriptVersion, SgData, VmContext, VmId},
7+
types::{CoreMachine, DebugPrinter, ScriptVersion, SgData, VmContext, VmId},
88
};
99
use ckb_traits::{CellDataProvider, ExtensionProvider, HeaderProvider};
1010
use ckb_vm::Syscalls;
@@ -14,7 +14,7 @@ pub fn generate_ckb_syscalls<DL>(
1414
vm_id: &VmId,
1515
sg_data: &SgData<DL>,
1616
vm_context: &VmContext<DL>,
17-
debug_context: &DebugContext,
17+
debug_printer: &DebugPrinter,
1818
) -> Vec<Box<(dyn Syscalls<CoreMachine>)>>
1919
where
2020
DL: CellDataProvider + HeaderProvider + ExtensionProvider + Send + Sync + Clone + 'static,
@@ -28,7 +28,7 @@ where
2828
Box::new(LoadWitness::new(sg_data)),
2929
Box::new(LoadScript::new(sg_data)),
3030
Box::new(LoadCellData::new(vm_context)),
31-
Box::new(Debugger::new(sg_data, debug_context)),
31+
Box::new(Debugger::new(sg_data, debug_printer)),
3232
];
3333
let script_version = &sg_data.sg_info.script_version;
3434
if script_version >= &ScriptVersion::V1 {
@@ -54,9 +54,5 @@ where
5454
Box::new(Close::new(vm_id, vm_context)),
5555
]);
5656
}
57-
#[cfg(test)]
58-
syscalls.push(Box::new(crate::syscalls::Pause::new(
59-
std::sync::Arc::clone(&debug_context.skip_pause),
60-
)));
6157
syscalls
6258
}

0 commit comments

Comments
 (0)