diff --git a/crates/blockifier/src/transaction/account_transaction.rs b/crates/blockifier/src/transaction/account_transaction.rs index f180528a89..648648320d 100644 --- a/crates/blockifier/src/transaction/account_transaction.rs +++ b/crates/blockifier/src/transaction/account_transaction.rs @@ -670,6 +670,11 @@ impl ExecutableTransaction for AccountTransaction { )?; let fee_transfer_call_info = self.handle_fee(state, tx_context, final_fee, charge_fee)?; + let total_gas = final_resources.to_gas_vector( + &block_context.versioned_constants, + block_context.block_info.use_kzg_da, + )?; + let tx_execution_info = TransactionExecutionInfo { validate_call_info, execute_call_info, @@ -678,6 +683,7 @@ impl ExecutableTransaction for AccountTransaction { da_gas: final_da_gas, actual_resources: final_resources, revert_error, + total_gas, }; Ok(tx_execution_info) } diff --git a/crates/blockifier/src/transaction/objects.rs b/crates/blockifier/src/transaction/objects.rs index 53af033833..f4c3650b6e 100644 --- a/crates/blockifier/src/transaction/objects.rs +++ b/crates/blockifier/src/transaction/objects.rs @@ -214,6 +214,8 @@ pub struct TransactionExecutionInfo { // TODO(Dori, 1/8/2023): If the `Eq` and `PartialEq` traits are removed, or implemented on all // internal structs in this enum, this field should be `Option`. pub revert_error: Option, + + pub total_gas: GasVector, } impl TransactionExecutionInfo { diff --git a/crates/blockifier/src/transaction/transaction_execution.rs b/crates/blockifier/src/transaction/transaction_execution.rs index dff9a6fbbf..e526d7d649 100644 --- a/crates/blockifier/src/transaction/transaction_execution.rs +++ b/crates/blockifier/src/transaction/transaction_execution.rs @@ -132,6 +132,11 @@ impl ExecutableTransaction for L1HandlerTransaction { return Err(TransactionFeeError::InsufficientL1Fee { paid_fee, actual_fee })?; } + let total_gas = actual_resources.to_gas_vector( + &block_context.versioned_constants, + block_context.block_info.use_kzg_da, + )?; + Ok(TransactionExecutionInfo { validate_call_info: None, execute_call_info, @@ -140,6 +145,7 @@ impl ExecutableTransaction for L1HandlerTransaction { da_gas, revert_error: None, actual_resources, + total_gas, }) } } diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index a49aca80fc..987050e215 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -452,12 +452,24 @@ fn test_invoke_tx( vec![&expected_validate_call_info, &expected_execute_call_info], ); let state_changes_count = starknet_resources.state_changes_for_fee; - let expected_actual_resources = TransactionResources { + let mut expected_actual_resources = TransactionResources { starknet_resources, vm_resources: expected_cairo_resources, ..Default::default() }; - let mut expected_execution_info = TransactionExecutionInfo { + + add_kzg_da_resources_to_resources_mapping( + &mut expected_actual_resources.vm_resources, + &state_changes_count, + versioned_constants, + use_kzg_da, + ); + + let total_gas = expected_actual_resources + .to_gas_vector(&block_context.versioned_constants, block_context.block_info.use_kzg_da) + .unwrap(); + + let expected_execution_info = TransactionExecutionInfo { validate_call_info: expected_validate_call_info, execute_call_info: expected_execute_call_info, fee_transfer_call_info: expected_fee_transfer_call_info, @@ -465,15 +477,9 @@ fn test_invoke_tx( da_gas, actual_resources: expected_actual_resources, revert_error: None, + total_gas, }; - add_kzg_da_resources_to_resources_mapping( - &mut expected_execution_info.actual_resources.vm_resources, - &state_changes_count, - versioned_constants, - use_kzg_da, - ); - // Test execution info result. assert_eq!(actual_execution_info, expected_execution_info); @@ -1156,12 +1162,23 @@ fn test_declare_tx( vec![&expected_validate_call_info], ); let state_changes_count = starknet_resources.state_changes_for_fee; - let expected_actual_resources = TransactionResources { + let mut expected_actual_resources = TransactionResources { starknet_resources, vm_resources: expected_cairo_resources, ..Default::default() }; - let mut expected_execution_info = TransactionExecutionInfo { + + add_kzg_da_resources_to_resources_mapping( + &mut expected_actual_resources.vm_resources, + &state_changes_count, + versioned_constants, + use_kzg_da, + ); + + let expected_total_gas = + expected_actual_resources.to_gas_vector(versioned_constants, use_kzg_da).unwrap(); + + let expected_execution_info = TransactionExecutionInfo { validate_call_info: expected_validate_call_info, execute_call_info: None, fee_transfer_call_info: expected_fee_transfer_call_info, @@ -1169,15 +1186,9 @@ fn test_declare_tx( da_gas, revert_error: None, actual_resources: expected_actual_resources, + total_gas: expected_total_gas, }; - add_kzg_da_resources_to_resources_mapping( - &mut expected_execution_info.actual_resources.vm_resources, - &state_changes_count, - versioned_constants, - use_kzg_da, - ); - // Test execution info result. assert_eq!(actual_execution_info, expected_execution_info); @@ -1297,12 +1308,24 @@ fn test_deploy_account_tx( vec![&expected_validate_call_info, &expected_execute_call_info], ); - let actual_resources = TransactionResources { + let mut actual_resources = TransactionResources { starknet_resources, vm_resources: expected_cairo_resources, ..Default::default() }; - let mut expected_execution_info = TransactionExecutionInfo { + + add_kzg_da_resources_to_resources_mapping( + &mut actual_resources.vm_resources, + &state_changes_count, + versioned_constants, + use_kzg_da, + ); + + let expected_total_gas = actual_resources + .to_gas_vector(&block_context.versioned_constants, block_context.block_info.use_kzg_da) + .unwrap(); + + let expected_execution_info = TransactionExecutionInfo { validate_call_info: expected_validate_call_info, execute_call_info: expected_execute_call_info, fee_transfer_call_info: expected_fee_transfer_call_info, @@ -1310,15 +1333,9 @@ fn test_deploy_account_tx( da_gas, revert_error: None, actual_resources, + total_gas: expected_total_gas, }; - add_kzg_da_resources_to_resources_mapping( - &mut expected_execution_info.actual_resources.vm_resources, - &state_changes_count, - versioned_constants, - use_kzg_da, - ); - // Test execution info result. assert_eq!(actual_execution_info, expected_execution_info); @@ -1797,6 +1814,11 @@ fn test_l1_handler(#[values(false, true)] use_kzg_da: bool) { .starknet_resources .to_gas_vector(versioned_constants, use_kzg_da) ); + + let total_gas = expected_tx_resources + .to_gas_vector(versioned_constants, block_context.block_info.use_kzg_da) + .unwrap(); + // Build the expected execution info. let expected_execution_info = TransactionExecutionInfo { validate_call_info: None, @@ -1806,6 +1828,7 @@ fn test_l1_handler(#[values(false, true)] use_kzg_da: bool) { da_gas: expected_da_gas, actual_resources: expected_tx_resources, revert_error: None, + total_gas, }; // Check the actual returned execution info. diff --git a/crates/native_blockifier/src/py_block_executor.rs b/crates/native_blockifier/src/py_block_executor.rs index 1f51685d46..228fa437dd 100644 --- a/crates/native_blockifier/src/py_block_executor.rs +++ b/crates/native_blockifier/src/py_block_executor.rs @@ -56,6 +56,7 @@ pub(crate) struct ThinTransactionExecutionInfo { pub da_gas: GasVector, pub actual_resources: ResourcesMapping, pub revert_error: Option, + pub total_gas: GasVector, } impl ThinTransactionExecutionInfo { @@ -75,6 +76,7 @@ impl ThinTransactionExecutionInfo { true, ), revert_error: tx_execution_info.revert_error, + total_gas: tx_execution_info.total_gas, } } }