Skip to content

Commit

Permalink
Merge pull request #4702 from eval-exec/exec/ignore-ctrl-c-signal-cau…
Browse files Browse the repository at this point in the history
…se-chunk-stop

Don't ban remote peer when ckb_vm received Ctrl-C signal when processing chunk_tx
  • Loading branch information
zhangsoledad authored Nov 29, 2024
2 parents 80cfe48 + 5f70ba5 commit 188d0a6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions error/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
12 changes: 10 additions & 2 deletions script/src/error.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -182,7 +186,11 @@ impl ScriptError {

impl From<TransactionScriptError> for Error {
fn from(error: TransactionScriptError) -> Self {
ErrorKind::Script.because(error)
match error.cause {
ScriptError::Interrupts => ErrorKind::Internal
.because(InternalErrorKind::Interrupts.other(ScriptError::Interrupts.to_string())),
_ => ErrorKind::Script.because(error),
}
}
}

Expand Down
1 change: 1 addition & 0 deletions script/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};

Expand Down
7 changes: 5 additions & 2 deletions script/src/verify/tests/ckb_latest/features_since_v2023.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 188d0a6

Please sign in to comment.