Skip to content

Commit

Permalink
apply CR
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Apr 8, 2022
1 parent 338323e commit d718b1d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 4 additions & 2 deletions actors/runtime/src/actor_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pub struct ActorError {
msg: String,
}

// TODO: use symbolic constant for ErrAssertionFailed when it's defined.
pub const EXIT_CODE_ERR_ASSERTION_FAILED: ExitCode = ExitCode::new(24);

impl ActorError {
/// Creates a new ActorError. This method does not check that the code is in the
/// range of valid actor abort codes.
Expand Down Expand Up @@ -44,8 +47,7 @@ impl ActorError {
Self { exit_code: ExitCode::USR_UNSPECIFIED, msg }
}
pub fn user_assertion_failed(msg: String) -> Self {
// TODO: use symbolic constant for ErrAssertionFailed when it's defined.
Self { exit_code: ExitCode::from(24), msg }
Self { exit_code: EXIT_CODE_ERR_ASSERTION_FAILED, msg }
}

/// Returns the exit code of the error.
Expand Down
7 changes: 4 additions & 3 deletions actors/runtime/src/runtime/fvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use fvm_shared::clock::ChainEpoch;
use fvm_shared::crypto::randomness::DomainSeparationTag;
use fvm_shared::crypto::signature::Signature;
use fvm_shared::econ::TokenAmount;
use fvm_shared::error::{ErrorNumber, ExitCode};
use fvm_shared::error::ErrorNumber;
use fvm_shared::piece::PieceInfo;
use fvm_shared::randomness::Randomness;
use fvm_shared::sector::{
Expand All @@ -23,7 +23,7 @@ use fvm_shared::{ActorID, MethodNum};

use crate::runtime::actor_blockstore::ActorBlockstore;
use crate::runtime::{ActorCode, ConsensusFault, MessageInfo, Policy, RuntimePolicy, Syscalls};
use crate::{actor_error, ActorError, Runtime};
use crate::{actor_error, ActorError, Runtime, EXIT_CODE_ERR_ASSERTION_FAILED};

lazy_static! {
/// Cid of the empty array Cbor bytes (`EMPTY_ARR_BYTES`).
Expand Down Expand Up @@ -270,6 +270,7 @@ where
} 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
Err(actor_error!(
user_assertion_failed,
format!(
Expand Down Expand Up @@ -448,7 +449,7 @@ pub fn trampoline<C: ActorCode>(params: u32) -> u32 {
// We do this after handling the error, because the actor may have encountered an error before
// it even could validate the caller.
if !rt.caller_validated {
fvm::vm::abort(ExitCode::USR_UNSPECIFIED.value(), Some("failed to validate caller"))
fvm::vm::abort(EXIT_CODE_ERR_ASSERTION_FAILED.value(), Some("failed to validate caller"))
}

// Then handle the return value.
Expand Down
8 changes: 4 additions & 4 deletions actors/runtime/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ impl Runtime<MemoryBlockstore> for MockRuntime {
F: FnOnce(&mut C, &mut Self) -> Result<RT, ActorError>,
{
if self.in_transaction {
return Err(actor_error!(unspecified; "nested transaction"));
return Err(actor_error!(user_assertion_failed; "nested transaction"));
}
let mut read_only = self.state()?;
self.in_transaction = true;
Expand All @@ -810,7 +810,7 @@ impl Runtime<MemoryBlockstore> for MockRuntime {
) -> Result<RawBytes, ActorError> {
self.require_in_call();
if self.in_transaction {
return Err(actor_error!(unspecified; "side-effect within transaction"));
return Err(actor_error!(user_assertion_failed; "side-effect within transaction"));
}

assert!(
Expand Down Expand Up @@ -855,7 +855,7 @@ impl Runtime<MemoryBlockstore> for MockRuntime {
fn create_actor(&mut self, code_id: Cid, actor_id: ActorID) -> Result<(), ActorError> {
self.require_in_call();
if self.in_transaction {
return Err(actor_error!(unspecified; "side-effect within transaction"));
return Err(actor_error!(user_assertion_failed; "side-effect within transaction"));
}
let expect_create_actor = self
.expectations
Expand All @@ -871,7 +871,7 @@ impl Runtime<MemoryBlockstore> for MockRuntime {
fn delete_actor(&mut self, addr: &Address) -> Result<(), ActorError> {
self.require_in_call();
if self.in_transaction {
return Err(actor_error!(unspecified; "side-effect within transaction"));
return Err(actor_error!(user_assertion_failed; "side-effect within transaction"));
}
let exp_act = self.expectations.borrow_mut().expect_delete_actor.take();
if exp_act.is_none() {
Expand Down

0 comments on commit d718b1d

Please sign in to comment.