@@ -24,11 +24,12 @@ impl EvmFoldedStackTraceBuilder {
24
24
self . fst . build ( )
25
25
}
26
26
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.
28
29
pub fn process_call_node ( & mut self , nodes : & [ CallTraceNode ] , idx : usize ) {
29
30
let node = & nodes[ idx] ;
30
31
31
- let label = if node. trace . kind . is_any_create ( ) {
32
+ let func_name = if node. trace . kind . is_any_create ( ) {
32
33
let default_contract_name = "Contract" . to_string ( ) ;
33
34
let contract_name = node. trace . decoded . label . as_ref ( ) . unwrap_or ( & default_contract_name) ;
34
35
format ! ( "new {contract_name}" )
@@ -47,9 +48,9 @@ impl EvmFoldedStackTraceBuilder {
47
48
}
48
49
} ;
49
50
50
- self . fst . enter ( label , node. trace . gas_used as i64 ) ;
51
+ self . fst . enter ( func_name , node. trace . gas_used as i64 ) ;
51
52
52
- // Track step exits to do in this call context
53
+ // Track internal function step exits to do in this call context.
53
54
let mut step_exits = vec ! [ ] ;
54
55
55
56
// Process children nodes.
@@ -76,7 +77,9 @@ impl EvmFoldedStackTraceBuilder {
76
77
self . fst . exit ( ) ;
77
78
}
78
79
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`.
80
83
fn process_step (
81
84
& mut self ,
82
85
steps : & [ CallTraceStep ] ,
@@ -111,9 +114,9 @@ impl EvmFoldedStackTraceBuilder {
111
114
/// Helps to translate a function enter-exit flow into a folded stack trace.
112
115
///
113
116
/// 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
117
120
///
118
121
/// For execution of the `top` function looks like:
119
122
/// 1. enter `top`
@@ -185,7 +188,7 @@ impl FoldedStackTraceBuilder {
185
188
186
189
/// Subtracts gas consumed by the children function calls from the parent function calls.
187
190
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.
189
192
for i in 0 ..self . traces . len ( ) {
190
193
let ( left, right) = self . traces . split_at_mut ( i) ;
191
194
let TraceEntry { names, gas } = & right[ 0 ] ;
0 commit comments