Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't ban remote peer when ckb_vm received Ctrl-C signal when processing chunk_tx #4702

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's other reason may make VM scheduler return VMInternalError::External?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

script/src/syscalls/debugger.rs
48:            .map_err(|e| VMError::External(format!("String from buffer {e:?}")))?;
script/src/syscalls/mod.rs
126:            _ => Err(Error::External(format!("CellField parse_from_u64 {i}"))),
148:            _ => Err(Error::External(format!("HeaderField parse_from_u64 {i}"))),
164:            _ => Err(Error::External(format!("InputField parse_from_u64 {i}"))),
197:            _ => Err(Error::External(format!("SourceEntry parse_from_u64 {i}"))),
243:            _ => Err(Error::External(format!("Place parse_from_u64 {i}"))),

_ => 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
Loading