Skip to content

Commit

Permalink
chore: misc tracer changes (#5404)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Nov 12, 2023
1 parent c91e87e commit b1b27e2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions crates/revm/revm-inspectors/src/tracing/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub(crate) enum PushTraceKind {
}

impl PushTraceKind {
#[inline]
fn is_attach_to_parent(&self) -> bool {
matches!(self, PushTraceKind::PushAndAttachToParent)
}
Expand Down
1 change: 1 addition & 0 deletions crates/revm/revm-inspectors/src/tracing/opcount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct OpcodeCountInspector {

impl OpcodeCountInspector {
/// Returns the opcode counter
#[inline]
pub fn count(&self) -> usize {
self.count
}
Expand Down
26 changes: 19 additions & 7 deletions crates/revm/revm-inspectors/src/tracing/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,24 +157,26 @@ pub(crate) struct CallTrace {
/// The status of the trace's call
pub(crate) status: InstructionResult,
/// call context of the runtime
pub(crate) call_context: Option<CallContext>,
pub(crate) call_context: Option<Box<CallContext>>,
/// Opcode-level execution steps
pub(crate) steps: Vec<CallTraceStep>,
}

impl CallTrace {
// Returns true if the status code is an error or revert, See [InstructionResult::Revert]
#[inline]
pub(crate) fn is_error(&self) -> bool {
self.status as u8 >= InstructionResult::Revert as u8
self.status.is_error()
}

// Returns true if the status code is a revert
#[inline]
pub(crate) fn is_revert(&self) -> bool {
self.status == InstructionResult::Revert
}

/// Returns the error message if it is an erroneous result.
pub(crate) fn as_error(&self, kind: TraceStyle) -> Option<String> {
pub(crate) fn as_error_msg(&self, kind: TraceStyle) -> Option<String> {
// See also <https://github.com/ethereum/go-ethereum/blob/34d507215951fb3f4a5983b65e127577989a6db8/eth/tracers/native/call_flat.go#L39-L55>
self.is_error().then(|| match self.status {
InstructionResult::Revert => {
Expand Down Expand Up @@ -311,12 +313,14 @@ impl CallTraceNode {
}

/// Returns the kind of call the trace belongs to
pub(crate) fn kind(&self) -> CallKind {
#[inline]
pub(crate) const fn kind(&self) -> CallKind {
self.trace.kind
}

/// Returns the status of the call
pub(crate) fn status(&self) -> InstructionResult {
#[inline]
pub(crate) const fn status(&self) -> InstructionResult {
self.trace.status
}

Expand All @@ -335,7 +339,7 @@ impl CallTraceNode {
} else {
Some(self.parity_trace_output())
};
let error = self.trace.as_error(TraceStyle::Parity);
let error = self.trace.as_error_msg(TraceStyle::Parity);
TransactionTrace { action, error, result, trace_address, subtraces: self.children.len() }
}

Expand Down Expand Up @@ -452,7 +456,7 @@ impl CallTraceNode {
if !self.trace.success {
call_frame.revert_reason = decode_revert_reason(self.trace.output.as_ref());
// Note: the call tracer mimics parity's trace transaction and geth maps errors to parity style error messages, <https://github.com/ethereum/go-ethereum/blob/34d507215951fb3f4a5983b65e127577989a6db8/eth/tracers/native/call_flat.go#L39-L55>
call_frame.error = self.trace.as_error(TraceStyle::Parity);
call_frame.error = self.trace.as_error_msg(TraceStyle::Parity);
}

if include_logs && !self.logs.is_empty() {
Expand Down Expand Up @@ -596,11 +600,13 @@ impl CallTraceStep {
}

// Returns true if the status code is an error or revert, See [InstructionResult::Revert]
#[inline]
pub(crate) fn is_error(&self) -> bool {
self.status as u8 >= InstructionResult::Revert as u8
}

/// Returns the error message if it is an erroneous result.
#[inline]
pub(crate) fn as_error(&self) -> Option<String> {
self.is_error().then(|| format!("{:?}", self.status))
}
Expand Down Expand Up @@ -631,27 +637,33 @@ pub(crate) struct StorageChange {
pub(crate) struct RecordedMemory(pub(crate) Vec<u8>);

impl RecordedMemory {
#[inline]
pub(crate) fn new(mem: Vec<u8>) -> Self {
Self(mem)
}

#[inline]
pub(crate) fn as_bytes(&self) -> &[u8] {
&self.0
}

#[inline]
pub(crate) fn resize(&mut self, size: usize) {
self.0.resize(size, 0);
}

#[inline]
pub(crate) fn len(&self) -> usize {
self.0.len()
}

#[inline]
pub(crate) fn is_empty(&self) -> bool {
self.0.is_empty()
}

/// Converts the memory into 32byte hex chunks
#[inline]
pub(crate) fn memory_chunks(&self) -> Vec<String> {
convert_memory(self.as_bytes())
}
Expand Down

0 comments on commit b1b27e2

Please sign in to comment.