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

Commit

Permalink
build: add total gas to transactionexecutioninfo (#1933)
Browse files Browse the repository at this point in the history
  • Loading branch information
AvivYossef-starkware authored Jun 5, 2024
1 parent cf5d3b6 commit 5f65e5e
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 27 deletions.
6 changes: 6 additions & 0 deletions crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,11 @@ impl<U: UpdatableState> ExecutableTransaction<U> 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,
Expand All @@ -678,6 +683,7 @@ impl<U: UpdatableState> ExecutableTransaction<U> for AccountTransaction {
da_gas: final_da_gas,
actual_resources: final_resources,
revert_error,
total_gas,
};
Ok(tx_execution_info)
}
Expand Down
2 changes: 2 additions & 0 deletions crates/blockifier/src/transaction/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TransactionExecutionError>`.
pub revert_error: Option<String>,

pub total_gas: GasVector,
}

impl TransactionExecutionInfo {
Expand Down
6 changes: 6 additions & 0 deletions crates/blockifier/src/transaction/transaction_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ impl<U: UpdatableState> ExecutableTransaction<U> 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,
Expand All @@ -140,6 +145,7 @@ impl<U: UpdatableState> ExecutableTransaction<U> for L1HandlerTransaction {
da_gas,
revert_error: None,
actual_resources,
total_gas,
})
}
}
Expand Down
77 changes: 50 additions & 27 deletions crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,28 +452,34 @@ 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,
actual_fee: expected_actual_fee,
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);

Expand Down Expand Up @@ -1156,28 +1162,33 @@ 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,
actual_fee: expected_actual_fee,
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);

Expand Down Expand Up @@ -1297,28 +1308,34 @@ 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,
actual_fee: expected_actual_fee,
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);

Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions crates/native_blockifier/src/py_block_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub(crate) struct ThinTransactionExecutionInfo {
pub da_gas: GasVector,
pub actual_resources: ResourcesMapping,
pub revert_error: Option<String>,
pub total_gas: GasVector,
}

impl ThinTransactionExecutionInfo {
Expand All @@ -75,6 +76,7 @@ impl ThinTransactionExecutionInfo {
true,
),
revert_error: tx_execution_info.revert_error,
total_gas: tx_execution_info.total_gas,
}
}
}
Expand Down

0 comments on commit 5f65e5e

Please sign in to comment.