From 51e436ac720cab4ee3ac3602a138f20a4869b0f7 Mon Sep 17 00:00:00 2001 From: Yonatan Iluz Date: Tue, 6 Aug 2024 12:23:59 +0300 Subject: [PATCH] refactor(blockifier): rename transaction_receipt to receipt --- .../src/blockifier/transaction_executor.rs | 2 +- .../blockifier/src/concurrency/fee_utils.rs | 4 +- .../src/concurrency/worker_logic.rs | 2 +- .../src/concurrency/worker_logic_test.rs | 4 +- crates/blockifier/src/fee/actual_cost_test.rs | 4 +- crates/blockifier/src/state/cached_state.rs | 2 +- .../src/transaction/account_transaction.rs | 2 +- .../transaction/account_transactions_test.rs | 73 +++++++++---------- .../src/transaction/execution_flavors_test.rs | 14 ++-- crates/blockifier/src/transaction/objects.rs | 2 +- .../src/transaction/post_execution_test.rs | 15 ++-- .../src/transaction/transaction_execution.rs | 4 +- .../src/transaction/transactions_test.rs | 50 +++++-------- .../src/py_block_executor.rs | 8 +- crates/papyrus_execution/src/objects.rs | 52 ++++++------- 15 files changed, 103 insertions(+), 135 deletions(-) diff --git a/crates/blockifier/src/blockifier/transaction_executor.rs b/crates/blockifier/src/blockifier/transaction_executor.rs index 2d7bfa857d..14c13ed932 100644 --- a/crates/blockifier/src/blockifier/transaction_executor.rs +++ b/crates/blockifier/src/blockifier/transaction_executor.rs @@ -103,7 +103,7 @@ impl TransactionExecutor { &transactional_state, &tx_state_changes_keys, &tx_execution_info.summarize(), - &tx_execution_info.transaction_receipt.resources, + &tx_execution_info.receipt.resources, )?; transactional_state.commit(); Ok(tx_execution_info) diff --git a/crates/blockifier/src/concurrency/fee_utils.rs b/crates/blockifier/src/concurrency/fee_utils.rs index b9ad04942e..e40f492319 100644 --- a/crates/blockifier/src/concurrency/fee_utils.rs +++ b/crates/blockifier/src/concurrency/fee_utils.rs @@ -51,13 +51,13 @@ pub fn complete_fee_transfer_flow( add_fee_to_sequencer_balance( tx_context.fee_token_address(), state, - tx_execution_info.transaction_receipt.fee, + tx_execution_info.receipt.fee, &tx_context.block_context, sequencer_balance, ); } else { assert_eq!( - tx_execution_info.transaction_receipt.fee, + tx_execution_info.receipt.fee, Fee(0), "Transaction with no fee transfer info must have zero fee." ) diff --git a/crates/blockifier/src/concurrency/worker_logic.rs b/crates/blockifier/src/concurrency/worker_logic.rs index 2a52138efc..3029236f6f 100644 --- a/crates/blockifier/src/concurrency/worker_logic.rs +++ b/crates/blockifier/src/concurrency/worker_logic.rs @@ -243,7 +243,7 @@ impl<'a, S: StateReader> WorkerExecutor<'a, S> { &tx_versioned_state, &tx_state_changes_keys, &tx_execution_info.summarize(), - &tx_execution_info.transaction_receipt.resources, + &tx_execution_info.receipt.resources, ); if let Err(error) = bouncer_result { match error { diff --git a/crates/blockifier/src/concurrency/worker_logic_test.rs b/crates/blockifier/src/concurrency/worker_logic_test.rs index 0962f914ee..ec6b8a6575 100644 --- a/crates/blockifier/src/concurrency/worker_logic_test.rs +++ b/crates/blockifier/src/concurrency/worker_logic_test.rs @@ -155,7 +155,7 @@ pub fn test_commit_tx() { let actual_fee = if should_fail_execution { 0 } else { - execution_result.as_ref().unwrap().transaction_receipt.fee.0 + execution_result.as_ref().unwrap().receipt.fee.0 }; if !should_fail_execution { assert!(!execution_result.as_ref().unwrap().is_reverted()); @@ -344,7 +344,7 @@ fn test_worker_execute(max_resource_bounds: ResourceBoundsMapping) { let execution_output = worker_executor.execution_outputs[tx_index].lock().unwrap(); let execution_output = execution_output.as_ref().unwrap(); let result = execution_output.result.as_ref().unwrap(); - let account_balance = BALANCE - result.transaction_receipt.fee.0; + let account_balance = BALANCE - result.receipt.fee.0; assert!(!result.is_reverted()); let erc20 = FeatureContract::ERC20(CairoVersion::Cairo0); diff --git a/crates/blockifier/src/fee/actual_cost_test.rs b/crates/blockifier/src/fee/actual_cost_test.rs index e9dcbd19b7..99c1b4d34c 100644 --- a/crates/blockifier/src/fee/actual_cost_test.rs +++ b/crates/blockifier/src/fee/actual_cost_test.rs @@ -327,7 +327,7 @@ fn test_calculate_tx_gas_usage( assert_eq!( starknet_resources.to_gas_vector(versioned_constants, use_kzg_da), tx_execution_info - .transaction_receipt + .receipt .resources .starknet_resources .to_gas_vector(versioned_constants, use_kzg_da) @@ -378,7 +378,7 @@ fn test_calculate_tx_gas_usage( assert_eq!( starknet_resources.to_gas_vector(versioned_constants, use_kzg_da), tx_execution_info - .transaction_receipt + .receipt .resources .starknet_resources .to_gas_vector(versioned_constants, use_kzg_da) diff --git a/crates/blockifier/src/state/cached_state.rs b/crates/blockifier/src/state/cached_state.rs index 2109b7e43c..93201f3456 100644 --- a/crates/blockifier/src/state/cached_state.rs +++ b/crates/blockifier/src/state/cached_state.rs @@ -616,7 +616,7 @@ impl StateChangesKeys { tx_result: &TransactionExecutionInfo, concurrency_mode: bool, ) { - let actual_fee = tx_result.transaction_receipt.fee.0; + let actual_fee = tx_result.receipt.fee.0; let sequencer_address = tx_context.block_context.block_info.sequencer_address; if concurrency_mode && !tx_context.is_sequencer_the_sender() && actual_fee > 0 { // Add the deleted sequencer balance key to the storage keys. diff --git a/crates/blockifier/src/transaction/account_transaction.rs b/crates/blockifier/src/transaction/account_transaction.rs index 40be142f57..857b4b1ea5 100644 --- a/crates/blockifier/src/transaction/account_transaction.rs +++ b/crates/blockifier/src/transaction/account_transaction.rs @@ -690,7 +690,7 @@ impl ExecutableTransaction for AccountTransaction { validate_call_info, execute_call_info, fee_transfer_call_info, - transaction_receipt: TransactionReceipt { + receipt: TransactionReceipt { fee: final_fee, da_gas: final_da_gas, resources: final_resources, diff --git a/crates/blockifier/src/transaction/account_transactions_test.rs b/crates/blockifier/src/transaction/account_transactions_test.rs index 5e99b92386..ebb08555a6 100644 --- a/crates/blockifier/src/transaction/account_transactions_test.rs +++ b/crates/blockifier/src/transaction/account_transactions_test.rs @@ -110,7 +110,7 @@ fn test_circuit(block_context: BlockContext, max_resource_bounds: ResourceBounds .unwrap(); assert!(tx_execution_info.revert_error.is_none()); - assert_eq!(tx_execution_info.transaction_receipt.gas, GasVector::from_l1_gas(6682)); + assert_eq!(tx_execution_info.receipt.gas, GasVector::from_l1_gas(6682)); } #[rstest] @@ -145,11 +145,11 @@ fn test_rc96_holes(block_context: BlockContext, max_resource_bounds: ResourceBou assert!(!tx_execution_info.is_reverted()); assert_eq!( - tx_execution_info.transaction_receipt.resources.vm_resources.builtin_instance_counter + tx_execution_info.receipt.resources.vm_resources.builtin_instance_counter [&BuiltinName::range_check96], 24 ); - assert_eq!(tx_execution_info.transaction_receipt.gas, GasVector::from_l1_gas(6598)); + assert_eq!(tx_execution_info.receipt.gas, GasVector::from_l1_gas(6598)); } #[rstest] @@ -197,7 +197,7 @@ fn test_enforce_fee_false_works(block_context: BlockContext, #[case] version: Tr ) .unwrap(); assert!(!tx_execution_info.is_reverted()); - assert_eq!(tx_execution_info.transaction_receipt.fee, Fee(0)); + assert_eq!(tx_execution_info.receipt.fee, Fee(0)); } // TODO(Dori, 15/9/2023): Convert version variance to attribute macro. @@ -559,12 +559,12 @@ fn test_revert_invoke( state .get_fee_token_balance(account_address, chain_info.fee_token_address(&fee_type)) .unwrap(), - (felt!(BALANCE - tx_execution_info.transaction_receipt.fee.0), felt!(0_u8)) + (felt!(BALANCE - tx_execution_info.receipt.fee.0), felt!(0_u8)) ); assert_eq!(state.get_nonce_at(account_address).unwrap(), nonce_manager.next(account_address)); // Check that reverted steps are taken into account. - assert!(tx_execution_info.transaction_receipt.resources.n_reverted_steps > 0); + assert!(tx_execution_info.receipt.resources.n_reverted_steps > 0); // Check that execution state changes were reverted. assert_eq!( @@ -718,8 +718,8 @@ fn test_reverted_reach_steps_limit( }, ) .unwrap(); - let n_steps_0 = result.transaction_receipt.resources.total_charged_steps(); - let actual_fee_0 = result.transaction_receipt.fee.0; + let n_steps_0 = result.receipt.resources.total_charged_steps(); + let actual_fee_0 = result.receipt.fee.0; // Ensure the transaction was not reverted. assert!(!result.is_reverted()); @@ -734,8 +734,8 @@ fn test_reverted_reach_steps_limit( }, ) .unwrap(); - let n_steps_1 = result.transaction_receipt.resources.total_charged_steps(); - let actual_fee_1 = result.transaction_receipt.fee.0; + let n_steps_1 = result.receipt.resources.total_charged_steps(); + let actual_fee_1 = result.receipt.fee.0; // Ensure the transaction was not reverted. assert!(!result.is_reverted()); @@ -761,8 +761,8 @@ fn test_reverted_reach_steps_limit( }, ) .unwrap(); - let n_steps_fail = result.transaction_receipt.resources.total_charged_steps(); - let actual_fee_fail: u128 = result.transaction_receipt.fee.0; + let n_steps_fail = result.receipt.resources.total_charged_steps(); + let actual_fee_fail: u128 = result.receipt.fee.0; // Ensure the transaction was reverted. assert!(result.is_reverted()); @@ -782,8 +782,8 @@ fn test_reverted_reach_steps_limit( }, ) .unwrap(); - let n_steps_fail_next = result.transaction_receipt.resources.total_charged_steps(); - let actual_fee_fail_next: u128 = result.transaction_receipt.fee.0; + let n_steps_fail_next = result.receipt.resources.total_charged_steps(); + let actual_fee_fail_next: u128 = result.receipt.fee.0; // Ensure the transaction was reverted. assert!(result.is_reverted()); @@ -821,9 +821,9 @@ fn test_n_reverted_steps( .unwrap(); // Ensure the transaction was reverted. assert!(result.is_reverted()); - let mut actual_resources_0 = result.transaction_receipt.resources.clone(); - let n_steps_0 = result.transaction_receipt.resources.total_charged_steps(); - let actual_fee_0 = result.transaction_receipt.fee.0; + let mut actual_resources_0 = result.receipt.resources.clone(); + let n_steps_0 = result.receipt.resources.total_charged_steps(); + let actual_fee_0 = result.receipt.fee.0; // Invoke the `recursive_fail` function with 1 iterations. This call should fail. let result = run_invoke_tx( @@ -838,9 +838,9 @@ fn test_n_reverted_steps( .unwrap(); // Ensure the transaction was reverted. assert!(result.is_reverted()); - let actual_resources_1 = result.transaction_receipt.resources; + let actual_resources_1 = result.receipt.resources; let n_steps_1 = actual_resources_1.total_charged_steps(); - let actual_fee_1 = result.transaction_receipt.fee.0; + let actual_fee_1 = result.receipt.fee.0; // Invoke the `recursive_fail` function with 2 iterations. This call should fail. let result = run_invoke_tx( @@ -853,8 +853,8 @@ fn test_n_reverted_steps( }, ) .unwrap(); - let n_steps_2 = result.transaction_receipt.resources.total_charged_steps(); - let actual_fee_2 = result.transaction_receipt.fee.0; + let n_steps_2 = result.receipt.resources.total_charged_steps(); + let actual_fee_2 = result.receipt.fee.0; // Ensure the transaction was reverted. assert!(result.is_reverted()); @@ -885,8 +885,8 @@ fn test_n_reverted_steps( }, ) .unwrap(); - let n_steps_100 = result.transaction_receipt.resources.total_charged_steps(); - let actual_fee_100 = result.transaction_receipt.fee.0; + let n_steps_100 = result.receipt.resources.total_charged_steps(); + let actual_fee_100 = result.receipt.fee.0; // Ensure the transaction was reverted. assert!(result.is_reverted()); @@ -933,9 +933,9 @@ fn test_max_fee_to_max_steps_conversion( let execution_context1 = EntryPointExecutionContext::new_invoke(tx_context1, true).unwrap(); let max_steps_limit1 = execution_context1.vm_run_resources.get_n_steps(); let tx_execution_info1 = account_tx1.execute(&mut state, &block_context, true, true).unwrap(); - let n_steps1 = tx_execution_info1.transaction_receipt.resources.vm_resources.n_steps; + let n_steps1 = tx_execution_info1.receipt.resources.vm_resources.n_steps; let gas_used_vector1 = tx_execution_info1 - .transaction_receipt + .receipt .resources .to_gas_vector(&block_context.versioned_constants, block_context.block_info.use_kzg_da) .unwrap(); @@ -953,26 +953,23 @@ fn test_max_fee_to_max_steps_conversion( let execution_context2 = EntryPointExecutionContext::new_invoke(tx_context2, true).unwrap(); let max_steps_limit2 = execution_context2.vm_run_resources.get_n_steps(); let tx_execution_info2 = account_tx2.execute(&mut state, &block_context, true, true).unwrap(); - let n_steps2 = tx_execution_info2.transaction_receipt.resources.vm_resources.n_steps; + let n_steps2 = tx_execution_info2.receipt.resources.vm_resources.n_steps; let gas_used_vector2 = tx_execution_info2 - .transaction_receipt + .receipt .resources .to_gas_vector(&block_context.versioned_constants, block_context.block_info.use_kzg_da) .unwrap(); // Test that steps limit doubles as max_fee doubles, but actual consumed steps and fee remains. assert_eq!(max_steps_limit2.unwrap(), 2 * max_steps_limit1.unwrap()); - assert_eq!( - tx_execution_info1.transaction_receipt.fee.0, - tx_execution_info2.transaction_receipt.fee.0 - ); + assert_eq!(tx_execution_info1.receipt.fee.0, tx_execution_info2.receipt.fee.0); // TODO(Ori, 1/2/2024): Write an indicative expect message explaining why the conversion works. // TODO(Aner, 21/01/24): verify test compliant with 4844 (or modify accordingly). assert_eq!( actual_gas_used, u64::try_from(gas_used_vector2.l1_gas).expect("Failed to convert u128 to u64.") ); - assert_eq!(actual_fee, tx_execution_info2.transaction_receipt.fee.0); + assert_eq!(actual_fee, tx_execution_info2.receipt.fee.0); assert_eq!(n_steps1, n_steps2); assert_eq!(gas_used_vector1, gas_used_vector2); } @@ -1004,7 +1001,7 @@ fn test_insufficient_max_fee_reverts( ) .unwrap(); assert!(!tx_execution_info1.is_reverted()); - let actual_fee_depth1 = tx_execution_info1.transaction_receipt.fee; + let actual_fee_depth1 = tx_execution_info1.receipt.fee; let gas_price = u128::from(block_context.block_info.gas_prices.strk_l1_gas_price); let gas_ammount = u64::try_from(actual_fee_depth1.0 / gas_price).unwrap(); @@ -1023,7 +1020,7 @@ fn test_insufficient_max_fee_reverts( ) .unwrap(); assert!(tx_execution_info2.is_reverted()); - assert!(tx_execution_info2.transaction_receipt.fee == actual_fee_depth1); + assert!(tx_execution_info2.receipt.fee == actual_fee_depth1); assert!(tx_execution_info2.revert_error.unwrap().starts_with("Insufficient max L1 gas:")); // Invoke the `recurse` function with depth of 824 and the actual fee of depth 1 as max_fee. @@ -1041,7 +1038,7 @@ fn test_insufficient_max_fee_reverts( ) .unwrap(); assert!(tx_execution_info3.is_reverted()); - assert!(tx_execution_info3.transaction_receipt.fee == actual_fee_depth1); + assert!(tx_execution_info3.receipt.fee == actual_fee_depth1); assert!( tx_execution_info3.revert_error.unwrap().contains("RunResources has no remaining steps.") ); @@ -1148,7 +1145,7 @@ fn test_count_actual_storage_changes( let execution_info = account_tx.execute_raw(&mut state, &block_context, execution_flags).unwrap(); - let fee_1 = execution_info.transaction_receipt.fee; + let fee_1 = execution_info.receipt.fee; let state_changes_1 = state.get_actual_state_changes().unwrap(); let cell_write_storage_change = ((contract_address, storage_key!(15_u8)), felt!(1_u8)); @@ -1191,7 +1188,7 @@ fn test_count_actual_storage_changes( let execution_info = account_tx.execute_raw(&mut state, &block_context, execution_flags).unwrap(); - let fee_2 = execution_info.transaction_receipt.fee; + let fee_2 = execution_info.receipt.fee; let state_changes_2 = state.get_actual_state_changes().unwrap(); expected_sequencer_total_fee += Felt::from(fee_2.0); @@ -1229,7 +1226,7 @@ fn test_count_actual_storage_changes( let execution_info = account_tx.execute_raw(&mut state, &block_context, execution_flags).unwrap(); - let fee_transfer = execution_info.transaction_receipt.fee; + let fee_transfer = execution_info.receipt.fee; let state_changes_transfer = state.get_actual_state_changes().unwrap(); let transfer_receipient_storage_change = ( (fee_token_address, get_fee_token_var_address(contract_address!(recipient))), diff --git a/crates/blockifier/src/transaction/execution_flavors_test.rs b/crates/blockifier/src/transaction/execution_flavors_test.rs index 5bc4acecd6..3f3d82d7c0 100644 --- a/crates/blockifier/src/transaction/execution_flavors_test.rs +++ b/crates/blockifier/src/transaction/execution_flavors_test.rs @@ -127,7 +127,7 @@ fn check_gas_and_fee( ) { assert_eq!( tx_execution_info - .transaction_receipt + .receipt .resources .to_gas_vector(&block_context.versioned_constants, block_context.block_info.use_kzg_da) .unwrap() @@ -135,15 +135,11 @@ fn check_gas_and_fee( expected_actual_gas.into() ); - assert_eq!(tx_execution_info.transaction_receipt.fee, expected_actual_fee); + assert_eq!(tx_execution_info.receipt.fee, expected_actual_fee); // Future compatibility: resources other than the L1 gas usage may affect the fee (currently, // `calculate_tx_fee` is simply the result of `calculate_tx_gas_usage_vector` times gas price). assert_eq!( - tx_execution_info - .transaction_receipt - .resources - .calculate_tx_fee(block_context, fee_type) - .unwrap(), + tx_execution_info.receipt.resources.calculate_tx_fee(block_context, fee_type).unwrap(), expected_cost_of_resources ); } @@ -514,7 +510,7 @@ fn test_simulate_validate_charge_fee_mid_execution( // availability), hence the actual resources may exceed the senders bounds after all. if charge_fee { limited_gas_used } else { unlimited_gas_used }, if charge_fee { fee_bound } else { unlimited_fee }, - // Complete resources used are reported as transaction_receipt.resources; but only the + // Complete resources used are reported as receipt.resources; but only the // charged final fee is shown in actual_fee. if charge_fee { limited_fee } else { unlimited_fee }, ); @@ -547,7 +543,7 @@ fn test_simulate_validate_charge_fee_mid_execution( .execute(&mut state, &low_step_block_context, charge_fee, validate) .unwrap(); assert!(tx_execution_info.revert_error.clone().unwrap().contains("no remaining steps")); - // Complete resources used are reported as transaction_receipt.resources; but only the charged + // Complete resources used are reported as receipt.resources; but only the charged // final fee is shown in actual_fee. As a sanity check, verify that the fee derived directly // from the consumed resources is also equal to the expected fee. check_gas_and_fee( diff --git a/crates/blockifier/src/transaction/objects.rs b/crates/blockifier/src/transaction/objects.rs index a08dbd5e8d..db844eb075 100644 --- a/crates/blockifier/src/transaction/objects.rs +++ b/crates/blockifier/src/transaction/objects.rs @@ -222,7 +222,7 @@ pub struct TransactionExecutionInfo { /// actual execution resources the transaction is charged for /// (including L1 gas and additional OS resources estimation), /// and total gas consumed. - pub transaction_receipt: TransactionReceipt, + pub receipt: TransactionReceipt, } impl TransactionExecutionInfo { diff --git a/crates/blockifier/src/transaction/post_execution_test.rs b/crates/blockifier/src/transaction/post_execution_test.rs index 3cf9c3c5ba..08d00350aa 100644 --- a/crates/blockifier/src/transaction/post_execution_test.rs +++ b/crates/blockifier/src/transaction/post_execution_test.rs @@ -141,7 +141,7 @@ fn test_revert_on_overdraft( .unwrap(); assert!(!execution_info.is_reverted()); - let transfer_tx_fee = execution_info.transaction_receipt.fee; + let transfer_tx_fee = execution_info.receipt.fee; // Check the current balance, before next transaction. let (balance, _) = state @@ -251,10 +251,10 @@ fn test_revert_on_resource_overuse( ) .unwrap(); assert_eq!(execution_info_measure.revert_error, None); - let actual_fee = execution_info_measure.transaction_receipt.fee; + let actual_fee = execution_info_measure.receipt.fee; // TODO(Ori, 1/2/2024): Write an indicative expect message explaining why the conversion works. let actual_gas_usage: u64 = execution_info_measure - .transaction_receipt + .receipt .resources .to_gas_vector(&block_context.versioned_constants, block_context.block_info.use_kzg_da) .unwrap() @@ -277,15 +277,12 @@ fn test_revert_on_resource_overuse( ) .unwrap(); assert_eq!(execution_info_tight.revert_error, None); - assert_eq!(execution_info_tight.transaction_receipt.fee, actual_fee); - assert_eq!( - execution_info_tight.transaction_receipt.resources, - execution_info_measure.transaction_receipt.resources - ); + assert_eq!(execution_info_tight.receipt.fee, actual_fee); + assert_eq!(execution_info_tight.receipt.resources, execution_info_measure.receipt.resources); // Re-run the same function with max bounds slightly below the actual usage, and verify it's // reverted. - let low_max_fee = Fee(execution_info_measure.transaction_receipt.fee.0 - 1); + let low_max_fee = Fee(execution_info_measure.receipt.fee.0 - 1); let execution_info_result = run_invoke_tx( &mut state, &block_context, diff --git a/crates/blockifier/src/transaction/transaction_execution.rs b/crates/blockifier/src/transaction/transaction_execution.rs index a2f6bf263d..f2fb174a84 100644 --- a/crates/blockifier/src/transaction/transaction_execution.rs +++ b/crates/blockifier/src/transaction/transaction_execution.rs @@ -148,7 +148,7 @@ impl ExecutableTransaction for L1HandlerTransaction { validate_call_info: None, execute_call_info, fee_transfer_call_info: None, - transaction_receipt: TransactionReceipt { + receipt: TransactionReceipt { fee: Fee::default(), da_gas, resources: actual_resources, @@ -191,7 +191,7 @@ impl ExecutableTransaction for Transaction { verify_tx_weights_in_bounds( state, &tx_execution_summary, - &tx_execution_info.transaction_receipt.resources, + &tx_execution_info.receipt.resources, &tx_state_changes_keys, &block_context.bouncer_config, )?; diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index 6e7ef6058c..3c0c9d3616 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -475,11 +475,8 @@ fn test_invoke_tx( // Build expected fee transfer call info. let fee_type = &tx_context.tx_info.fee_type(); - let expected_actual_fee = actual_execution_info - .transaction_receipt - .resources - .calculate_tx_fee(block_context, fee_type) - .unwrap(); + let expected_actual_fee = + actual_execution_info.receipt.resources.calculate_tx_fee(block_context, fee_type).unwrap(); let expected_fee_transfer_call_info = expected_fee_transfer_call_info( &tx_context, sender_address, @@ -517,7 +514,7 @@ fn test_invoke_tx( validate_call_info: expected_validate_call_info, execute_call_info: expected_execute_call_info, fee_transfer_call_info: expected_fee_transfer_call_info, - transaction_receipt: TransactionReceipt { + receipt: TransactionReceipt { fee: expected_actual_fee, da_gas, resources: expected_actual_resources, @@ -1011,7 +1008,7 @@ fn test_actual_fee_gt_resource_bounds( // Test that fee was charged. let minimal_fee = Fee(minimal_l1_gas * u128::from(block_context.block_info.gas_prices.strk_l1_gas_price)); - assert_eq!(execution_result.transaction_receipt.fee, minimal_fee); + assert_eq!(execution_result.receipt.fee, minimal_fee); } #[rstest] @@ -1196,11 +1193,8 @@ fn test_declare_tx( ); // Build expected fee transfer call info. - let expected_actual_fee = actual_execution_info - .transaction_receipt - .resources - .calculate_tx_fee(block_context, fee_type) - .unwrap(); + let expected_actual_fee = + actual_execution_info.receipt.resources.calculate_tx_fee(block_context, fee_type).unwrap(); let expected_fee_transfer_call_info = expected_fee_transfer_call_info( tx_context, sender_address, @@ -1236,7 +1230,7 @@ fn test_declare_tx( validate_call_info: expected_validate_call_info, execute_call_info: None, fee_transfer_call_info: expected_fee_transfer_call_info, - transaction_receipt: TransactionReceipt { + receipt: TransactionReceipt { fee: expected_actual_fee, da_gas, resources: expected_actual_resources, @@ -1360,19 +1354,15 @@ fn test_deploy_account_tx( }); // Build expected fee transfer call info. - let expected_actual_fee = actual_execution_info - .transaction_receipt - .resources - .calculate_tx_fee(block_context, fee_type) - .unwrap(); + let expected_actual_fee = + actual_execution_info.receipt.resources.calculate_tx_fee(block_context, fee_type).unwrap(); let expected_fee_transfer_call_info = expected_fee_transfer_call_info( tx_context, deployed_account_address, expected_actual_fee, FeatureContract::ERC20(CairoVersion::Cairo0).get_class_hash(), ); - let starknet_resources = - actual_execution_info.transaction_receipt.resources.starknet_resources.clone(); + let starknet_resources = actual_execution_info.receipt.resources.starknet_resources.clone(); let state_changes_count = StateChangesCount { n_storage_updates: 1, @@ -1409,7 +1399,7 @@ fn test_deploy_account_tx( validate_call_info: expected_validate_call_info, execute_call_info: expected_execute_call_info, fee_transfer_call_info: expected_fee_transfer_call_info, - transaction_receipt: TransactionReceipt { + receipt: TransactionReceipt { fee: expected_actual_fee, da_gas, resources: actual_resources, @@ -1903,18 +1893,14 @@ fn test_l1_handler(#[values(false, true)] use_kzg_da: bool) { // Copy StarknetResources from actual resources and assert gas usage calculation is correct. let expected_tx_resources = TransactionResources { - starknet_resources: actual_execution_info - .transaction_receipt - .resources - .starknet_resources - .clone(), + starknet_resources: actual_execution_info.receipt.resources.starknet_resources.clone(), vm_resources: expected_execution_resources, ..Default::default() }; assert_eq!( expected_gas, actual_execution_info - .transaction_receipt + .receipt .resources .starknet_resources .to_gas_vector(versioned_constants, use_kzg_da) @@ -1929,7 +1915,7 @@ fn test_l1_handler(#[values(false, true)] use_kzg_da: bool) { validate_call_info: None, execute_call_info: Some(expected_call_info), fee_transfer_call_info: None, - transaction_receipt: TransactionReceipt { + receipt: TransactionReceipt { fee: Fee(0), da_gas: expected_da_gas, resources: expected_tx_resources, @@ -1955,11 +1941,9 @@ fn test_l1_handler(#[values(false, true)] use_kzg_da: bool) { let tx_no_fee = L1HandlerTransaction::create_for_testing(Fee(0), contract_address); let error = tx_no_fee.execute(state, block_context, true, true).unwrap_err(); // Today, we check that the paid_fee is positive, no matter what was the actual fee. - let expected_actual_fee = (expected_execution_info - .transaction_receipt - .resources - .calculate_tx_fee(block_context, &FeeType::Eth)) - .unwrap(); + let expected_actual_fee = + (expected_execution_info.receipt.resources.calculate_tx_fee(block_context, &FeeType::Eth)) + .unwrap(); assert_matches!( error, TransactionExecutionError::TransactionFeeError( diff --git a/crates/native_blockifier/src/py_block_executor.rs b/crates/native_blockifier/src/py_block_executor.rs index bf3c244eba..f1f953d8b9 100644 --- a/crates/native_blockifier/src/py_block_executor.rs +++ b/crates/native_blockifier/src/py_block_executor.rs @@ -60,15 +60,15 @@ impl ThinTransactionExecutionInfo { validate_call_info: tx_execution_info.validate_call_info, execute_call_info: tx_execution_info.execute_call_info, fee_transfer_call_info: tx_execution_info.fee_transfer_call_info, - actual_fee: tx_execution_info.transaction_receipt.fee, - da_gas: tx_execution_info.transaction_receipt.da_gas, - actual_resources: tx_execution_info.transaction_receipt.resources.to_resources_mapping( + actual_fee: tx_execution_info.receipt.fee, + da_gas: tx_execution_info.receipt.da_gas, + actual_resources: tx_execution_info.receipt.resources.to_resources_mapping( block_context.versioned_constants(), block_context.block_info().use_kzg_da, true, ), revert_error: tx_execution_info.revert_error, - total_gas: tx_execution_info.transaction_receipt.gas, + total_gas: tx_execution_info.receipt.gas, } } pub fn serialize(self) -> RawTransactionExecutionResult { diff --git a/crates/papyrus_execution/src/objects.rs b/crates/papyrus_execution/src/objects.rs index 96d2e627a8..3b4e247769 100644 --- a/crates/papyrus_execution/src/objects.rs +++ b/crates/papyrus_execution/src/objects.rs @@ -127,7 +127,7 @@ impl TryFrom for InvokeTransactionTrace { transaction_execution_info .execute_call_info .expect("Invoke transaction execution should contain execute_call_info."), - transaction_execution_info.transaction_receipt.da_gas, + transaction_execution_info.receipt.da_gas, ) .try_into()?, ), @@ -136,18 +136,16 @@ impl TryFrom for InvokeTransactionTrace { Ok(Self { validate_invocation: match transaction_execution_info.validate_call_info { None => None, - Some(call_info) => Some( - (call_info, transaction_execution_info.transaction_receipt.da_gas) - .try_into()?, - ), + Some(call_info) => { + Some((call_info, transaction_execution_info.receipt.da_gas).try_into()?) + } }, execute_invocation, fee_transfer_invocation: match transaction_execution_info.fee_transfer_call_info { None => None, - Some(call_info) => Some( - (call_info, transaction_execution_info.transaction_receipt.da_gas) - .try_into()?, - ), + Some(call_info) => { + Some((call_info, transaction_execution_info.receipt.da_gas).try_into()?) + } }, }) } @@ -169,14 +167,14 @@ pub(crate) fn tx_execution_output_to_fee_estimation( ), }; - let gas_vector = tx_execution_output.execution_info.transaction_receipt.gas; + let gas_vector = tx_execution_output.execution_info.receipt.gas; Ok(FeeEstimation { gas_consumed: gas_vector.l1_gas.into(), gas_price, data_gas_consumed: gas_vector.l1_data_gas.into(), data_gas_price, - overall_fee: tx_execution_output.execution_info.transaction_receipt.fee, + overall_fee: tx_execution_output.execution_info.receipt.fee, unit: tx_execution_output.price_unit, }) } @@ -198,17 +196,15 @@ impl TryFrom for DeclareTransactionTrace { Ok(Self { validate_invocation: match transaction_execution_info.validate_call_info { None => None, - Some(call_info) => Some( - (call_info, transaction_execution_info.transaction_receipt.da_gas) - .try_into()?, - ), + Some(call_info) => { + Some((call_info, transaction_execution_info.receipt.da_gas).try_into()?) + } }, fee_transfer_invocation: match transaction_execution_info.fee_transfer_call_info { None => None, - Some(call_info) => Some( - (call_info, transaction_execution_info.transaction_receipt.da_gas) - .try_into()?, - ), + Some(call_info) => { + Some((call_info, transaction_execution_info.receipt.da_gas).try_into()?) + } }, }) } @@ -233,25 +229,23 @@ impl TryFrom for DeployAccountTransactionTrace { Ok(Self { validate_invocation: match transaction_execution_info.validate_call_info { None => None, - Some(call_info) => Some( - (call_info, transaction_execution_info.transaction_receipt.da_gas) - .try_into()?, - ), + Some(call_info) => { + Some((call_info, transaction_execution_info.receipt.da_gas).try_into()?) + } }, constructor_invocation: ( transaction_execution_info.execute_call_info.expect( "Deploy account execution should contain execute_call_info (the constructor \ call info).", ), - transaction_execution_info.transaction_receipt.da_gas, + transaction_execution_info.receipt.da_gas, ) .try_into()?, fee_transfer_invocation: match transaction_execution_info.fee_transfer_call_info { None => None, - Some(call_info) => Some( - (call_info, transaction_execution_info.transaction_receipt.da_gas) - .try_into()?, - ), + Some(call_info) => { + Some((call_info, transaction_execution_info.receipt.da_gas).try_into()?) + } }, }) } @@ -272,7 +266,7 @@ impl TryFrom for L1HandlerTransactionTrace { transaction_execution_info .execute_call_info .expect("L1Handler execution should contain execute_call_info."), - transaction_execution_info.transaction_receipt.da_gas, + transaction_execution_info.receipt.da_gas, ) .try_into()?, })