Skip to content

Commit

Permalink
fix(tracing): align trace output with geth (#198)
Browse files Browse the repository at this point in the history
1. The error msg should not be converted to parity style in
`callTracer`. They should only be converted in `flatCallTracer` which is
not supported by reth now.
2. The `gasUsed` should be the `gasLimit` when there's a not reverted
error.
3. The `call_frame.to` should be None if the call type is
`Create/Create2` and it failed.

Related geth code: 
*
https://github.com/ethereum/go-ethereum/blob/a9523b6428238a762e1a1e55e46ead47630c3a23/eth/tracers/native/call_flat.go#L226
*
https://github.com/ethereum/go-ethereum/blob/a9523b6428238a762e1a1e55e46ead47630c3a23/core/vm/evm.go#L254
*
https://github.com/ethereum/go-ethereum/blob/a9523b6428238a762e1a1e55e46ead47630c3a23/eth/tracers/native/call.go#L88

---------

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
  • Loading branch information
pythonberg1997 and mattsse authored Sep 14, 2024
1 parent 08995dd commit ac15221
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/tracing/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ impl CallTrace {
InstructionResult::PrecompileError => {
if kind.is_parity() { "Built-in failed" } else { "precompiled failed" }.to_string()
}
InstructionResult::InvalidFEOpcode => {
if kind.is_parity() { "Bad instruction" } else { "invalid opcode: INVALID" }
.to_string()
}
status => format!("{:?}", status),
})
}
Expand Down Expand Up @@ -402,10 +406,19 @@ impl CallTraceNode {

// we need to populate error and revert reason
if !self.trace.success {
if self.kind().is_any_create() {
call_frame.to = None;
}

if !self.status().is_revert() {
call_frame.gas_used = U256::from(self.trace.gas_limit);
call_frame.output = None;
}

call_frame.revert_reason = utils::maybe_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_msg(TraceStyle::Parity);
// Note: regular calltracer uses geth errors, only flatCallTracer uses parity errors: <https://github.com/ethereum/go-ethereum/blob/a9523b6428238a762e1a1e55e46ead47630c3a23/eth/tracers/native/call_flat.go#L226>
call_frame.error = self.trace.as_error_msg(TraceStyle::Geth);
}

if include_logs && !self.logs.is_empty() {
Expand Down

0 comments on commit ac15221

Please sign in to comment.