From 0d33585426f52e7a098d0f0892efc618d1a99822 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 3 Aug 2023 18:30:14 +0200 Subject: [PATCH] chore: move call op match to fn (#4047) --- .../src/tracing/builder/parity.rs | 15 +++----- .../revm/revm-inspectors/src/tracing/types.rs | 35 +++++++++++-------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/crates/revm/revm-inspectors/src/tracing/builder/parity.rs b/crates/revm/revm-inspectors/src/tracing/builder/parity.rs index fb18366424..f1eb1b6060 100644 --- a/crates/revm/revm-inspectors/src/tracing/builder/parity.rs +++ b/crates/revm/revm-inspectors/src/tracing/builder/parity.rs @@ -7,7 +7,6 @@ use reth_primitives::{Address, U64}; use reth_rpc_types::{trace::parity::*, TransactionInfo}; use revm::{ db::DatabaseRef, - interpreter::opcode, primitives::{AccountInfo, ExecutionResult, ResultAndState, KECCAK_EMPTY}, }; use std::collections::{HashSet, VecDeque}; @@ -301,16 +300,10 @@ impl ParityTraceBuilder { Vec::with_capacity(current.trace.steps.len()); for step in ¤t.trace.steps { - let maybe_sub = match step.op.u8() { - opcode::CALL | - opcode::CALLCODE | - opcode::DELEGATECALL | - opcode::STATICCALL | - opcode::CREATE | - opcode::CREATE2 => { - sub_stack.pop_front().expect("there should be a sub trace") - } - _ => None, + let maybe_sub = if step.is_calllike_op() { + sub_stack.pop_front().expect("there should be a sub trace") + } else { + None }; instructions.push(Self::make_instruction(step, maybe_sub)); diff --git a/crates/revm/revm-inspectors/src/tracing/types.rs b/crates/revm/revm-inspectors/src/tracing/types.rs index b7d8648140..0aee843053 100644 --- a/crates/revm/revm-inspectors/src/tracing/types.rs +++ b/crates/revm/revm-inspectors/src/tracing/types.rs @@ -260,21 +260,13 @@ impl CallTraceNode { let mut item = CallTraceStepStackItem { trace_node: self, step, call_child_id: None }; // If the opcode is a call, put the child trace on the stack - match step.op.u8() { - opcode::CREATE | - opcode::CREATE2 | - opcode::DELEGATECALL | - opcode::CALL | - opcode::STATICCALL | - opcode::CALLCODE => { - // The opcode of this step is a call but it's possible that this step resulted - // in a revert or out of gas error in which case there's no actual child call executed and recorded: - if let Some(call_id) = self.children.get(child_id).copied() { - item.call_child_id = Some(call_id); - child_id += 1; - } + if step.is_calllike_op() { + // The opcode of this step is a call but it's possible that this step resulted + // in a revert or out of gas error in which case there's no actual child call executed and recorded: + if let Some(call_id) = self.children.get(child_id).copied() { + item.call_child_id = Some(call_id); + child_id += 1; } - _ => {} } stack.push(item); } @@ -607,6 +599,21 @@ impl CallTraceStep { log } + /// Returns true if the step is a call operation, any of + /// CALL, CALLCODE, DELEGATECALL, STATICCALL, CREATE, CREATE2 + #[inline] + pub(crate) fn is_calllike_op(&self) -> bool { + matches!( + self.op.u8(), + opcode::CALL | + opcode::DELEGATECALL | + opcode::STATICCALL | + opcode::CREATE | + opcode::CALLCODE | + opcode::CREATE2 + ) + } + // Returns true if the status code is an error or revert, See [InstructionResult::Revert] pub(crate) fn is_error(&self) -> bool { self.status as u8 >= InstructionResult::Revert as u8