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

fix: check actor error codes #1039

Merged
merged 2 commits into from
Jan 13, 2023
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
20 changes: 12 additions & 8 deletions actors/evm/src/interpreter/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,21 @@ impl<'r, RT: Runtime> System<'r, RT> {
.rt
.send_generalized(to, method, params, value, gas_limit, send_flags)
.map_err(|err| actor_error!(unspecified; "send syscall failed: {}", err))?;

// Don't bother reloading on abort, just return the error.
if !result.exit_code.is_success() {
return Err(ActorError::checked_with_data(
result.exit_code,
format!("failed to call {to} on method {method}"),
Copy link
Contributor

Choose a reason for hiding this comment

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

missing the {to} param here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope. Rust format strings let you inline variables like that.

Copy link
Member Author

Choose a reason for hiding this comment

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

(and they're type-checked at compile time)

result.return_data,
));
}

if !send_flags.read_only() {
self.reload()?;
}
match result.exit_code {
ExitCode::OK => Ok(result.return_data),
e => Err(ActorError::unchecked_with_data(
e,
"send failed".to_string(),
result.return_data,
)),
}

Ok(result.return_data)
}

/// Flush the actor state (bytecode, nonce, and slots).
Expand Down
34 changes: 34 additions & 0 deletions runtime/src/actor_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,40 @@ impl ActorError {
Self { exit_code: code, msg, data }
}

/// Creates a new ActorError. This method checks if the exit code is within the allowed range,
/// and automatically converts it into a user code.
pub fn checked(code: ExitCode, msg: String) -> Self {
let exit_code = match code {
// This means the called actor did something wrong. We can't "make up" a
// reasonable exit code.
ExitCode::SYS_MISSING_RETURN
| ExitCode::SYS_ILLEGAL_INSTRUCTION
| ExitCode::SYS_ILLEGAL_EXIT_CODE => ExitCode::USR_UNSPECIFIED,
// We don't expect any other system errors.
code if code.is_system_error() => ExitCode::USR_ASSERTION_FAILED,
// Otherwise, pass it through.
code => code,
};
Self { exit_code, msg, data: None }
}

/// Creates a new ActorError. This method checks if the exit code is within the allowed range,
/// and automatically converts it into a user code.
pub fn checked_with_data(code: ExitCode, msg: String, data: Option<IpldBlock>) -> Self {
let exit_code = match code {
// This means the called actor did something wrong. We can't "make up" a
// reasonable exit code.
ExitCode::SYS_MISSING_RETURN
| ExitCode::SYS_ILLEGAL_INSTRUCTION
| ExitCode::SYS_ILLEGAL_EXIT_CODE => ExitCode::USR_UNSPECIFIED,
// We don't expect any other system errors.
code if code.is_system_error() => ExitCode::USR_ASSERTION_FAILED,
// Otherwise, pass it through.
code => code,
};
Self { exit_code, msg, data }
}

pub fn illegal_argument(msg: String) -> Self {
Self { exit_code: ExitCode::USR_ILLEGAL_ARGUMENT, msg, data: None }
}
Expand Down
18 changes: 2 additions & 16 deletions runtime/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,22 +203,8 @@ pub trait Runtime: Primitives + Verifier + RuntimePolicy {
if ret.exit_code.is_success() {
Ok(ret.return_data)
} else {
// The returned code can't be simply propagated as it may be a system exit code.
// TODO: improve propagation once we return a RuntimeError.
// Ref https://github.com/filecoin-project/builtin-actors/issues/144
let exit_code = match ret.exit_code {
// This means the called actor did something wrong. We can't "make up" a
// reasonable exit code.
ExitCode::SYS_MISSING_RETURN
| ExitCode::SYS_ILLEGAL_INSTRUCTION
| ExitCode::SYS_ILLEGAL_EXIT_CODE => ExitCode::USR_UNSPECIFIED,
// We don't expect any other system errors.
code if code.is_system_error() => ExitCode::USR_ASSERTION_FAILED,
// Otherwise, pass it through.
code => code,
};
Err(ActorError::unchecked_with_data(
exit_code,
Err(ActorError::checked_with_data(
ret.exit_code,
format!(
"send to {} method {} aborted with code {}",
to, method, ret.exit_code
Expand Down