Skip to content

Commit 13c0618

Browse files
Add and implement trace_block at EvmDebugApi
1 parent 23024ae commit 13c0618

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

crates/evm-debug-api/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@ use sp_core::{sp_std::vec::Vec, H160, H256, U256};
77
sp_api::decl_runtime_apis! {
88
/// Runtime API for the EVM debug logic.
99
pub trait EvmDebugApi {
10+
/// Trace block.
11+
fn trace_block(
12+
extrinsics: Vec<Block::Extrinsic>,
13+
known_transactions: Vec<H256>,
14+
header: &Block::Header,
15+
) -> Result<(), sp_runtime::DispatchError>;
16+
1017
// Allow too many arguments to pass them in the way used at EVM runner call.
1118
#[allow(clippy::too_many_arguments)]
12-
/// Trace EVM call execution.
19+
/// Trace call execution.
1320
fn trace_call(
1421
header: &Block::Header,
1522
from: H160,

crates/humanode-runtime/src/lib.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,58 @@ impl_runtime_apis! {
15061506

15071507
#[cfg(feature = "evm-tracing")]
15081508
impl evm_debug_api::EvmDebugApi<Block> for Runtime {
1509+
fn trace_block(
1510+
extrinsics: Vec<<Block as BlockT>::Extrinsic>,
1511+
known_transactions: Vec<H256>,
1512+
header: &<Block as BlockT>::Header,
1513+
) -> Result<(), sp_runtime::DispatchError> {
1514+
Executive::initialize_block(header);
1515+
1516+
let mut config = <Runtime as pallet_evm::Config>::config().clone();
1517+
config.estimate = true;
1518+
1519+
// Apply all extrinsics. Ethereum extrinsics are traced.
1520+
for ext in extrinsics {
1521+
match &ext.0.function {
1522+
RuntimeCall::Ethereum(transact { transaction }) => {
1523+
let tx_hash = &transaction.hash();
1524+
if known_transactions.contains(tx_hash) {
1525+
// Each known extrinsic is a new call stack.
1526+
evm_tracer::EvmTracer::emit_new();
1527+
evm_tracer::EvmTracer::new().trace(|| {
1528+
if let Err(err) = Executive::apply_extrinsic(ext) {
1529+
frame_support::log::debug!(
1530+
target: "tracing",
1531+
"Could not trace eth transaction (hash: {}): {:?}",
1532+
&tx_hash,
1533+
err
1534+
);
1535+
}
1536+
});
1537+
} else if let Err(err) = Executive::apply_extrinsic(ext) {
1538+
frame_support::log::debug!(
1539+
target: "tracing",
1540+
"Failed to apply eth extrinsic (hash: {}): {:?}",
1541+
&tx_hash,
1542+
err
1543+
);
1544+
}
1545+
},
1546+
_ => {
1547+
if let Err(err) = Executive::apply_extrinsic(ext) {
1548+
frame_support::log::debug!(
1549+
target: "tracing",
1550+
"Failed to apply non-eth extrinsic: {:?}",
1551+
err
1552+
);
1553+
}
1554+
}
1555+
}
1556+
}
1557+
1558+
Ok(())
1559+
}
1560+
15091561
fn trace_call(
15101562
header: &<Block as BlockT>::Header,
15111563
from: H160,

0 commit comments

Comments
 (0)