feat: add FlatCallTracer (#11114)

This commit is contained in:
krane
2024-09-24 13:55:32 +04:00
committed by GitHub
parent 68d76f6469
commit 33d88a4372
3 changed files with 61 additions and 14 deletions

4
Cargo.lock generated
View File

@ -9104,9 +9104,9 @@ dependencies = [
[[package]]
name = "revm-inspectors"
version = "0.7.4"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48294aab02ed5d1940ad9b06f2a3230c3f0d98db6eacd618878cf143e204f6b0"
checksum = "b57b33a24b5b8b8efa1da3f60d44f02d6e649f06ef925d7780723ff14ff55321"
dependencies = [
"alloy-primitives",
"alloy-rpc-types-eth",

View File

@ -413,7 +413,7 @@ revm = { version = "14.0.2", features = [
"secp256k1",
"blst",
], default-features = false }
revm-inspectors = "0.7"
revm-inspectors = "0.7.6"
revm-primitives = { version = "9.0.2", features = [
"std",
], default-features = false }

View File

@ -1,11 +1,14 @@
use alloy_primitives::{Address, Bytes, B256, U256};
use alloy_rlp::{Decodable, Encodable};
use alloy_rpc_types::{state::EvmOverrides, Block as RpcBlock, BlockError, Bundle, StateContext};
use alloy_rpc_types::{
state::EvmOverrides, Block as RpcBlock, BlockError, Bundle, StateContext, TransactionInfo,
};
use alloy_rpc_types_debug::ExecutionWitness;
use alloy_rpc_types_eth::transaction::TransactionRequest;
use alloy_rpc_types_trace::geth::{
BlockTraceResult, FourByteFrame, GethDebugBuiltInTracerType, GethDebugTracerType,
GethDebugTracingCallOptions, GethDebugTracingOptions, GethTrace, NoopFrame, TraceResult,
call::FlatCallFrame, BlockTraceResult, FourByteFrame, GethDebugBuiltInTracerType,
GethDebugTracerType, GethDebugTracingCallOptions, GethDebugTracingOptions, GethTrace,
NoopFrame, TraceResult,
};
use async_trait::async_trait;
use jsonrpsee::core::RpcResult;
@ -388,9 +391,32 @@ where
return Ok(frame)
}
GethDebugBuiltInTracerType::FlatCallTracer => {
return Err(
EthApiError::Unsupported("Flatcall tracer is not supported yet").into()
)
let flat_call_config = tracer_config
.into_flat_call_config()
.map_err(|_| EthApiError::InvalidTracerConfig)?;
let mut inspector = TracingInspector::new(
TracingInspectorConfig::from_flat_call_config(&flat_call_config),
);
let frame: FlatCallFrame = self
.inner
.eth_api
.spawn_with_call_at(call, at, overrides, move |db, env| {
let (_res, env) =
this.eth_api().inspect(db, env, &mut inspector)?;
let tx_info = TransactionInfo::default();
let frame: FlatCallFrame = inspector
.with_transaction_gas_limit(env.tx.gas_limit)
.into_parity_builder()
.into_localized_transaction_traces(tx_info)
.pop()
.unwrap();
Ok(frame)
})
.await?;
return Ok(frame.into());
}
},
#[cfg(not(feature = "js-tracer"))]
@ -689,8 +715,7 @@ where
opts: GethDebugTracingOptions,
env: EnvWithHandlerCfg,
db: &mut StateCacheDb<'_>,
#[cfg(not(feature = "js-tracer"))] _transaction_context: Option<TransactionContext>,
#[cfg(feature = "js-tracer")] transaction_context: Option<TransactionContext>,
transaction_context: Option<TransactionContext>,
) -> Result<(GethTrace, revm_primitives::EvmState), Eth::Error> {
let GethDebugTracingOptions { config, tracer, tracer_config, .. } = opts;
@ -756,9 +781,31 @@ where
return Ok((frame.into(), res.state))
}
GethDebugBuiltInTracerType::FlatCallTracer => {
return Err(
EthApiError::Unsupported("Flatcall tracer is not supported yet").into()
)
let flat_call_config = tracer_config
.into_flat_call_config()
.map_err(|_| EthApiError::InvalidTracerConfig)?;
let mut inspector = TracingInspector::new(
TracingInspectorConfig::from_flat_call_config(&flat_call_config),
);
let (res, env) = self.eth_api().inspect(db, env, &mut inspector)?;
let tx_info = TransactionInfo {
hash: transaction_context.unwrap().tx_hash,
index: transaction_context.unwrap().tx_index.map(|index| index as u64),
block_hash: transaction_context.unwrap().block_hash,
block_number: Some(env.block.number.try_into().unwrap_or_default()),
base_fee: Some(env.block.basefee.try_into().unwrap_or_default()),
};
let frame: FlatCallFrame = inspector
.with_transaction_gas_limit(env.tx.gas_limit)
.into_parity_builder()
.into_localized_transaction_traces(tx_info)
.pop()
.unwrap();
return Ok((frame.into(), res.state));
}
},
#[cfg(not(feature = "js-tracer"))]