Skip to content

Commit

Permalink
Add tx_hash for citrea_handler in trace_transaction (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
kpp authored and rakanalh committed Apr 6, 2024
1 parent 6bc98d4 commit 0a7e756
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions crates/evm/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,7 @@ impl<C: sov_modules_api::Context> Evm<C> {
cfg_env.clone(),
block_env.clone().into(),
tx_env_with_recovered(&tx),
tx.hash(),
&mut evm_db,
l1_fee_rate,
)?;
Expand Down
32 changes: 27 additions & 5 deletions crates/evm/src/rpc_helpers/tracing_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub(crate) fn trace_transaction<C: sov_modules_api::Context>(
config_env: CfgEnvWithHandlerCfg,
block_env: BlockEnv,
tx_env: TxEnv,
tx_hash: TxHash,
db: &mut EvmDb<'_, C>,
l1_fee_rate: u64,
) -> EthResult<(GethTrace, revm::primitives::State)> {
Expand All @@ -37,8 +38,14 @@ pub(crate) fn trace_transaction<C: sov_modules_api::Context>(
GethDebugBuiltInTracerType::FourByteTracer => {
let inspector = FourByteInspector::default();
let mut citrea_inspector = TracingCitreaExternal::new(inspector, l1_fee_rate);
let res =
inspect_citrea(db, config_env, block_env, tx_env, &mut citrea_inspector)?;
let res = inspect_citrea(
db,
config_env,
block_env,
tx_env,
tx_hash,
&mut citrea_inspector,
)?;
return Ok((
FourByteFrame::from(citrea_inspector.inspector).into(),
res.state,
Expand All @@ -53,8 +60,14 @@ pub(crate) fn trace_transaction<C: sov_modules_api::Context>(
.set_record_logs(call_config.with_log.unwrap_or_default()),
);
let mut citrea_inspector = TracingCitreaExternal::new(inspector, l1_fee_rate);
let res =
inspect_citrea(db, config_env, block_env, tx_env, &mut citrea_inspector)?;
let res = inspect_citrea(
db,
config_env,
block_env,
tx_env,
tx_hash,
&mut citrea_inspector,
)?;
let frame = citrea_inspector
.inspector
.into_geth_builder()
Expand Down Expand Up @@ -86,7 +99,14 @@ pub(crate) fn trace_transaction<C: sov_modules_api::Context>(
let inspector = TracingInspector::new(inspector_config);
let mut citrea_inspector = TracingCitreaExternal::new(inspector, l1_fee_rate);

let res = inspect_citrea(db, config_env, block_env, tx_env, &mut citrea_inspector)?;
let res = inspect_citrea(
db,
config_env,
block_env,
tx_env,
tx_hash,
&mut citrea_inspector,
)?;
let gas_used = res.result.gas_used();
let return_value = res.result.into_output().unwrap_or_default();
let frame =
Expand All @@ -104,6 +124,7 @@ fn inspect_citrea<DB, I>(
config_env: CfgEnvWithHandlerCfg,
block_env: BlockEnv,
tx_env: TxEnv,
tx_hash: TxHash,
inspector: I,
) -> Result<ResultAndState, EVMError<DB::Error>>
where
Expand All @@ -121,6 +142,7 @@ where
.append_handler_register(citrea_handle_register)
.append_handler_register(inspector_handle_register)
.build();
evm.context.external.set_current_tx_hash(tx_hash);

evm.transact()
}
Expand Down

0 comments on commit 0a7e756

Please sign in to comment.