mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: misc tracer changes (#5404)
This commit is contained in:
@ -68,6 +68,7 @@ pub(crate) enum PushTraceKind {
|
||||
}
|
||||
|
||||
impl PushTraceKind {
|
||||
#[inline]
|
||||
fn is_attach_to_parent(&self) -> bool {
|
||||
matches!(self, PushTraceKind::PushAndAttachToParent)
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ pub struct OpcodeCountInspector {
|
||||
|
||||
impl OpcodeCountInspector {
|
||||
/// Returns the opcode counter
|
||||
#[inline]
|
||||
pub fn count(&self) -> usize {
|
||||
self.count
|
||||
}
|
||||
|
||||
@ -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 => {
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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() }
|
||||
}
|
||||
|
||||
@ -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() {
|
||||
@ -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))
|
||||
}
|
||||
@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user