feat(rpc): add overrides to trace call opts (#2115)

This commit is contained in:
Matthias Seitz
2023-04-04 23:10:45 +02:00
committed by GitHub
parent 40b5201bbe
commit 59dabcdac0
4 changed files with 44 additions and 13 deletions

View File

@@ -1,7 +1,10 @@
use jsonrpsee::{core::RpcResult as Result, proc_macros::rpc};
use reth_primitives::{BlockId, BlockNumberOrTag, Bytes, H256};
use reth_rpc_types::{
trace::geth::{BlockTraceResult, GethDebugTracingOptions, GethTraceFrame, TraceResult},
trace::geth::{
BlockTraceResult, GethDebugTracingCallOptions, GethDebugTracingOptions, GethTraceFrame,
TraceResult,
},
CallRequest, RichBlock,
};
@@ -97,6 +100,6 @@ pub trait DebugApi {
&self,
request: CallRequest,
block_number: Option<BlockId>,
opts: GethDebugTracingOptions,
opts: GethDebugTracingCallOptions,
) -> Result<GethTraceFrame>;
}

View File

@@ -2,7 +2,7 @@
use crate::Transaction;
use reth_primitives::{
Address, Block as PrimitiveBlock, Bloom, Bytes, Header as PrimitiveHeader, SealedHeader,
Withdrawal, H256, H64, U256,
Withdrawal, H256, H64, U256, U64,
};
use reth_rlp::Encodable;
use serde::{ser::Error, Deserialize, Serialize, Serializer};
@@ -351,6 +351,27 @@ impl<T: Serialize> Serialize for Rich<T> {
}
}
/// BlockOverrides is a set of header fields to override.
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(default, rename_all = "camelCase", deny_unknown_fields)]
#[allow(missing_docs)]
pub struct BlockOverrides {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub number: Option<U256>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub difficulty: Option<U256>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub time: Option<U64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub gas_limit: Option<U64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub coinbase: Option<Address>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub random: Option<H256>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub base_fee: Option<U256>,
}
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -1,5 +1,6 @@
#![allow(missing_docs)]
use crate::{state::StateOverride, BlockOverrides};
/// Geth tracing types
use reth_primitives::{Bytes, JsonU256, H256, U256};
use serde::{Deserialize, Serialize};
@@ -308,9 +309,6 @@ pub struct GethDefaultTracingOptions {
/// maximum length of output, but zero means unlimited
#[serde(default, skip_serializing_if = "Option::is_none")]
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 overrides: Option<serde_json::Value>,
}
/// Bindings for additional `debug_traceCall` options
@@ -321,5 +319,10 @@ pub struct GethDefaultTracingOptions {
pub struct GethDebugTracingCallOptions {
#[serde(flatten)]
pub tracing_options: GethDebugTracingOptions,
// TODO: Add stateoverrides and blockoverrides options
/// The state overrides to apply
#[serde(default, skip_serializing_if = "Option::is_none")]
pub state_overrides: Option<StateOverride>,
/// The block overrides to apply
#[serde(default, skip_serializing_if = "Option::is_none")]
pub block_overrides: Option<BlockOverrides>,
}

View File

@@ -21,7 +21,8 @@ use reth_rpc_api::DebugApiServer;
use reth_rpc_types::{
trace::geth::{
BlockTraceResult, FourByteFrame, GethDebugBuiltInTracerType, GethDebugTracerType,
GethDebugTracingOptions, GethTraceFrame, NoopFrame, TraceResult,
GethDebugTracingCallOptions, GethDebugTracingOptions, GethTraceFrame, NoopFrame,
TraceResult,
},
BlockError, CallRequest, RichBlock,
};
@@ -141,11 +142,13 @@ where
&self,
call: CallRequest,
block_id: Option<BlockId>,
opts: GethDebugTracingOptions,
opts: GethDebugTracingCallOptions,
) -> EthResult<GethTraceFrame> {
let at = block_id.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest));
let GethDebugTracingOptions { config, .. } = opts;
// TODO(mattsse) apply block overrides
let GethDebugTracingCallOptions { tracing_options, state_overrides, block_overrides: _ } =
opts;
let GethDebugTracingOptions { config, .. } = tracing_options;
// TODO(mattsse) support non default tracers
// default structlog tracer
@@ -153,7 +156,8 @@ where
let mut inspector = TracingInspector::new(inspector_config);
let (res, _) = self.eth_api.inspect_call_at(call, at, None, &mut inspector).await?;
let (res, _) =
self.eth_api.inspect_call_at(call, at, state_overrides, &mut inspector).await?;
let gas_used = res.result.gas_used();
let frame = inspector.into_geth_builder().geth_traces(U256::from(gas_used), config);
@@ -288,7 +292,7 @@ where
&self,
request: CallRequest,
block_number: Option<BlockId>,
opts: GethDebugTracingOptions,
opts: GethDebugTracingCallOptions,
) -> RpcResult<GethTraceFrame> {
Ok(DebugApi::debug_trace_call(self, request, block_number, opts).await?)
}