Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit b825aec

Browse files
authored
Merge branch 'main' into document-syscallsbusiness_logic_syscall_handler-module
2 parents 561c824 + 4539844 commit b825aec

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/transaction/fee.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,9 @@ pub(crate) fn execute_fee_transfer<S: StateReader>(
7272
call_info.ok_or(TransactionError::CallInfoIsNone)
7373
}
7474

75-
// ----------------------------------------------------------------------------------------
7675
/// Calculates the fee of a transaction given its execution resources.
7776
/// We add the l1_gas_usage (which may include, for example, the direct cost of L2-to-L1
7877
/// messages) to the gas consumed by Cairo resource and multiply by the L1 gas price.
79-
8078
pub fn calculate_tx_fee(
8179
resources: &HashMap<String, usize>,
8280
gas_price: u128,
@@ -93,11 +91,9 @@ pub fn calculate_tx_fee(
9391
Ok(total_l1_gas_usage.ceil() as u128 * gas_price)
9492
}
9593

96-
// ----------------------------------------------------------------------------------------
9794
/// Calculates the L1 gas consumed when submitting the underlying Cairo program to SHARP.
9895
/// I.e., returns the heaviest Cairo resource weight (in terms of L1 gas), as the size of
9996
/// a proof is determined similarly - by the (normalized) largest segment.
100-
10197
pub(crate) fn calculate_l1_gas_by_cairo_usage(
10298
block_context: &BlockContext,
10399
cairo_resource_usage: &HashMap<String, usize>,
@@ -116,6 +112,7 @@ pub(crate) fn calculate_l1_gas_by_cairo_usage(
116112
))
117113
}
118114

115+
/// Calculates the maximum weighted value from a given resource usage mapping.
119116
fn max_of_keys(cairo_rsc: &HashMap<String, usize>, weights: &HashMap<String, f64>) -> f64 {
120117
let mut max = 0.0_f64;
121118
for (k, v) in weights {
@@ -135,6 +132,11 @@ fn max_of_keys(cairo_rsc: &HashMap<String, usize>, weights: &HashMap<String, f64
135132
/// - `tx_execution_context`: The transaction's execution context.
136133
/// - `skip_fee_transfer`: Whether to skip the fee transfer.
137134
///
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.
138140
pub fn charge_fee<S: StateReader>(
139141
state: &mut CachedState<S>,
140142
resources: &HashMap<String, usize>,
@@ -195,6 +197,8 @@ mod tests {
195197
transaction::fee::charge_fee,
196198
};
197199

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.
198202
#[test]
199203
fn charge_fee_v0_max_fee_exceeded_should_charge_nothing() {
200204
let mut state = CachedState::new(
@@ -224,6 +228,8 @@ mod tests {
224228
assert_eq!(result.1, 0);
225229
}
226230

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.
227233
#[test]
228234
fn charge_fee_v1_max_fee_exceeded_should_charge_max_fee() {
229235
let mut state = CachedState::new(

0 commit comments

Comments
 (0)