Skip to content

Commit

Permalink
Merge pull request #4123 from libraries/fix_current_cycles_in_spawn
Browse files Browse the repository at this point in the history
fix(script/spawn): calucate the correct cycles_base
  • Loading branch information
zhangsoledad authored Aug 29, 2023
2 parents 79f943d + 153104b commit 7db3976
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion script/src/syscalls/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct Spawn<DL> {
script_version: ScriptVersion,
syscalls_generator: TransactionScriptsSyscallsGenerator<DL>,
peak_memory: u64,
cycles_base: u64,
context: Arc<Mutex<MachineContext>>,
}

Expand All @@ -34,13 +35,15 @@ impl<DL: CellDataProvider + Clone + HeaderProvider + Send + Sync + 'static> Spaw
script_version: ScriptVersion,
syscalls_generator: TransactionScriptsSyscallsGenerator<DL>,
peak_memory: u64,
cycles_base: u64,
context: Arc<Mutex<MachineContext>>,
) -> Self {
Self {
script_group,
script_version,
syscalls_generator,
peak_memory,
cycles_base,
context,
}
}
Expand Down Expand Up @@ -155,7 +158,7 @@ where
caller_exit_code_addr: exit_code_addr.to_u64(),
caller_content_addr: content_addr.to_u64(),
caller_content_length_addr: content_length_addr.to_u64(),
cycles_base: machine.cycles(),
cycles_base: self.cycles_base + machine.cycles(),
};
let mut machine_child = build_child_machine(
&self.script_group,
Expand Down Expand Up @@ -290,6 +293,7 @@ pub fn build_child_machine<
script_version,
script_group,
*callee_peak_memory,
*cycles_base,
Arc::clone(context),
)));
let machine_builder = machine_builder.syscall(Box::new(
Expand Down
10 changes: 9 additions & 1 deletion script/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,15 @@ impl<DL: CellDataProvider + HeaderProvider + ExtensionProvider + Send + Sync + C
script_version: ScriptVersion,
script_group: &ScriptGroup,
peak_memory: u64,
cycles_base: u64,
context: Arc<Mutex<MachineContext>>,
) -> Spawn<DL> {
Spawn::new(
script_group.clone(),
script_version,
self.clone(),
peak_memory,
cycles_base,
context,
)
}
Expand Down Expand Up @@ -329,7 +331,13 @@ impl<DL: CellDataProvider + HeaderProvider + ExtensionProvider + Send + Sync + C
syscalls.append(&mut vec![
Box::new(self.build_get_memory_limit(8)),
Box::new(self.build_set_content(Arc::new(Mutex::new(vec![])), 0)),
Box::new(self.build_spawn(script_version, script_group, 8, Arc::clone(&context))),
Box::new(self.build_spawn(
script_version,
script_group,
8,
0,
Arc::clone(&context),
)),
Box::new(self.build_current_memory(8)),
])
}
Expand Down

0 comments on commit 7db3976

Please sign in to comment.