Skip to content

Commit

Permalink
fix: dont use Stack::default (#5521)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Nov 21, 2023
1 parent afdb0a3 commit c825b26
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
10 changes: 4 additions & 6 deletions crates/revm/revm-inspectors/src/tracing/builder/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,10 @@ impl ParityTraceBuilder {
};
let mut push_stack = step.push_stack.clone().unwrap_or_default();
for idx in (0..show_stack).rev() {
if step.stack.len() > idx {
push_stack.push(step.stack.peek(idx).unwrap_or_default())
if let Some(stack) = step.stack.as_ref() {
if stack.len() > idx {
push_stack.push(stack.peek(idx).unwrap_or_default())
}
}
}
push_stack
Expand Down Expand Up @@ -487,10 +489,6 @@ impl ParityTraceBuilder {
}

/// An iterator for [TransactionTrace]s
///
/// This iterator handles additional selfdestruct actions based on the last emitted
/// [TransactionTrace], since selfdestructs are not recorded as individual call traces but are
/// derived from recorded call
struct TransactionTraceIter<Iter> {
iter: Iter,
next_selfdestruct: Option<TransactionTrace>,
Expand Down
12 changes: 7 additions & 5 deletions crates/revm/revm-inspectors/src/tracing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@ impl TracingInspector {
.record_memory_snapshots
.then(|| RecordedMemory::new(interp.shared_memory.context_memory().to_vec()))
.unwrap_or_default();
let stack =
self.config.record_stack_snapshots.then(|| interp.stack.clone()).unwrap_or_default();
let stack = self.config.record_stack_snapshots.then(|| interp.stack.clone());

let op = OpCode::new(interp.current_opcode())
.or_else(|| {
Expand Down Expand Up @@ -326,9 +325,12 @@ impl TracingInspector {
self.step_stack.pop().expect("can't fill step without starting a step first");
let step = &mut self.traces.arena[trace_idx].trace.steps[step_idx];

if interp.stack.len() > step.stack.len() {
// if the stack grew, we need to record the new values
step.push_stack = Some(interp.stack.data()[step.stack.len()..].to_vec());
if let Some(stack) = step.stack.as_ref() {
// only check stack changes if record stack snapshots is enabled: if stack is Some
if interp.stack.len() > stack.len() {
// if the stack grew, we need to record the new values
step.push_stack = Some(interp.stack.data()[stack.len()..].to_vec());
}
}

if self.config.record_memory_snapshots {
Expand Down
9 changes: 2 additions & 7 deletions crates/revm/revm-inspectors/src/tracing/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,6 @@ impl CallTraceNode {
}

/// Converts this call trace into an _empty_ geth [CallFrame]
///
/// Caution: this does not include any of the child calls
pub(crate) fn geth_empty_call_frame(&self, include_logs: bool) -> CallFrame {
let mut call_frame = CallFrame {
typ: self.trace.kind.to_string(),
Expand Down Expand Up @@ -485,9 +483,6 @@ pub(crate) struct CallTraceStepStackItem<'a> {
}

/// Ordering enum for calls and logs
///
/// i.e. if Call 0 occurs before Log 0, it will be pushed into the `CallTraceNode`'s ordering before
/// the log.
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) enum LogCallOrder {
Log(usize),
Expand Down Expand Up @@ -516,7 +511,7 @@ pub(crate) struct CallTraceStep {
/// Current contract address
pub(crate) contract: Address,
/// Stack before step execution
pub(crate) stack: Stack,
pub(crate) stack: Option<Stack>,
/// The new stack items placed by this step if any
pub(crate) push_stack: Option<Vec<U256>>,
/// All allocated memory in a step
Expand Down Expand Up @@ -568,7 +563,7 @@ impl CallTraceStep {
};

if opts.is_stack_enabled() {
log.stack = Some(self.stack.data().clone());
log.stack = self.stack.as_ref().map(|stack| stack.data().clone());
}

if opts.is_memory_enabled() {
Expand Down
1 change: 1 addition & 0 deletions crates/rpc/rpc/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ fn tracing_config(trace_types: &HashSet<TraceType>) -> TracingInspectorConfig {
let needs_vm_trace = trace_types.contains(&TraceType::VmTrace);
TracingInspectorConfig::default_parity()
.set_steps(needs_vm_trace)
.set_stack_snapshots(needs_vm_trace)
.set_memory_snapshots(needs_vm_trace)
}

Expand Down

0 comments on commit c825b26

Please sign in to comment.