fix: map more errors to messages (#3837)

This commit is contained in:
Matthias Seitz
2023-07-18 17:34:38 +02:00
committed by GitHub
parent 9313eda6cc
commit 0ef68b7d63
2 changed files with 42 additions and 5 deletions

View File

@@ -1,5 +1,24 @@
use reth_rpc_types::trace::geth::GethDefaultTracingOptions;
/// What kind of tracing style this is.
///
/// This affects things like error messages.
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub(crate) enum TraceStyle {
/// Parity style tracer
Parity,
/// Geth style tracer
#[allow(unused)]
Geth,
}
impl TraceStyle {
/// Returns true if this is a parity style tracer.
pub(crate) const fn is_parity(self) -> bool {
matches!(self, Self::Parity)
}
}
/// Gives guidance to the [TracingInspector](crate::tracing::TracingInspector).
///
/// Use [TracingInspectorConfig::default_parity] or [TracingInspectorConfig::default_geth] to get

View File

@@ -1,6 +1,6 @@
//! Types for representing call trace items.
use crate::tracing::utils::convert_memory;
use crate::tracing::{config::TraceStyle, utils::convert_memory};
use reth_primitives::{abi::decode_revert_reason, bytes::Bytes, Address, H256, U256};
use reth_rpc_types::trace::{
geth::{CallFrame, CallLogFrame, GethDefaultTracingOptions, StructLog},
@@ -160,9 +160,26 @@ impl CallTrace {
}
/// Returns the error message if it is an erroneous result.
pub(crate) fn as_error(&self) -> Option<String> {
pub(crate) fn as_error(&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 => "Reverted".to_string(),
InstructionResult::Revert => {
if kind.is_parity() { "Reverted" } else { "execution reverted" }.to_string()
}
InstructionResult::OutOfGas | InstructionResult::MemoryOOG => {
if kind.is_parity() { "Out of gas" } else { "out of gas" }.to_string()
}
InstructionResult::OpcodeNotFound => {
if kind.is_parity() { "Bad instruction" } else { "invalid opcode" }.to_string()
}
InstructionResult::StackOverflow => "Out of stack".to_string(),
InstructionResult::InvalidJump => {
if kind.is_parity() { "Bad jump destination" } else { "invalid jump destination" }
.to_string()
}
InstructionResult::PrecompileError => {
if kind.is_parity() { "Built-in failed" } else { "precompiled failed" }.to_string()
}
status => format!("{:?}", status),
})
}
@@ -324,7 +341,7 @@ impl CallTraceNode {
pub(crate) fn parity_transaction_trace(&self, trace_address: Vec<usize>) -> TransactionTrace {
let action = self.parity_action();
let output = self.parity_trace_output();
let error = self.trace.as_error();
let error = self.trace.as_error(TraceStyle::Parity);
TransactionTrace {
action,
error,
@@ -402,7 +419,8 @@ impl CallTraceNode {
// we need to populate error and revert reason
if !self.trace.success {
call_frame.revert_reason = decode_revert_reason(self.trace.output.clone());
call_frame.error = self.trace.as_error();
// 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);
}
if include_logs && !self.logs.is_empty() {