From 8e23dfffab58008b5c7714e59f1c4b4204057cf3 Mon Sep 17 00:00:00 2001 From: Nimrod Weiss Date: Wed, 14 Aug 2024 14:25:00 +0300 Subject: [PATCH] build(fee): tx_resources depend on resource bounds signature --- crates/blockifier/src/fee/actual_cost.rs | 1 + crates/blockifier/src/test_utils/struct_impls.rs | 1 + .../src/transaction/account_transactions_test.rs | 12 ++++++++++-- .../src/transaction/execution_flavors_test.rs | 6 +++++- crates/blockifier/src/transaction/objects.rs | 10 +++++++++- .../src/transaction/post_execution_test.rs | 6 +++++- .../src/transaction/transactions_test.rs | 16 ++++++++++++---- 7 files changed, 43 insertions(+), 9 deletions(-) diff --git a/crates/blockifier/src/fee/actual_cost.rs b/crates/blockifier/src/fee/actual_cost.rs index 36967058b8..3e3806a0f3 100644 --- a/crates/blockifier/src/fee/actual_cost.rs +++ b/crates/blockifier/src/fee/actual_cost.rs @@ -88,6 +88,7 @@ impl TransactionReceipt { let gas = tx_resources.to_gas_vector( &tx_context.block_context.versioned_constants, tx_context.block_context.block_info.use_kzg_da, + tx_context.tx_info.has_l2_gas_bounds(), )?; // L1 handler transactions are not charged an L2 fee but it is compared to the L1 fee. diff --git a/crates/blockifier/src/test_utils/struct_impls.rs b/crates/blockifier/src/test_utils/struct_impls.rs index 664041671c..481220fa14 100644 --- a/crates/blockifier/src/test_utils/struct_impls.rs +++ b/crates/blockifier/src/test_utils/struct_impls.rs @@ -120,6 +120,7 @@ impl TransactionResources { let gas_vector = self.to_gas_vector( &block_context.versioned_constants, block_context.block_info.use_kzg_da, + false, )?; Ok(get_fee_by_gas_vector(&block_context.block_info, gas_vector, fee_type)) } diff --git a/crates/blockifier/src/transaction/account_transactions_test.rs b/crates/blockifier/src/transaction/account_transactions_test.rs index 3f48297d15..eb282f4f0a 100644 --- a/crates/blockifier/src/transaction/account_transactions_test.rs +++ b/crates/blockifier/src/transaction/account_transactions_test.rs @@ -937,7 +937,11 @@ fn test_max_fee_to_max_steps_conversion( let gas_used_vector1 = tx_execution_info1 .receipt .resources - .to_gas_vector(&block_context.versioned_constants, block_context.block_info.use_kzg_da) + .to_gas_vector( + &block_context.versioned_constants, + block_context.block_info.use_kzg_da, + false, + ) .unwrap(); // Second invocation of `with_arg` gets twice the pre-calculated actual fee as max_fee. @@ -957,7 +961,11 @@ fn test_max_fee_to_max_steps_conversion( let gas_used_vector2 = tx_execution_info2 .receipt .resources - .to_gas_vector(&block_context.versioned_constants, block_context.block_info.use_kzg_da) + .to_gas_vector( + &block_context.versioned_constants, + block_context.block_info.use_kzg_da, + false, + ) .unwrap(); // Test that steps limit doubles as max_fee doubles, but actual consumed steps and fee remains. diff --git a/crates/blockifier/src/transaction/execution_flavors_test.rs b/crates/blockifier/src/transaction/execution_flavors_test.rs index a7537b49fe..8dfecbbbe7 100644 --- a/crates/blockifier/src/transaction/execution_flavors_test.rs +++ b/crates/blockifier/src/transaction/execution_flavors_test.rs @@ -129,7 +129,11 @@ fn check_gas_and_fee( tx_execution_info .receipt .resources - .to_gas_vector(&block_context.versioned_constants, block_context.block_info.use_kzg_da) + .to_gas_vector( + &block_context.versioned_constants, + block_context.block_info.use_kzg_da, + false + ) .unwrap() .l1_gas, expected_actual_gas.into() diff --git a/crates/blockifier/src/transaction/objects.rs b/crates/blockifier/src/transaction/objects.rs index a10c98137e..8d80da2177 100644 --- a/crates/blockifier/src/transaction/objects.rs +++ b/crates/blockifier/src/transaction/objects.rs @@ -110,6 +110,13 @@ impl TransactionInfo { TransactionInfo::Deprecated(context) => Ok(context.max_fee != Fee(0)), } } + + pub fn has_l2_gas_bounds(&self) -> bool { + match self { + TransactionInfo::Current(context) => context.resource_bounds.0.len() == 3, + TransactionInfo::Deprecated(_) => false, + } + } } impl HasRelatedFeeType for TransactionInfo { @@ -470,8 +477,9 @@ impl TransactionResources { &self, versioned_constants: &VersionedConstants, use_kzg_da: bool, + include_l2_gas: bool, ) -> TransactionFeeResult { - Ok(self.starknet_resources.to_gas_vector(versioned_constants, use_kzg_da, false) + Ok(self.starknet_resources.to_gas_vector(versioned_constants, use_kzg_da, include_l2_gas) + calculate_l1_gas_by_vm_usage( versioned_constants, &self.vm_resources, diff --git a/crates/blockifier/src/transaction/post_execution_test.rs b/crates/blockifier/src/transaction/post_execution_test.rs index 08d00350aa..8922f16b3e 100644 --- a/crates/blockifier/src/transaction/post_execution_test.rs +++ b/crates/blockifier/src/transaction/post_execution_test.rs @@ -256,7 +256,11 @@ fn test_revert_on_resource_overuse( let actual_gas_usage: u64 = execution_info_measure .receipt .resources - .to_gas_vector(&block_context.versioned_constants, block_context.block_info.use_kzg_da) + .to_gas_vector( + &block_context.versioned_constants, + block_context.block_info.use_kzg_da, + false, + ) .unwrap() .l1_gas .try_into() diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index ffd28965a4..34a6946fec 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -507,7 +507,11 @@ fn test_invoke_tx( ); let total_gas = expected_actual_resources - .to_gas_vector(&block_context.versioned_constants, block_context.block_info.use_kzg_da) + .to_gas_vector( + &block_context.versioned_constants, + block_context.block_info.use_kzg_da, + false, + ) .unwrap(); let expected_execution_info = TransactionExecutionInfo { @@ -1224,7 +1228,7 @@ fn test_declare_tx( ); let expected_total_gas = - expected_actual_resources.to_gas_vector(versioned_constants, use_kzg_da).unwrap(); + expected_actual_resources.to_gas_vector(versioned_constants, use_kzg_da, false).unwrap(); let expected_execution_info = TransactionExecutionInfo { validate_call_info: expected_validate_call_info, @@ -1392,7 +1396,11 @@ fn test_deploy_account_tx( ); let expected_total_gas = actual_resources - .to_gas_vector(&block_context.versioned_constants, block_context.block_info.use_kzg_da) + .to_gas_vector( + &block_context.versioned_constants, + block_context.block_info.use_kzg_da, + false, + ) .unwrap(); let expected_execution_info = TransactionExecutionInfo { @@ -1907,7 +1915,7 @@ fn test_l1_handler(#[values(false, true)] use_kzg_da: bool) { ); let total_gas = expected_tx_resources - .to_gas_vector(versioned_constants, block_context.block_info.use_kzg_da) + .to_gas_vector(versioned_constants, block_context.block_info.use_kzg_da, false) .unwrap(); // Build the expected execution info.