From 8a1bdd42bff1103672d0a0c44f390b41dc6c3d68 Mon Sep 17 00:00:00 2001 From: Aviv Greenburg Date: Sun, 15 Sep 2024 16:11:44 +0300 Subject: [PATCH] refactor(blockifier): remove enforce fee from actual fee --- crates/blockifier/src/concurrency/fee_utils.rs | 8 +++----- crates/blockifier/src/fee/receipt.rs | 10 +++++----- .../transaction/account_transactions_test.rs | 5 +++-- .../src/transaction/transactions_test.rs | 18 +++++++++++------- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/crates/blockifier/src/concurrency/fee_utils.rs b/crates/blockifier/src/concurrency/fee_utils.rs index e40f492319..f31d134708 100644 --- a/crates/blockifier/src/concurrency/fee_utils.rs +++ b/crates/blockifier/src/concurrency/fee_utils.rs @@ -56,11 +56,9 @@ pub fn complete_fee_transfer_flow( sequencer_balance, ); } else { - assert_eq!( - tx_execution_info.receipt.fee, - Fee(0), - "Transaction with no fee transfer info must have zero fee." - ) + // Assumes we set the charge fee flag to the transaction enforce fee value. + let charge_fee = tx_context.tx_info.enforce_fee(); + assert!(!charge_fee, "Transaction with no fee transfer info must not enforce a fee charge.") } } diff --git a/crates/blockifier/src/fee/receipt.rs b/crates/blockifier/src/fee/receipt.rs index 28e630b73f..5720417d50 100644 --- a/crates/blockifier/src/fee/receipt.rs +++ b/crates/blockifier/src/fee/receipt.rs @@ -93,13 +93,13 @@ impl TransactionReceipt { tx_context.block_context.block_info.use_kzg_da, &tx_context.get_gas_vector_computation_mode(), ); - - // L1 handler transactions are not charged an L2 fee but it is compared to the L1 fee. - let fee = if tx_context.tx_info.enforce_fee() || tx_type == TransactionType::L1Handler { - tx_context.tx_info.get_fee_by_gas_vector(&tx_context.block_context.block_info, gas) - } else { + // Backward-compatibility. + let fee = if tx_type == TransactionType::Declare && tx_context.tx_info.is_v0() { Fee(0) + } else { + tx_context.tx_info.get_fee_by_gas_vector(&tx_context.block_context.block_info, gas) }; + let da_gas = tx_resources .starknet_resources .state diff --git a/crates/blockifier/src/transaction/account_transactions_test.rs b/crates/blockifier/src/transaction/account_transactions_test.rs index a47d31dcdb..b9ab6a0980 100644 --- a/crates/blockifier/src/transaction/account_transactions_test.rs +++ b/crates/blockifier/src/transaction/account_transactions_test.rs @@ -81,6 +81,7 @@ use crate::transaction::constants::TRANSFER_ENTRY_POINT_NAME; use crate::transaction::objects::{FeeType, HasRelatedFeeType, TransactionInfoCreator}; use crate::transaction::test_utils::{ account_invoke_tx, + all_resource_bounds, block_context, calculate_class_info_for_testing, create_account_tx_for_validate_test_nonce_0, @@ -636,7 +637,7 @@ fn test_recursion_depth_exceeded( fn test_revert_invoke( block_context: BlockContext, max_fee: Fee, - default_all_resource_bounds: ValidResourceBounds, + all_resource_bounds: ValidResourceBounds, #[case] transaction_version: TransactionVersion, #[case] fee_type: FeeType, ) { @@ -655,7 +656,7 @@ fn test_revert_invoke( &block_context, invoke_tx_args! { max_fee, - resource_bounds: default_all_resource_bounds, + resource_bounds: all_resource_bounds, sender_address: account_address, calldata: create_calldata( test_contract_address, diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index e00a8ad3b0..98d5faf34b 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -1383,7 +1383,6 @@ fn test_declare_tx( None, ExecutionSummary::default(), ); - let account_tx = declare_tx( declare_tx_args! { max_fee: MAX_FEE, @@ -1426,12 +1425,17 @@ fn test_declare_tx( // Build expected fee transfer call info. let expected_actual_fee = actual_execution_info.receipt.fee; - let expected_fee_transfer_call_info = expected_fee_transfer_call_info( - tx_context, - sender_address, - expected_actual_fee, - FeatureContract::ERC20(CairoVersion::Cairo0).get_class_hash(), - ); + // V0 transactions do not handle fee. + let expected_fee_transfer_call_info = if tx_version == TransactionVersion::ZERO { + None + } else { + expected_fee_transfer_call_info( + tx_context, + sender_address, + expected_actual_fee, + FeatureContract::ERC20(CairoVersion::Cairo0).get_class_hash(), + ) + }; let da_gas = starknet_resources.state.to_gas_vector(use_kzg_da); let expected_cairo_resources = get_expected_cairo_resources(