feat(rpc): kickoff geth traces (#1772)

This commit is contained in:
Matthias Seitz
2023-03-19 19:29:22 +01:00
committed by GitHub
parent 0128d42b4b
commit 0936523e3d
12 changed files with 249 additions and 42 deletions

View File

@ -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;
@ -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 }
}
@ -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
@ -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()

View File

@ -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
@ -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 }
}

View File

@ -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.
@ -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 {

View File

@ -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.
///
@ -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>,
@ -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(),