Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions crates/revm/revm-inspectors/src/tracing/builder/geth.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Geth trace builder

use crate::tracing::{types::CallTraceNode, TraceInspectorConfig};
use crate::tracing::{types::CallTraceNode, TracingInspectorConfig};
use reth_primitives::{Address, JsonU256, H256, U256};
use reth_rpc_types::trace::geth::*;
use revm::interpreter::opcode;
Expand All @@ -12,12 +12,12 @@ pub struct GethTraceBuilder {
/// Recorded trace nodes.
nodes: Vec<CallTraceNode>,
/// How the traces were recorded
_config: TraceInspectorConfig,
_config: TracingInspectorConfig,
}

impl GethTraceBuilder {
/// Returns a new instance of the builder
pub(crate) fn new(nodes: Vec<CallTraceNode>, _config: TraceInspectorConfig) -> Self {
pub(crate) fn new(nodes: Vec<CallTraceNode>, _config: TracingInspectorConfig) -> Self {
Self { nodes, _config }
}

Expand All @@ -29,7 +29,7 @@ impl GethTraceBuilder {
storage: &mut HashMap<Address, BTreeMap<H256, H256>>,
trace_node: &CallTraceNode,
struct_logs: &mut Vec<StructLog>,
opts: &GethDebugTracingOptions,
opts: &GethDefaultTracingOptions,
) {
let mut child_id = 0;
// Iterate over the steps inside the given trace
Expand Down Expand Up @@ -80,7 +80,7 @@ impl GethTraceBuilder {
&self,
// TODO(mattsse): This should be the total gas used, or gas used by last CallTrace?
receipt_gas_used: U256,
opts: GethDebugTracingOptions,
opts: GethDefaultTracingOptions,
) -> DefaultFrame {
if self.nodes.is_empty() {
return Default::default()
Expand Down
6 changes: 3 additions & 3 deletions crates/revm/revm-inspectors/src/tracing/builder/parity.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::tracing::{types::CallTraceNode, TraceInspectorConfig};
use crate::tracing::{types::CallTraceNode, TracingInspectorConfig};
use reth_rpc_types::{trace::parity::*, TransactionInfo};

/// A type for creating parity style traces
Expand All @@ -7,12 +7,12 @@ pub struct ParityTraceBuilder {
/// Recorded trace nodes
nodes: Vec<CallTraceNode>,
/// How the traces were recorded
_config: TraceInspectorConfig,
_config: TracingInspectorConfig,
}

impl ParityTraceBuilder {
/// Returns a new instance of the builder
pub(crate) fn new(nodes: Vec<CallTraceNode>, _config: TraceInspectorConfig) -> Self {
pub(crate) fn new(nodes: Vec<CallTraceNode>, _config: TracingInspectorConfig) -> Self {
Self { nodes, _config }
}

Expand Down
8 changes: 4 additions & 4 deletions crates/revm/revm-inspectors/src/tracing/config.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/// Gives guidance to the [TracingInspector](crate::tracing::TracingInspector).
///
/// Use [TraceInspectorConfig::default_parity] or [TraceInspectorConfig::default_geth] to get the
/// default configs for specific styles of traces.
/// Use [TracingInspectorConfig::default_parity] or [TracingInspectorConfig::default_geth] to get
/// the default configs for specific styles of traces.
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct TraceInspectorConfig {
pub struct TracingInspectorConfig {
/// Whether to record every individual opcode level step.
pub record_steps: bool,
/// Whether to record individual memory snapshots.
Expand All @@ -14,7 +14,7 @@ pub struct TraceInspectorConfig {
pub record_state_diff: bool,
}

impl TraceInspectorConfig {
impl TracingInspectorConfig {
/// Returns a config with everything enabled.
pub const fn all() -> Self {
Self {
Expand Down
6 changes: 3 additions & 3 deletions crates/revm/revm-inspectors/src/tracing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod config;
mod types;
mod utils;
pub use builder::{geth::GethTraceBuilder, parity::ParityTraceBuilder};
pub use config::TraceInspectorConfig;
pub use config::TracingInspectorConfig;

/// An inspector that collects call traces.
///
Expand All @@ -36,7 +36,7 @@ pub use config::TraceInspectorConfig;
#[derive(Debug, Clone)]
pub struct TracingInspector {
/// Configures what and how the inspector records traces.
config: TraceInspectorConfig,
config: TracingInspectorConfig,
/// Records all call traces
traces: CallTraceArena,
trace_stack: Vec<usize>,
Expand All @@ -52,7 +52,7 @@ pub struct TracingInspector {

impl TracingInspector {
/// Returns a new instance for the given config
pub fn new(config: TraceInspectorConfig) -> Self {
pub fn new(config: TracingInspectorConfig) -> Self {
Self {
config,
traces: Default::default(),
Expand Down
4 changes: 3 additions & 1 deletion crates/rpc/rpc-types/src/eth/trace/geth/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub struct CallLogFrame {
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CallConfig {
/// When set to true, this will only trace the primary (top-level) call and not any sub-calls.
/// It eliminates the additional processing for each call frame
#[serde(default, skip_serializing_if = "Option::is_none")]
pub only_top_call: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
Expand All @@ -60,7 +62,7 @@ mod tests {
#[test]
fn test_serialize_call_trace() {
let mut opts = GethDebugTracingCallOptions::default();
opts.tracing_options.disable_storage = Some(false);
opts.tracing_options.config.disable_storage = Some(false);
opts.tracing_options.tracer =
Some(GethDebugTracerType::BuiltInTracer(GethDebugBuiltInTracerType::CallTracer));
opts.tracing_options.tracer_config =
Expand Down
113 changes: 106 additions & 7 deletions crates/rpc/rpc-types/src/eth/trace/geth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,28 @@ impl From<serde_json::Value> for GethTrace {
/// See <https://geth.ethereum.org/docs/developers/evm-tracing/built-in-tracers>
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
pub enum GethDebugBuiltInTracerType {
/// The 4byteTracer collects the function selectors of every function executed in the lifetime
/// of a transaction, along with the size of the supplied call data. The result is a
/// [FourByteFrame] where the keys are SELECTOR-CALLDATASIZE and the values are number of
/// occurrences of this key.
#[serde(rename = "4byteTracer")]
FourByteTracer,
/// The callTracer tracks all the call frames executed during a transaction, including depth 0.
/// The result will be a nested list of call frames, resembling how EVM works. They form a tree
/// with the top-level call at root and sub-calls as children of the higher levels.
#[serde(rename = "callTracer")]
CallTracer,
/// The prestate tracer has two modes: prestate and diff. The prestate mode returns the
/// accounts necessary to execute a given transaction. diff mode returns the differences
/// between the transaction's pre and post-state (i.e. what changed because the transaction
/// happened). The prestateTracer defaults to prestate mode. It reexecutes the given
/// transaction and tracks every part of state that is touched. This is similar to the concept
/// of a stateless witness, the difference being this tracer doesn't return any cryptographic
/// proof, rather only the trie leaves. The result is an object. The keys are addresses of
/// accounts.
#[serde(rename = "prestateTracer")]
PreStateTracer,
/// This tracer is noop. It returns an empty object and is only meant for testing the setup.
#[serde(rename = "noopTracer")]
NoopTracer,
}
Expand All @@ -152,6 +168,22 @@ pub enum GethDebugBuiltInTracerConfig {
PreStateTracer(PreStateConfig),
}

// === impl GethDebugBuiltInTracerConfig ===

impl GethDebugBuiltInTracerConfig {
/// Returns true if the config matches the given tracer
pub fn matches_tracer(&self, tracer: &GethDebugBuiltInTracerType) -> bool {
matches!(
(self, tracer),
(GethDebugBuiltInTracerConfig::CallTracer(_), GethDebugBuiltInTracerType::CallTracer,) |
(
GethDebugBuiltInTracerConfig::PreStateTracer(_),
GethDebugBuiltInTracerType::PreStateTracer,
)
)
}
}

/// Available tracers
///
/// See <https://geth.ethereum.org/docs/developers/evm-tracing/built-in-tracers> and <https://geth.ethereum.org/docs/developers/evm-tracing/custom-tracer>
Expand All @@ -174,28 +206,95 @@ pub enum GethDebugTracerConfig {
JsTracer(serde_json::Value),
}

// === impl GethDebugTracerConfig ===

impl GethDebugTracerConfig {
/// Returns the [CallConfig] if it is a call config.
pub fn into_call_config(self) -> Option<CallConfig> {
match self {
GethDebugTracerConfig::BuiltInTracer(GethDebugBuiltInTracerConfig::CallTracer(cfg)) => {
Some(cfg)
}
_ => None,
}
}

/// Returns the [PreStateConfig] if it is a call config.
pub fn into_pre_state_config(self) -> Option<PreStateConfig> {
match self {
GethDebugTracerConfig::BuiltInTracer(GethDebugBuiltInTracerConfig::PreStateTracer(
cfg,
)) => Some(cfg),
_ => None,
}
}

/// Returns true if the config matches the given tracer
pub fn matches_tracer(&self, tracer: &GethDebugTracerType) -> bool {
match (self, tracer) {
(_, GethDebugTracerType::BuiltInTracer(tracer)) => self.matches_builtin_tracer(tracer),
(GethDebugTracerConfig::JsTracer(_), GethDebugTracerType::JsTracer(_)) => true,
_ => false,
}
}

/// Returns true if the config matches the given tracer
pub fn matches_builtin_tracer(&self, tracer: &GethDebugBuiltInTracerType) -> bool {
match (self, tracer) {
(GethDebugTracerConfig::BuiltInTracer(config), tracer) => config.matches_tracer(tracer),
(GethDebugTracerConfig::JsTracer(_), _) => false,
}
}
}

/// Bindings for additional `debug_traceTransaction` options
///
/// See <https://geth.ethereum.org/docs/rpc/ns-debug#debug_tracetransaction>
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GethDebugTracingOptions {
#[serde(default, flatten)]
pub config: GethDefaultTracingOptions,
/// The custom tracer to use.
///
/// If `None` then the default structlog tracer is used.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub disable_storage: Option<bool>,
pub tracer: Option<GethDebugTracerType>,
/// tracerConfig is slated for Geth v1.11.0
/// See <https://github.com/ethereum/go-ethereum/issues/26513>
#[serde(default, skip_serializing_if = "Option::is_none")]
pub disable_stack: Option<bool>,
pub tracer_config: Option<GethDebugTracerConfig>,
/// A string of decimal integers that overrides the JavaScript-based tracing calls default
/// timeout of 5 seconds.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub timeout: Option<String>,
}

/// Default tracing options for the struct looger
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GethDefaultTracingOptions {
/// enable memory capture
#[serde(default, skip_serializing_if = "Option::is_none")]
pub enable_memory: Option<bool>,
/// disable stack capture
#[serde(default, skip_serializing_if = "Option::is_none")]
pub disable_stack: Option<bool>,
/// disable storage capture
#[serde(default, skip_serializing_if = "Option::is_none")]
pub disable_storage: Option<bool>,
/// enable return data capture
#[serde(default, skip_serializing_if = "Option::is_none")]
pub enable_return_data: Option<bool>,
/// print output during capture end
#[serde(default, skip_serializing_if = "Option::is_none")]
pub tracer: Option<GethDebugTracerType>,
/// tracerConfig is slated for Geth v1.11.0
/// See <https://github.com/ethereum/go-ethereum/issues/26513>
pub debug: Option<bool>,
/// maximum length of output, but zero means unlimited
#[serde(default, skip_serializing_if = "Option::is_none")]
pub tracer_config: Option<GethDebugTracerConfig>,
pub limit: Option<u64>,
/// Chain overrides, can be used to execute a trace using future fork rules
#[serde(default, skip_serializing_if = "Option::is_none")]
pub timeout: Option<String>,
pub overrides: Option<serde_json::Value>,
}

/// Bindings for additional `debug_traceCall` options
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-types/src/eth/trace/geth/pre_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ mod tests {
#[test]
fn test_serialize_pre_state_trace() {
let mut opts = GethDebugTracingCallOptions::default();
opts.tracing_options.disable_storage = Some(false);
opts.tracing_options.config.disable_storage = Some(false);
opts.tracing_options.tracer =
Some(GethDebugTracerType::BuiltInTracer(GethDebugBuiltInTracerType::PreStateTracer));
opts.tracing_options.tracer_config = Some(GethDebugTracerConfig::BuiltInTracer(
Expand Down
Loading