Skip to content

Commit

Permalink
fix: use correct trace_call params (paradigmxyz#5214)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Oct 28, 2023
1 parent aa4a39e commit de01f08
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
14 changes: 11 additions & 3 deletions crates/rpc/rpc-api/src/trace.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
use reth_primitives::{BlockId, Bytes, B256};
use reth_rpc_types::{
trace::{filter::TraceFilter, parity::*, tracerequest::TraceRequest},
CallRequest, Index,
state::StateOverride,
trace::{filter::TraceFilter, parity::*},
BlockOverrides, CallRequest, Index,
};
use std::collections::HashSet;

Expand All @@ -12,7 +13,14 @@ use std::collections::HashSet;
pub trait TraceApi {
/// Executes the given call and returns a number of possible traces for it.
#[method(name = "call")]
async fn trace_call(&self, trace_request: TraceRequest) -> RpcResult<TraceResults>;
async fn trace_call(
&self,
call: CallRequest,
trace_types: HashSet<TraceType>,
block_id: Option<BlockId>,
state_overrides: Option<StateOverride>,
block_overrides: Option<Box<BlockOverrides>>,
) -> RpcResult<TraceResults>;

/// Performs multiple call traces on top of the same block. i.e. transaction n will be executed
/// on top of a pending block with all n-1 transactions applied (traced) first. Allows to trace
Expand Down
8 changes: 4 additions & 4 deletions crates/rpc/rpc-types/src/eth/trace/tracerequest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use crate::{
use serde::{Deserialize, Serialize};
use std::collections::HashSet;

/// Trace Request builder style function implementation
/// Container type for `trace_call` arguments
#[derive(Debug, Serialize, Deserialize)]
pub struct TraceRequest {
pub struct TraceCallRequest {
/// call request object
pub call: CallRequest,
/// trace types
Expand All @@ -22,8 +22,8 @@ pub struct TraceRequest {
pub block_overrides: Option<Box<BlockOverrides>>,
}

impl TraceRequest {
/// Returns a new [`TraceRequest`] given a [`CallRequest`] and [`HashSet<TraceType>`]
impl TraceCallRequest {
/// Returns a new [`TraceCallRequest`] given a [`CallRequest`] and [`HashSet<TraceType>`]
pub fn new(call: CallRequest) -> Self {
Self {
call,
Expand Down
24 changes: 16 additions & 8 deletions crates/rpc/rpc/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ use reth_revm::{
};
use reth_rpc_api::TraceApiServer;
use reth_rpc_types::{
trace::{filter::TraceFilter, parity::*, tracerequest::TraceRequest},
BlockError, CallRequest, Index,
state::StateOverride,
trace::{filter::TraceFilter, parity::*, tracerequest::TraceCallRequest},
BlockError, BlockOverrides, CallRequest, Index,
};
use revm::{db::CacheDB, primitives::Env};
use revm_primitives::db::DatabaseCommit;
Expand Down Expand Up @@ -65,10 +66,8 @@ where
Eth: EthTransactions + 'static,
{
/// Executes the given call and returns a number of possible traces for it.
pub async fn trace_call(&self, trace_request: TraceRequest) -> EthResult<TraceResults> {
let at = trace_request
.block_id
.unwrap_or(reth_rpc_types::BlockId::Number(reth_rpc_types::BlockNumberOrTag::Latest));
pub async fn trace_call(&self, trace_request: TraceCallRequest) -> EthResult<TraceResults> {
let at = trace_request.block_id.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest));
let config = tracing_config(&trace_request.trace_types);
let overrides =
EvmOverrides::new(trace_request.state_overrides, trace_request.block_overrides);
Expand Down Expand Up @@ -435,9 +434,18 @@ where
/// Executes the given call and returns a number of possible traces for it.
///
/// Handler for `trace_call`
async fn trace_call(&self, trace_request: TraceRequest) -> Result<TraceResults> {
async fn trace_call(
&self,
call: CallRequest,
trace_types: HashSet<TraceType>,
block_id: Option<BlockId>,
state_overrides: Option<StateOverride>,
block_overrides: Option<Box<BlockOverrides>>,
) -> Result<TraceResults> {
let _permit = self.acquire_trace_permit().await;
Ok(TraceApi::trace_call(self, trace_request).await?)
let request =
TraceCallRequest { call, trace_types, block_id, state_overrides, block_overrides };
Ok(TraceApi::trace_call(self, request).await?)
}

/// Handler for `trace_callMany`
Expand Down
4 changes: 2 additions & 2 deletions examples/trace-transaction-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use reth::{
primitives::{Address, IntoRecoveredTransaction},
rpc::{
compat::transaction::transaction_to_call_request,
types::trace::{parity::TraceType, tracerequest::TraceRequest},
types::trace::{parity::TraceType, tracerequest::TraceCallRequest},
},
tasks::TaskSpawner,
transaction_pool::TransactionPool,
Expand Down Expand Up @@ -80,7 +80,7 @@ impl RethNodeCommandConfig for RethCliTxpoolExt {
let callrequest =
transaction_to_call_request(tx.to_recovered_transaction());
let tracerequest =
TraceRequest::new(callrequest).with_trace_type(TraceType::Trace);
TraceCallRequest::new(callrequest).with_trace_type(TraceType::Trace);
if let Ok(trace_result) = traceapi.trace_call(tracerequest).await {
println!(
"trace result for transaction : {:?} is {:?}",
Expand Down

0 comments on commit de01f08

Please sign in to comment.