Skip to content

Commit

Permalink
return TraceResult
Browse files Browse the repository at this point in the history
  • Loading branch information
exeokan committed Dec 19, 2024
1 parent d240484 commit ee196ec
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
4 changes: 2 additions & 2 deletions crates/ethereum-rpc/src/ethereum.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::{Arc, Mutex};

use alloy_primitives::U256;
use alloy_rpc_types_trace::geth::GethTrace;
use alloy_rpc_types_trace::geth::TraceResult;
#[cfg(feature = "local")]
use citrea_evm::DevSigner;
use citrea_evm::Evm;
Expand Down Expand Up @@ -40,7 +40,7 @@ pub struct Ethereum<C: sov_modules_api::Context, Da: DaService> {
pub(crate) ledger_db: LedgerDB,
pub(crate) sequencer_client: Option<HttpClient>,
pub(crate) web3_client_version: String,
pub(crate) trace_cache: Mutex<LruMap<u64, Vec<GethTrace>, ByLength>>,
pub(crate) trace_cache: Mutex<LruMap<u64, Vec<TraceResult>, ByLength>>,
pub(crate) subscription_manager: Option<SubscriptionManager>,
}

Expand Down
16 changes: 12 additions & 4 deletions crates/ethereum-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::sync::Arc;
use alloy_network::AnyNetwork;
use alloy_primitives::{keccak256, Bytes, B256, U256};
use alloy_rpc_types::{FeeHistory, Index};
use alloy_rpc_types_trace::geth::{GethDebugTracingOptions, GethTrace};
use alloy_rpc_types_trace::geth::{GethDebugTracingOptions, GethTrace, TraceResult};
#[cfg(feature = "local")]
pub use citrea_evm::DevSigner;
use citrea_evm::{Evm, Filter};
Expand Down Expand Up @@ -394,7 +394,7 @@ fn register_rpc_methods<C: sov_modules_api::Context, Da: DaService>(
// Ok::<_, ErrorObjectOwned>(tx_hash)
// })?;

rpc.register_blocking_method::<Result<Vec<GethTrace>, ErrorObjectOwned>, _>(
rpc.register_blocking_method::<Result<Vec<TraceResult>, ErrorObjectOwned>, _>(
"debug_traceBlockByHash",
move |parameters, ethereum, _| {
let mut params = parameters.sequence();
Expand All @@ -416,7 +416,7 @@ fn register_rpc_methods<C: sov_modules_api::Context, Da: DaService>(
},
)?;

rpc.register_blocking_method::<Result<Vec<GethTrace>, ErrorObjectOwned>, _>(
rpc.register_blocking_method::<Result<Vec<TraceResult>, ErrorObjectOwned>, _>(
"debug_traceBlockByNumber",
move |parameters, ethereum, _| {
let mut params = parameters.sequence();
Expand Down Expand Up @@ -479,7 +479,15 @@ fn register_rpc_methods<C: sov_modules_api::Context, Da: DaService>(
&mut working_set,
opts,
)?;
Ok(traces[0].clone())
match &traces[0] {
TraceResult::Success { result, .. } => {
Ok(result.clone())
}
// this should never happen since we propagate any tracing error
TraceResult::Error { error, tx_hash: _} => {
Err(EthApiError::EvmCustom(error.clone()).into())
}
}
},
)?;

Expand Down
18 changes: 9 additions & 9 deletions crates/ethereum-rpc/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;

use alloy_rpc_types_trace::geth::{
CallConfig, CallFrame, FourByteFrame, GethDebugBuiltInTracerType, GethDebugTracerConfig,
GethDebugTracerType, GethDebugTracingOptions, GethTrace, NoopFrame,
GethDebugTracerType, GethDebugTracingOptions, GethTrace, NoopFrame, TraceResult,
};
#[cfg(feature = "local")]
use citrea_evm::Evm;
Expand Down Expand Up @@ -140,7 +140,7 @@ pub fn debug_trace_by_block_number<C: sov_modules_api::Context, Da: DaService>(
evm: &Evm<C>,
working_set: &mut WorkingSet<C::Storage>,
opts: Option<GethDebugTracingOptions>,
) -> Result<Vec<GethTrace>, ErrorObjectOwned> {
) -> Result<Vec<TraceResult>, ErrorObjectOwned> {
// If opts is None or if opts.tracer is None, then do not check cache or insert cache, just perform the operation
if opts.as_ref().map_or(true, |o| o.tracer.is_none()) {
let traces =
Expand Down Expand Up @@ -209,10 +209,10 @@ fn remove_logs_from_call_frame(call_frame: &mut Vec<CallFrame>) {
}

fn get_traces_with_requested_tracer_and_config(
traces: Vec<GethTrace>,
traces: Vec<TraceResult>,
tracer: GethDebugTracerType,
tracer_config: GethDebugTracerConfig,
) -> Result<Vec<GethTrace>, EthApiError> {
) -> Result<Vec<TraceResult>, EthApiError> {
// This can be only CallConfig or PreStateConfig if it is not CallConfig return Error for now

let mut new_traces = vec![];
Expand All @@ -237,10 +237,10 @@ fn get_traces_with_requested_tracer_and_config(
}
_ => {
traces.into_iter().for_each(|trace| {
if let GethTrace::CallTracer(call_frame) = trace {
if let TraceResult::Success { result: GethTrace::CallTracer(call_frame), tx_hash } = trace {
let new_call_frame =
apply_call_config(call_frame.clone(), call_config);
new_traces.push(GethTrace::CallTracer(new_call_frame));
new_traces.push(TraceResult::new_success(GethTrace::CallTracer(new_call_frame), tx_hash));
}
});
}
Expand All @@ -249,16 +249,16 @@ fn get_traces_with_requested_tracer_and_config(
}
GethDebugBuiltInTracerType::FourByteTracer => {
traces.into_iter().for_each(|trace| {
if let GethTrace::CallTracer(call_frame) = trace {
if let TraceResult::Success { result: GethTrace::CallTracer(call_frame), tx_hash } = trace {
let four_byte_frame =
convert_call_trace_into_4byte_frame(vec![call_frame]);
new_traces.push(GethTrace::FourByteTracer(four_byte_frame));
new_traces.push(TraceResult::new_success(GethTrace::FourByteTracer(four_byte_frame), tx_hash));
}
});
Ok(new_traces)
}
GethDebugBuiltInTracerType::NoopTracer => {
Ok(vec![GethTrace::NoopTracer(NoopFrame::default())])
Ok(vec![TraceResult::new_success(GethTrace::NoopTracer(NoopFrame::default()), None)])
}
_ => Err(EthApiError::Unsupported("This tracer is not supported")),
}
Expand Down
6 changes: 3 additions & 3 deletions crates/evm/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use alloy_rpc_types::{
};
use alloy_rpc_types_eth::transaction::TransactionRequest;
use alloy_rpc_types_eth::Block as AlloyRpcBlock;
use alloy_rpc_types_trace::geth::{GethDebugTracingOptions, GethTrace};
use alloy_rpc_types_trace::geth::{GethDebugTracingOptions, TraceResult};
use alloy_serde::OtherFields;
use citrea_primitives::basefee::calculate_next_block_base_fee;
use citrea_primitives::forks::FORKS;
Expand Down Expand Up @@ -1207,7 +1207,7 @@ impl<C: sov_modules_api::Context> Evm<C> {
opts: Option<GethDebugTracingOptions>,
stop_at: Option<usize>,
working_set: &mut WorkingSet<C::Storage>,
) -> RpcResult<Vec<GethTrace>> {
) -> RpcResult<Vec<TraceResult>> {
let sealed_block = self
.get_sealed_block_by_number(Some(BlockNumberOrTag::Number(block_number)), working_set)?
.ok_or_else(|| EthApiError::HeaderNotFound(block_number.into()))?;
Expand Down Expand Up @@ -1260,7 +1260,7 @@ impl<C: sov_modules_api::Context> Evm<C> {
&mut evm_db,
l1_fee_rate,
)?;
traces.push(trace);
traces.push(TraceResult::new_success(trace, Some(tx.hash())));

if limit == index {
break;
Expand Down

0 comments on commit ee196ec

Please sign in to comment.