Skip to content

Commit d718b1d

Browse files
apply CR
1 parent 338323e commit d718b1d

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

actors/runtime/src/actor_error.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ pub struct ActorError {
1212
msg: String,
1313
}
1414

15+
// TODO: use symbolic constant for ErrAssertionFailed when it's defined.
16+
pub const EXIT_CODE_ERR_ASSERTION_FAILED: ExitCode = ExitCode::new(24);
17+
1518
impl ActorError {
1619
/// Creates a new ActorError. This method does not check that the code is in the
1720
/// range of valid actor abort codes.
@@ -44,8 +47,7 @@ impl ActorError {
4447
Self { exit_code: ExitCode::USR_UNSPECIFIED, msg }
4548
}
4649
pub fn user_assertion_failed(msg: String) -> Self {
47-
// TODO: use symbolic constant for ErrAssertionFailed when it's defined.
48-
Self { exit_code: ExitCode::from(24), msg }
50+
Self { exit_code: EXIT_CODE_ERR_ASSERTION_FAILED, msg }
4951
}
5052

5153
/// Returns the exit code of the error.

actors/runtime/src/runtime/fvm.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use fvm_shared::clock::ChainEpoch;
1111
use fvm_shared::crypto::randomness::DomainSeparationTag;
1212
use fvm_shared::crypto::signature::Signature;
1313
use fvm_shared::econ::TokenAmount;
14-
use fvm_shared::error::{ErrorNumber, ExitCode};
14+
use fvm_shared::error::ErrorNumber;
1515
use fvm_shared::piece::PieceInfo;
1616
use fvm_shared::randomness::Randomness;
1717
use fvm_shared::sector::{
@@ -23,7 +23,7 @@ use fvm_shared::{ActorID, MethodNum};
2323

2424
use crate::runtime::actor_blockstore::ActorBlockstore;
2525
use crate::runtime::{ActorCode, ConsensusFault, MessageInfo, Policy, RuntimePolicy, Syscalls};
26-
use crate::{actor_error, ActorError, Runtime};
26+
use crate::{actor_error, ActorError, Runtime, EXIT_CODE_ERR_ASSERTION_FAILED};
2727

2828
lazy_static! {
2929
/// Cid of the empty array Cbor bytes (`EMPTY_ARR_BYTES`).
@@ -270,6 +270,7 @@ where
270270
} else {
271271
// The returned code can't be simply propagated as it may be a system exit code.
272272
// TODO: improve propagation once we return a RuntimeError.
273+
// Ref https://github.com/filecoin-project/builtin-actors/issues/144
273274
Err(actor_error!(
274275
user_assertion_failed,
275276
format!(
@@ -448,7 +449,7 @@ pub fn trampoline<C: ActorCode>(params: u32) -> u32 {
448449
// We do this after handling the error, because the actor may have encountered an error before
449450
// it even could validate the caller.
450451
if !rt.caller_validated {
451-
fvm::vm::abort(ExitCode::USR_UNSPECIFIED.value(), Some("failed to validate caller"))
452+
fvm::vm::abort(EXIT_CODE_ERR_ASSERTION_FAILED.value(), Some("failed to validate caller"))
452453
}
453454

454455
// Then handle the return value.

actors/runtime/src/test_utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ impl Runtime<MemoryBlockstore> for MockRuntime {
785785
F: FnOnce(&mut C, &mut Self) -> Result<RT, ActorError>,
786786
{
787787
if self.in_transaction {
788-
return Err(actor_error!(unspecified; "nested transaction"));
788+
return Err(actor_error!(user_assertion_failed; "nested transaction"));
789789
}
790790
let mut read_only = self.state()?;
791791
self.in_transaction = true;
@@ -810,7 +810,7 @@ impl Runtime<MemoryBlockstore> for MockRuntime {
810810
) -> Result<RawBytes, ActorError> {
811811
self.require_in_call();
812812
if self.in_transaction {
813-
return Err(actor_error!(unspecified; "side-effect within transaction"));
813+
return Err(actor_error!(user_assertion_failed; "side-effect within transaction"));
814814
}
815815

816816
assert!(
@@ -855,7 +855,7 @@ impl Runtime<MemoryBlockstore> for MockRuntime {
855855
fn create_actor(&mut self, code_id: Cid, actor_id: ActorID) -> Result<(), ActorError> {
856856
self.require_in_call();
857857
if self.in_transaction {
858-
return Err(actor_error!(unspecified; "side-effect within transaction"));
858+
return Err(actor_error!(user_assertion_failed; "side-effect within transaction"));
859859
}
860860
let expect_create_actor = self
861861
.expectations
@@ -871,7 +871,7 @@ impl Runtime<MemoryBlockstore> for MockRuntime {
871871
fn delete_actor(&mut self, addr: &Address) -> Result<(), ActorError> {
872872
self.require_in_call();
873873
if self.in_transaction {
874-
return Err(actor_error!(unspecified; "side-effect within transaction"));
874+
return Err(actor_error!(user_assertion_failed; "side-effect within transaction"));
875875
}
876876
let exp_act = self.expectations.borrow_mut().expect_delete_actor.take();
877877
if exp_act.is_none() {

0 commit comments

Comments
 (0)