Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

fix(fee): count events of inner calls in get_tx_events_gas_cost #1744

Merged
merged 1 commit into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions crates/blockifier/src/fee/gas_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ pub fn get_tx_events_gas_cost<'a>(
call_infos: impl Iterator<Item = &'a CallInfo>,
versioned_constants: &VersionedConstants,
) -> GasVector {
let l1_milligas: u128 = call_infos
.map(|call_info| get_events_milligas_cost(&call_info.execution.events, versioned_constants))
.sum();
let mut l1_milligas: u128 = 0;
for main_call_info in call_infos {
for inner_call in main_call_info.into_iter() {
l1_milligas +=
get_events_milligas_cost(&inner_call.execution.events, versioned_constants);
}
}
GasVector { l1_gas: l1_milligas / 1000_u128, l1_data_gas: 0_u128 }
}

Expand Down
10 changes: 6 additions & 4 deletions crates/blockifier/src/fee/gas_usage_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ fn test_get_event_gas_cost(versioned_constants: &VersionedConstants) {
let call_info_1 = &CallInfo::default();
let call_info_2 = &CallInfo::default();
let call_info_3 = &CallInfo::default();
let call_infos = call_info_1.into_iter().chain(call_info_2).chain(call_info_3);
let call_infos =
Some(call_info_1).into_iter().chain(Some(call_info_2)).chain(Some(call_info_3));
assert_eq!(GasVector::default(), get_tx_events_gas_cost(call_infos, versioned_constants));

let create_event = |keys_size: usize, data_size: usize| OrderedEvent {
Expand All @@ -52,15 +53,16 @@ fn test_get_event_gas_cost(versioned_constants: &VersionedConstants) {
let call_info_3 = &CallInfo {
execution: CallExecution { events: vec![create_event(0, 1)], ..Default::default() },
inner_calls: vec![CallInfo {
execution: CallExecution { events: vec![create_event(1, 0)], ..Default::default() },
execution: CallExecution { events: vec![create_event(5, 5)], ..Default::default() },
..Default::default()
}],
..Default::default()
};
let call_infos = call_info_1.into_iter().chain(call_info_2).chain(call_info_3);
let call_infos =
Some(call_info_1).into_iter().chain(Some(call_info_2)).chain(Some(call_info_3));
let expected = GasVector {
// 4 keys and 6 data words overall.
l1_gas: (event_key_factor * data_word_cost * 4_u128 + data_word_cost * 6_u128) / 1000,
l1_gas: (event_key_factor * data_word_cost * 8_u128 + data_word_cost * 11_u128) / 1000,
l1_data_gas: 0_u128,
};
let gas_vector = get_tx_events_gas_cost(call_infos, versioned_constants);
Expand Down
Loading