From ac15221076e4eb38447a6a37cf99f01b7573ee72 Mon Sep 17 00:00:00 2001 From: Roshan <48975233+pythonberg1997@users.noreply.github.com> Date: Sat, 14 Sep 2024 17:13:43 +0800 Subject: [PATCH] fix(tracing): align trace output with geth (#198) 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 --- src/tracing/types.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/tracing/types.rs b/src/tracing/types.rs index 16b725f..b1fff1f 100644 --- a/src/tracing/types.rs +++ b/src/tracing/types.rs @@ -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), }) } @@ -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, - call_frame.error = self.trace.as_error_msg(TraceStyle::Parity); + // Note: regular calltracer uses geth errors, only flatCallTracer uses parity errors: + call_frame.error = self.trace.as_error_msg(TraceStyle::Geth); } if include_logs && !self.logs.is_empty() {