Skip to content

Commit 13df658

Browse files
committed
some docs
1 parent b4da5a4 commit 13df658

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

crates/evm/traces/src/folded_stack_trace.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ impl EvmFoldedStackTraceBuilder {
2424
self.fst.build()
2525
}
2626

27-
/// Creates an entry for a EVM CALL in the folded stack trace.
27+
/// Creates an entry for a EVM CALL in the folded stack trace. This method recursively processes
28+
/// all the children nodes of the call node and at the end it exits.
2829
pub fn process_call_node(&mut self, nodes: &[CallTraceNode], idx: usize) {
2930
let node = &nodes[idx];
3031

31-
let label = if node.trace.kind.is_any_create() {
32+
let func_name = if node.trace.kind.is_any_create() {
3233
let default_contract_name = "Contract".to_string();
3334
let contract_name = node.trace.decoded.label.as_ref().unwrap_or(&default_contract_name);
3435
format!("new {contract_name}")
@@ -47,9 +48,9 @@ impl EvmFoldedStackTraceBuilder {
4748
}
4849
};
4950

50-
self.fst.enter(label, node.trace.gas_used as i64);
51+
self.fst.enter(func_name, node.trace.gas_used as i64);
5152

52-
// Track step exits to do in this call context
53+
// Track internal function step exits to do in this call context.
5354
let mut step_exits = vec![];
5455

5556
// Process children nodes.
@@ -76,7 +77,9 @@ impl EvmFoldedStackTraceBuilder {
7677
self.fst.exit();
7778
}
7879

79-
/// Creates an entry for an internal function call in the folded stack trace.
80+
/// Creates an entry for an internal function call in the folded stack trace. This method only
81+
/// enters the function in the folded stack trace, we cannot exit since we need to exit at a
82+
/// future step. Hence, we keep track of the step end index in the `step_exits`.
8083
fn process_step(
8184
&mut self,
8285
steps: &[CallTraceStep],
@@ -111,9 +114,9 @@ impl EvmFoldedStackTraceBuilder {
111114
/// Helps to translate a function enter-exit flow into a folded stack trace.
112115
///
113116
/// Example:
114-
/// fn top() { child_a(); child_b() } // consumes 500 cpu cycles
115-
/// fn child_a() {} // consumes 100 cpu cycles
116-
/// fn child_b() {} // consumes 200 cpu cycles
117+
/// fn top() { child_a(); child_b() } // consumes 500 gas
118+
/// fn child_a() {} // consumes 100 gas
119+
/// fn child_b() {} // consumes 200 gas
117120
///
118121
/// For execution of the `top` function looks like:
119122
/// 1. enter `top`
@@ -185,7 +188,7 @@ impl FoldedStackTraceBuilder {
185188

186189
/// Subtracts gas consumed by the children function calls from the parent function calls.
187190
fn subtract_children(&mut self) {
188-
// Iterate over each trace to find the children and subtract their values from the parents
191+
// Iterate over each trace to find the children and subtract their values from the parents.
189192
for i in 0..self.traces.len() {
190193
let (left, right) = self.traces.split_at_mut(i);
191194
let TraceEntry { names, gas } = &right[0];

0 commit comments

Comments
 (0)