chore: move call op match to fn (#4047)

This commit is contained in:
Matthias Seitz
2023-08-03 18:30:14 +02:00
committed by GitHub
parent 77b7d77819
commit 0d33585426
2 changed files with 25 additions and 25 deletions

View File

@@ -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 &current.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));

View File

@@ -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: <https://github.com/paradigmxyz/reth/issues/3915>
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: <https://github.com/paradigmxyz/reth/issues/3915>
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