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

refactor: simplify SuccessOrHalt trait bound #1768

Merged
merged 1 commit into from
Sep 16, 2024
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
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
Loading