Skip to content

Commit

Permalink
refactor: simplify SuccessOrHalt trait bound (#1768)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodann committed Sep 16, 2024
1 parent f57e3e6 commit 8d6c5d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions crates/interpreter/src/instruction_result.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use core::fmt::Debug;

use derive_where::derive_where;
use revm_primitives::EvmWiring;
use revm_primitives::HaltReasonTrait;

use crate::primitives::{HaltReason, OutOfGasError, SuccessReason};

Expand Down Expand Up @@ -236,17 +235,16 @@ pub enum InternalResult {
InvalidExtDelegateCallTarget,
}

#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[derive_where(Debug; EvmWiringT::HaltReason)]
pub enum SuccessOrHalt<EvmWiringT: EvmWiring> {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum SuccessOrHalt<HaltReasonT: HaltReasonTrait> {
Success(SuccessReason),
Revert,
Halt(EvmWiringT::HaltReason),
Halt(HaltReasonT),
FatalExternalError,
Internal(InternalResult),
}

impl<EvmWiringT: EvmWiring> SuccessOrHalt<EvmWiringT> {
impl<HaltReasonT: HaltReasonTrait> SuccessOrHalt<HaltReasonT> {
/// Returns true if the transaction returned successfully without halts.
#[inline]
pub fn is_success(self) -> bool {
Expand Down Expand Up @@ -276,15 +274,15 @@ impl<EvmWiringT: EvmWiring> SuccessOrHalt<EvmWiringT> {

/// Returns the [HaltReason] value the EVM has experienced an exceptional halt
#[inline]
pub fn to_halt(self) -> Option<EvmWiringT::HaltReason> {
pub fn to_halt(self) -> Option<HaltReasonT> {
match self {
SuccessOrHalt::Halt(reason) => Some(reason),
_ => None,
}
}
}

impl<EvmWiringT: EvmWiring> From<InstructionResult> for SuccessOrHalt<EvmWiringT> {
impl<HaltReasonT: HaltReasonTrait> From<InstructionResult> for SuccessOrHalt<HaltReasonT> {
fn from(result: InstructionResult) -> Self {
match result {
InstructionResult::Continue => Self::Internal(InternalResult::InternalContinue), // used only in interpreter loop
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/handler/mainnet/post_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn output<EvmWiringT: EvmWiring>(
// reset journal and return present state.
let (state, logs) = context.evm.journaled_state.finalize();

let result = match SuccessOrHalt::<EvmWiringT>::from(instruction_result.result) {
let result = match SuccessOrHalt::<EvmWiringT::HaltReason>::from(instruction_result.result) {
SuccessOrHalt::Success(reason) => ExecutionResult::Success {
reason,
gas_used: final_gas_used,
Expand Down

0 comments on commit 8d6c5d1

Please sign in to comment.