@@ -72,11 +72,9 @@ pub(crate) fn execute_fee_transfer<S: StateReader>(
72
72
call_info. ok_or ( TransactionError :: CallInfoIsNone )
73
73
}
74
74
75
- // ----------------------------------------------------------------------------------------
76
75
/// Calculates the fee of a transaction given its execution resources.
77
76
/// We add the l1_gas_usage (which may include, for example, the direct cost of L2-to-L1
78
77
/// messages) to the gas consumed by Cairo resource and multiply by the L1 gas price.
79
-
80
78
pub fn calculate_tx_fee (
81
79
resources : & HashMap < String , usize > ,
82
80
gas_price : u128 ,
@@ -93,11 +91,9 @@ pub fn calculate_tx_fee(
93
91
Ok ( total_l1_gas_usage. ceil ( ) as u128 * gas_price)
94
92
}
95
93
96
- // ----------------------------------------------------------------------------------------
97
94
/// Calculates the L1 gas consumed when submitting the underlying Cairo program to SHARP.
98
95
/// I.e., returns the heaviest Cairo resource weight (in terms of L1 gas), as the size of
99
96
/// a proof is determined similarly - by the (normalized) largest segment.
100
-
101
97
pub ( crate ) fn calculate_l1_gas_by_cairo_usage (
102
98
block_context : & BlockContext ,
103
99
cairo_resource_usage : & HashMap < String , usize > ,
@@ -116,6 +112,7 @@ pub(crate) fn calculate_l1_gas_by_cairo_usage(
116
112
) )
117
113
}
118
114
115
+ /// Calculates the maximum weighted value from a given resource usage mapping.
119
116
fn max_of_keys ( cairo_rsc : & HashMap < String , usize > , weights : & HashMap < String , f64 > ) -> f64 {
120
117
let mut max = 0.0_f64 ;
121
118
for ( k, v) in weights {
@@ -135,6 +132,11 @@ fn max_of_keys(cairo_rsc: &HashMap<String, usize>, weights: &HashMap<String, f64
135
132
/// - `tx_execution_context`: The transaction's execution context.
136
133
/// - `skip_fee_transfer`: Whether to skip the fee transfer.
137
134
///
135
+ /// # Errors
136
+ /// - [TransactionError::ActualFeeExceedsMaxFee] - If the actual fee is bigger than the maximal fee.
137
+ ///
138
+ /// # Returns
139
+ /// The [FeeInfo] with the given actual fee.
138
140
pub fn charge_fee < S : StateReader > (
139
141
state : & mut CachedState < S > ,
140
142
resources : & HashMap < String , usize > ,
@@ -195,6 +197,8 @@ mod tests {
195
197
transaction:: fee:: charge_fee,
196
198
} ;
197
199
200
+ /// Tests the behavior of the charge_fee function when the actual fee exceeds the maximum fee
201
+ /// for version 0. It expects to return an ActualFeeExceedsMaxFee error.
198
202
#[ test]
199
203
fn charge_fee_v0_max_fee_exceeded_should_charge_nothing ( ) {
200
204
let mut state = CachedState :: new (
@@ -224,6 +228,8 @@ mod tests {
224
228
assert_eq ! ( result. 1 , 0 ) ;
225
229
}
226
230
231
+ /// Tests the behavior of the charge_fee function when the actual fee exceeds the maximum fee
232
+ /// for version 1. It expects the function to return the maximum fee.
227
233
#[ test]
228
234
fn charge_fee_v1_max_fee_exceeded_should_charge_max_fee ( ) {
229
235
let mut state = CachedState :: new (
0 commit comments