fix: use correct trace_call params (#5214)

This commit is contained in:
Matthias Seitz
2023-10-28 19:23:15 +02:00
committed by GitHub
parent aa4a39e21f
commit de01f08d90
4 changed files with 33 additions and 17 deletions

View File

@ -1,8 +1,9 @@
use jsonrpsee::{core::RpcResult, proc_macros::rpc}; use jsonrpsee::{core::RpcResult, proc_macros::rpc};
use reth_primitives::{BlockId, Bytes, B256}; use reth_primitives::{BlockId, Bytes, B256};
use reth_rpc_types::{ use reth_rpc_types::{
trace::{filter::TraceFilter, parity::*, tracerequest::TraceRequest}, state::StateOverride,
CallRequest, Index, trace::{filter::TraceFilter, parity::*},
BlockOverrides, CallRequest, Index,
}; };
use std::collections::HashSet; use std::collections::HashSet;
@ -12,7 +13,14 @@ use std::collections::HashSet;
pub trait TraceApi { pub trait TraceApi {
/// Executes the given call and returns a number of possible traces for it. /// Executes the given call and returns a number of possible traces for it.
#[method(name = "call")] #[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 /// 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 /// on top of a pending block with all n-1 transactions applied (traced) first. Allows to trace

View File

@ -7,9 +7,9 @@ use crate::{
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::HashSet; use std::collections::HashSet;
/// Trace Request builder style function implementation /// Container type for `trace_call` arguments
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct TraceRequest { pub struct TraceCallRequest {
/// call request object /// call request object
pub call: CallRequest, pub call: CallRequest,
/// trace types /// trace types
@ -22,8 +22,8 @@ pub struct TraceRequest {
pub block_overrides: Option<Box<BlockOverrides>>, pub block_overrides: Option<Box<BlockOverrides>>,
} }
impl TraceRequest { impl TraceCallRequest {
/// Returns a new [`TraceRequest`] given a [`CallRequest`] and [`HashSet<TraceType>`] /// Returns a new [`TraceCallRequest`] given a [`CallRequest`] and [`HashSet<TraceType>`]
pub fn new(call: CallRequest) -> Self { pub fn new(call: CallRequest) -> Self {
Self { Self {
call, call,

View File

@ -20,8 +20,9 @@ use reth_revm::{
}; };
use reth_rpc_api::TraceApiServer; use reth_rpc_api::TraceApiServer;
use reth_rpc_types::{ use reth_rpc_types::{
trace::{filter::TraceFilter, parity::*, tracerequest::TraceRequest}, state::StateOverride,
BlockError, CallRequest, Index, trace::{filter::TraceFilter, parity::*, tracerequest::TraceCallRequest},
BlockError, BlockOverrides, CallRequest, Index,
}; };
use revm::{db::CacheDB, primitives::Env}; use revm::{db::CacheDB, primitives::Env};
use revm_primitives::db::DatabaseCommit; use revm_primitives::db::DatabaseCommit;
@ -65,10 +66,8 @@ where
Eth: EthTransactions + 'static, Eth: EthTransactions + 'static,
{ {
/// Executes the given call and returns a number of possible traces for it. /// Executes the given call and returns a number of possible traces for it.
pub async fn trace_call(&self, trace_request: TraceRequest) -> EthResult<TraceResults> { pub async fn trace_call(&self, trace_request: TraceCallRequest) -> EthResult<TraceResults> {
let at = trace_request let at = trace_request.block_id.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest));
.block_id
.unwrap_or(reth_rpc_types::BlockId::Number(reth_rpc_types::BlockNumberOrTag::Latest));
let config = tracing_config(&trace_request.trace_types); let config = tracing_config(&trace_request.trace_types);
let overrides = let overrides =
EvmOverrides::new(trace_request.state_overrides, trace_request.block_overrides); EvmOverrides::new(trace_request.state_overrides, trace_request.block_overrides);
@ -435,9 +434,18 @@ where
/// Executes the given call and returns a number of possible traces for it. /// Executes the given call and returns a number of possible traces for it.
/// ///
/// Handler for `trace_call` /// 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; 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` /// Handler for `trace_callMany`

View File

@ -19,7 +19,7 @@ use reth::{
primitives::{Address, IntoRecoveredTransaction}, primitives::{Address, IntoRecoveredTransaction},
rpc::{ rpc::{
compat::transaction::transaction_to_call_request, compat::transaction::transaction_to_call_request,
types::trace::{parity::TraceType, tracerequest::TraceRequest}, types::trace::{parity::TraceType, tracerequest::TraceCallRequest},
}, },
tasks::TaskSpawner, tasks::TaskSpawner,
transaction_pool::TransactionPool, transaction_pool::TransactionPool,
@ -80,7 +80,7 @@ impl RethNodeCommandConfig for RethCliTxpoolExt {
let callrequest = let callrequest =
transaction_to_call_request(tx.to_recovered_transaction()); transaction_to_call_request(tx.to_recovered_transaction());
let tracerequest = 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 { if let Ok(trace_result) = traceapi.trace_call(tracerequest).await {
println!( println!(
"trace result for transaction : {:?} is {:?}", "trace result for transaction : {:?} is {:?}",