From b861c56f1608210e1e49aca8756535740e151d4f Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Tue, 29 Oct 2024 16:03:14 +0800 Subject: [PATCH 1/2] let ckb_vm::Error::External("stopped") return ErrorKind::Internal instead of ErrorKind::Script --- script/src/error.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/script/src/error.rs b/script/src/error.rs index cac50b738d..094671d6e3 100644 --- a/script/src/error.rs +++ b/script/src/error.rs @@ -182,7 +182,12 @@ impl ScriptError { impl From for Error { fn from(error: TransactionScriptError) -> Self { - ErrorKind::Script.because(error) + match error.cause { + ScriptError::Other(ref reason) if reason == "stopped" => { + ErrorKind::Internal.because(error) + } + _ => ErrorKind::Script.because(error), + } } } From 5f70ba5b97b8a286cc7cf164d9beb10916db2d8c Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Mon, 25 Nov 2024 10:52:17 +0800 Subject: [PATCH 2/2] Create Interrupts for ScriptError Signed-off-by: Eval EXEC --- error/src/internal.rs | 3 +++ script/src/error.rs | 11 +++++++---- script/src/verify.rs | 1 + .../verify/tests/ckb_latest/features_since_v2023.rs | 7 +++++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/error/src/internal.rs b/error/src/internal.rs index 71e99cd214..f73f7103ce 100644 --- a/error/src/internal.rs +++ b/error/src/internal.rs @@ -50,6 +50,9 @@ pub enum InternalErrorKind { /// The feature is disabled or is conflicted with the configuration Config, + /// Interrupts, such as a Ctrl-C signal + Interrupts, + /// Other system error Other, } diff --git a/script/src/error.rs b/script/src/error.rs index 094671d6e3..c4778562d7 100644 --- a/script/src/error.rs +++ b/script/src/error.rs @@ -1,5 +1,5 @@ use crate::types::{ScriptGroup, ScriptGroupType}; -use ckb_error::{prelude::*, Error, ErrorKind}; +use ckb_error::{prelude::*, Error, ErrorKind, InternalErrorKind}; use ckb_types::core::{Cycle, ScriptHashType}; use ckb_types::packed::{Byte32, Script}; use ckb_vm::Error as VMInternalError; @@ -44,6 +44,10 @@ pub enum ScriptError { #[error("VM Internal Error: {0:?}")] VMInternalError(VMInternalError), + /// Interrupts, such as a Ctrl-C signal + #[error("VM Interrupts")] + Interrupts, + /// Other errors raised in script execution process #[error("Other Error: {0}")] Other(String), @@ -183,9 +187,8 @@ impl ScriptError { impl From for Error { fn from(error: TransactionScriptError) -> Self { match error.cause { - ScriptError::Other(ref reason) if reason == "stopped" => { - ErrorKind::Internal.because(error) - } + ScriptError::Interrupts => ErrorKind::Internal + .because(InternalErrorKind::Interrupts.other(ScriptError::Interrupts.to_string())), _ => ErrorKind::Script.because(error), } } diff --git a/script/src/verify.rs b/script/src/verify.rs index 6551ffa7f3..f2bf0d44a0 100644 --- a/script/src/verify.rs +++ b/script/src/verify.rs @@ -1186,6 +1186,7 @@ where 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), }; diff --git a/script/src/verify/tests/ckb_latest/features_since_v2023.rs b/script/src/verify/tests/ckb_latest/features_since_v2023.rs index d5eb783ca0..ddb0f0627d 100644 --- a/script/src/verify/tests/ckb_latest/features_since_v2023.rs +++ b/script/src/verify/tests/ckb_latest/features_since_v2023.rs @@ -540,8 +540,11 @@ async fn check_spawn_suspend_shutdown() { .verify_complete_async(script_version, &rtx, &mut command_rx, true) .await; assert!(res.is_err()); - let err = res.unwrap_err().to_string(); - assert!(err.contains("VM Internal Error: External(\"stopped\")")); + let err = res.unwrap_err(); + assert!(err.to_string().contains("VM Interrupts")); + + let reject = ckb_types::core::tx_pool::Reject::Verification(err); + assert!(!reject.is_malformed_tx()); } #[test]