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

feat: Add Step to LogCallOrder #150

Merged
merged 3 commits into from
Jun 21, 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
4 changes: 2 additions & 2 deletions src/tracing/arena.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::types::{CallTrace, CallTraceNode, LogCallOrder};
use super::types::{CallTrace, CallTraceNode, TraceMemberOrder};

/// An arena of recorded traces.
///
Expand Down Expand Up @@ -70,7 +70,7 @@ impl CallTraceArena {
if kind.is_attach_to_parent() {
let parent = &mut self.arena[entry];
let trace_location = parent.children.len();
parent.ordering.push(LogCallOrder::Call(trace_location));
parent.ordering.push(TraceMemberOrder::Call(trace_location));
parent.children.push(id);
}

Expand Down
10 changes: 7 additions & 3 deletions src/tracing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use self::parity::stack_push_count;
use crate::tracing::{
arena::PushTraceKind,
types::{
CallKind, CallTraceNode, LogCallOrder, RecordedMemory, StorageChange, StorageChangeReason,
CallKind, CallTraceNode, RecordedMemory, StorageChange, StorageChangeReason,
TraceMemberOrder,
},
utils::gas_used,
};
Expand Down Expand Up @@ -332,7 +333,8 @@ impl TracingInspector {
let trace_idx = self.last_trace_idx();
let trace = &mut self.traces.arena[trace_idx];

self.step_stack.push(StackStep { trace_idx, step_idx: trace.trace.steps.len() });
let step_idx = trace.trace.steps.len();
self.step_stack.push(StackStep { trace_idx, step_idx });

let memory = self
.config
Expand Down Expand Up @@ -366,6 +368,8 @@ impl TracingInspector {
storage_change: None,
status: InstructionResult::Continue,
});

trace.ordering.push(TraceMemberOrder::Step(step_idx));
}

/// Fills the current trace with the output of a step.
Expand Down Expand Up @@ -456,7 +460,7 @@ where
fn log(&mut self, _context: &mut EvmContext<DB>, log: &Log) {
if self.config.record_logs {
let trace = self.last_trace();
trace.ordering.push(LogCallOrder::Log(trace.logs.len()));
trace.ordering.push(TraceMemberOrder::Log(trace.logs.len()));
trace.logs.push(log.data.clone());
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/tracing/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub struct CallTraceNode {
/// Recorded logs, if enabled
pub logs: Vec<LogData>,
/// Ordering of child calls and logs
pub ordering: Vec<LogCallOrder>,
pub ordering: Vec<TraceMemberOrder>,
}

impl CallTraceNode {
Expand Down Expand Up @@ -470,14 +470,16 @@ pub(crate) struct CallTraceStepStackItem<'a> {
pub(crate) call_child_id: Option<usize>,
}

/// Ordering enum for calls and logs
/// Ordering enum for calls, logs and steps
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum LogCallOrder {
pub enum TraceMemberOrder {
/// Contains the index of the corresponding log
Log(usize),
/// Contains the index of the corresponding trace node
Call(usize),
/// Contains the index of the corresponding step, if those are being traced
Step(usize),
}

/// Represents a tracked call step during execution
Expand Down
7 changes: 4 additions & 3 deletions src/tracing/writer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{
types::{CallKind, CallTrace, CallTraceNode, LogCallOrder},
types::{CallKind, CallTrace, CallTraceNode, TraceMemberOrder},
CallTraceArena,
};
use alloy_primitives::{address, hex, Address, LogData};
Expand Down Expand Up @@ -98,8 +98,9 @@ impl<W: Write> TraceWriter<W> {
self.indentation_level += 1;
for child in &node.ordering {
match *child {
LogCallOrder::Log(index) => self.write_raw_log(&node.logs[index]),
LogCallOrder::Call(index) => self.write_node(nodes, node.children[index]),
TraceMemberOrder::Log(index) => self.write_raw_log(&node.logs[index]),
TraceMemberOrder::Call(index) => self.write_node(nodes, node.children[index]),
TraceMemberOrder::Step(_) => Ok(()),
}?;
}

Expand Down
Loading