Skip to content

Commit

Permalink
Refactor to use exit code shim
Browse files Browse the repository at this point in the history
  • Loading branch information
elmattic committed Jan 9, 2025
1 parent ff508b0 commit b2c5430
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/rpc/methods/eth/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ use crate::eth::{EAMMethod, EVMMethod};
use crate::rpc::methods::eth::lookup_eth_address;
use crate::rpc::methods::state::ExecutionTrace;
use crate::rpc::state::ActorTrace;
use crate::shim::fvm_shared_latest::METHOD_CONSTRUCTOR;
use crate::shim::{actors::is_evm_actor, address::Address, error::ExitCode, state_tree::StateTree};
use fil_actor_eam_state::v12 as eam12;
use fil_actor_evm_state::v15 as evm12;
use fil_actor_init_state::v12::ExecReturn;
use fil_actor_init_state::v15::Method as InitMethod;
use fvm_ipld_blockstore::Blockstore;
use fvm_shared4::{error::ExitCode as ExitCodeV4, METHOD_CONSTRUCTOR};

use anyhow::{bail, Context};
use num::FromPrimitive;
Expand Down Expand Up @@ -74,7 +74,7 @@ fn trace_err_msg(trace: &ExecutionTrace) -> Option<String> {
}

// EVM tools often expect this literal string.
if code == ExitCodeV4::SYS_OUT_OF_GAS.into() {
if code == ExitCode::SYS_OUT_OF_GAS {
return Some("out of gas".into());
}

Expand Down Expand Up @@ -180,7 +180,7 @@ fn build_trace(
// NOTE: The FFI currently folds all unknown syscall errors into "sys assertion
// failed" which is turned into SysErrFatal.
if !address.is_empty()
&& Into::<ExitCodeV4>::into(trace.msg_rct.exit_code) == ExitCodeV4::SYS_INSUFFICIENT_FUNDS
&& Into::<ExitCode>::into(trace.msg_rct.exit_code) == ExitCode::SYS_INSUFFICIENT_FUNDS
{
return Ok((None, None));
}
Expand Down
12 changes: 11 additions & 1 deletion src/shim/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ impl fmt::Display for ExitCode {

impl ExitCode {
/// The lowest exit code that an actor may abort with.
pub const FIRST_USER_EXIT_CODE: u32 = ExitCodeV4::FIRST_USER_EXIT_CODE;
pub const FIRST_USER_EXIT_CODE: u32 = ExitCode_latest::FIRST_USER_EXIT_CODE;

/// Message execution (including subcalls) used more gas than the specified limit.
pub const SYS_OUT_OF_GAS: Self = Self::new(ExitCode_latest::SYS_OUT_OF_GAS);

/// The message sender didn't have the requisite funds.
pub const SYS_INSUFFICIENT_FUNDS: Self = Self::new(ExitCode_latest::SYS_INSUFFICIENT_FUNDS);

/// The initial range of exit codes is reserved for system errors.
/// Actors may define codes starting with this one.
Expand All @@ -97,6 +103,10 @@ impl ExitCode {
pub fn is_success(&self) -> bool {
self.0.is_success()
}

pub const fn new(value: ExitCode_latest) -> Self {
Self(value)
}
}

impl From<u32> for ExitCode {
Expand Down

0 comments on commit b2c5430

Please sign in to comment.