diff --git a/script/src/verify.rs b/script/src/verify.rs index f2bf0d44a0..141910fc25 100644 --- a/script/src/verify.rs +++ b/script/src/verify.rs @@ -1046,10 +1046,6 @@ where } else { Scheduler::new(tx_data, version, self.syscalls_generator.clone()) }; - let map_vm_internal_error = |error: VMInternalError| match error { - VMInternalError::CyclesExceeded => ScriptError::ExceededMaximumCycles(max_cycles), - _ => ScriptError::VMInternalError(error), - }; let previous_cycles = scheduler.consumed_cycles(); let res = scheduler.run(RunMode::LimitCycles(max_cycles)); match res { @@ -1068,10 +1064,12 @@ where } Err(error) => match error { VMInternalError::CyclesExceeded | VMInternalError::Pause => { - let snapshot = scheduler.suspend().map_err(map_vm_internal_error)?; + let snapshot = scheduler + .suspend() + .map_err(|err| self.map_vm_internal_error(err, max_cycles))?; Ok(ChunkState::suspended(snapshot)) } - _ => Err(map_vm_internal_error(error)), + _ => Err(self.map_vm_internal_error(error, max_cycles)), }, } } @@ -1149,13 +1147,9 @@ where max_cycles: Cycle, ) -> Result<(i8, Cycle), ScriptError> { let mut scheduler = self.create_scheduler(script_group)?; - let map_vm_internal_error = |error: VMInternalError| match error { - VMInternalError::CyclesExceeded => ScriptError::ExceededMaximumCycles(max_cycles), - _ => ScriptError::VMInternalError(error), - }; scheduler .run(RunMode::LimitCycles(max_cycles)) - .map_err(map_vm_internal_error) + .map_err(|err| self.map_vm_internal_error(err, max_cycles)) } fn run(&self, script_group: &ScriptGroup, max_cycles: Cycle) -> Result { @@ -1168,6 +1162,14 @@ where } } + fn map_vm_internal_error(&self, error: VMInternalError, max_cycles: Cycle) -> ScriptError { + match error { + VMInternalError::CyclesExceeded => ScriptError::ExceededMaximumCycles(max_cycles), + VMInternalError::External(reason) if reason.eq("stopped") => ScriptError::Interrupts, + _ => ScriptError::VMInternalError(error), + } + } + #[cfg(not(target_family = "wasm"))] async fn chunk_run_with_signal( &self, @@ -1184,12 +1186,6 @@ where }; let version = self.select_version(&script_group.script)?; let mut scheduler = Scheduler::new(tx_data, version, self.syscalls_generator.clone()); - let map_vm_internal_error = |error: VMInternalError| match error { - VMInternalError::CyclesExceeded => ScriptError::ExceededMaximumCycles(max_cycles), - VMInternalError::External(reason) if reason.eq("stopped") => ScriptError::Interrupts, - _ => ScriptError::VMInternalError(error), - }; - let mut pause = VMPause::new(); let child_pause = pause.clone(); let (finish_tx, mut finish_rx) = oneshot::channel::>(); @@ -1264,7 +1260,7 @@ where exit_code ))}, Err(err) => { - return Err(map_vm_internal_error(err)); + return Err(self.map_vm_internal_error(err, max_cycles)); } }