From d1f5d45edb9ea466f7019f57104627ae8acdc4dd Mon Sep 17 00:00:00 2001 From: Nimrod Weiss Date: Tue, 20 Aug 2024 14:32:59 +0300 Subject: [PATCH] build(fee): tx_context and create_tx_info cannot_fail --- .../src/blockifier/stateful_validator.rs | 12 ++--- .../src/concurrency/versioned_state_test.rs | 4 +- .../src/concurrency/worker_logic.rs | 5 +- .../src/concurrency/worker_logic_test.rs | 4 +- crates/blockifier/src/context.rs | 9 ++-- crates/blockifier/src/fee/fee_test.rs | 2 +- crates/blockifier/src/fee/gas_usage_test.rs | 5 +- crates/blockifier/src/test_utils/prices.rs | 6 +-- .../src/transaction/account_transaction.rs | 6 +-- .../transaction/account_transactions_test.rs | 8 ++-- crates/blockifier/src/transaction/errors.rs | 11 ----- crates/blockifier/src/transaction/objects.rs | 3 +- .../src/transaction/post_execution_test.rs | 2 +- .../src/transaction/transaction_execution.rs | 8 ++-- .../src/transaction/transactions.rs | 46 +++++++++---------- .../src/transaction/transactions_test.rs | 16 +++---- crates/native_blockifier/src/py_validator.rs | 2 +- 17 files changed, 60 insertions(+), 89 deletions(-) diff --git a/crates/blockifier/src/blockifier/stateful_validator.rs b/crates/blockifier/src/blockifier/stateful_validator.rs index 392db678856..3c6a8606dd3 100644 --- a/crates/blockifier/src/blockifier/stateful_validator.rs +++ b/crates/blockifier/src/blockifier/stateful_validator.rs @@ -18,11 +18,7 @@ use crate::state::cached_state::CachedState; use crate::state::errors::StateError; use crate::state::state_api::StateReader; use crate::transaction::account_transaction::AccountTransaction; -use crate::transaction::errors::{ - TransactionExecutionError, - TransactionInfoCreationError, - TransactionPreValidationError, -}; +use crate::transaction::errors::{TransactionExecutionError, TransactionPreValidationError}; use crate::transaction::transaction_execution::Transaction; use crate::transaction::transactions::ValidatableTransaction; @@ -40,8 +36,6 @@ pub enum StatefulValidatorError { TransactionExecutorError(#[from] TransactionExecutorError), #[error(transparent)] TransactionPreValidationError(#[from] TransactionPreValidationError), - #[error(transparent)] - TransactionCreationError(#[from] TransactionInfoCreationError), } pub type StatefulValidatorResult = Result; @@ -71,7 +65,7 @@ impl StatefulValidator { return Ok(()); } - let tx_context = self.tx_executor.block_context.to_tx_context(&tx)?; + let tx_context = self.tx_executor.block_context.to_tx_context(&tx); self.perform_pre_validation_stage(&tx, &tx_context)?; if skip_validate { @@ -118,7 +112,7 @@ impl StatefulValidator { mut remaining_gas: u64, ) -> StatefulValidatorResult<(Option, TransactionReceipt)> { let mut execution_resources = ExecutionResources::default(); - let tx_context = Arc::new(self.tx_executor.block_context.to_tx_context(tx)?); + let tx_context = Arc::new(self.tx_executor.block_context.to_tx_context(tx)); let limit_steps_by_resources = true; let validate_call_info = tx.validate_tx( diff --git a/crates/blockifier/src/concurrency/versioned_state_test.rs b/crates/blockifier/src/concurrency/versioned_state_test.rs index c77fa1d3802..1edd1db1930 100644 --- a/crates/blockifier/src/concurrency/versioned_state_test.rs +++ b/crates/blockifier/src/concurrency/versioned_state_test.rs @@ -233,7 +233,7 @@ fn test_run_parallel_txs(max_resource_bounds: ValidResourceBounds) { &mut NonceManager::default(), ); let account_tx_1 = AccountTransaction::DeployAccount(deploy_account_tx_1); - let enforce_fee = account_tx_1.create_tx_info().unwrap().enforce_fee(); + let enforce_fee = account_tx_1.create_tx_info().enforce_fee(); let class_hash = grindy_account.get_class_hash(); let ctor_storage_arg = felt!(1_u8); @@ -248,7 +248,7 @@ fn test_run_parallel_txs(max_resource_bounds: ValidResourceBounds) { let deploy_account_tx_2 = deploy_account_tx(deploy_tx_args, nonce_manager); let account_address = deploy_account_tx_2.contract_address(); let account_tx_2 = AccountTransaction::DeployAccount(deploy_account_tx_2); - let tx_context = block_context.to_tx_context(&account_tx_2).unwrap(); + let tx_context = block_context.to_tx_context(&account_tx_2); let fee_type = tx_context.tx_info.fee_type(); let deployed_account_balance_key = get_fee_token_var_address(account_address); diff --git a/crates/blockifier/src/concurrency/worker_logic.rs b/crates/blockifier/src/concurrency/worker_logic.rs index ed22913bfe8..3029236f6f1 100644 --- a/crates/blockifier/src/concurrency/worker_logic.rs +++ b/crates/blockifier/src/concurrency/worker_logic.rs @@ -230,10 +230,7 @@ impl<'a, S: StateReader> WorkerExecutor<'a, S> { &mut execution_output.as_mut().expect(EXECUTION_OUTPUTS_UNWRAP_ERROR).result; if let Ok(tx_execution_info) = tx_result.as_mut() { - let tx_context = self - .block_context - .to_tx_context(&self.chunk[tx_index]) - .expect("Failed to create tx context."); + let tx_context = self.block_context.to_tx_context(&self.chunk[tx_index]); // Add the deleted sequencer balance key to the storage keys. let concurrency_mode = true; tx_state_changes_keys.update_sequencer_key_in_storage( diff --git a/crates/blockifier/src/concurrency/worker_logic_test.rs b/crates/blockifier/src/concurrency/worker_logic_test.rs index e6aca5c932a..8f7584d1649 100644 --- a/crates/blockifier/src/concurrency/worker_logic_test.rs +++ b/crates/blockifier/src/concurrency/worker_logic_test.rs @@ -174,7 +174,7 @@ pub fn test_commit_tx() { assert_eq!(felt!(expected_sequencer_storage_read), actual_sequencer_storage_read,); } } - let tx_context = executor.block_context.to_tx_context(&txs[commit_idx]).unwrap(); + let tx_context = executor.block_context.to_tx_context(&txs[commit_idx]); expected_sequencer_balance_low += actual_fee; // Check that the sequencer balance was updated correctly in the state. verify_sequencer_balance_update( @@ -228,7 +228,7 @@ fn test_commit_tx_when_sender_is_sequencer() { let read_values_before_commit = fee_transfer_call_info.storage_read_values.clone(); drop(execution_task_outputs); - let tx_context = &executor.block_context.to_tx_context(&sequencer_tx[0]).unwrap(); + let tx_context = &executor.block_context.to_tx_context(&sequencer_tx[0]); let fee_token_address = executor.block_context.chain_info.fee_token_address(&tx_context.tx_info.fee_type()); let sequencer_balance_high_before = diff --git a/crates/blockifier/src/context.rs b/crates/blockifier/src/context.rs index 50ea1444d18..229a0831017 100644 --- a/crates/blockifier/src/context.rs +++ b/crates/blockifier/src/context.rs @@ -7,7 +7,6 @@ use starknet_api::core::{ChainId, ContractAddress}; use crate::blockifier::block::BlockInfo; use crate::bouncer::BouncerConfig; -use crate::transaction::errors::TransactionInfoCreationError; use crate::transaction::objects::{ FeeType, HasRelatedFeeType, @@ -67,11 +66,11 @@ impl BlockContext { pub fn to_tx_context( &self, tx_info_creator: &impl TransactionInfoCreator, - ) -> Result { - Ok(TransactionContext { + ) -> TransactionContext { + TransactionContext { block_context: self.clone(), - tx_info: tx_info_creator.create_tx_info()?, - }) + tx_info: tx_info_creator.create_tx_info(), + } } } diff --git a/crates/blockifier/src/fee/fee_test.rs b/crates/blockifier/src/fee/fee_test.rs index 5944d05b134..bcc791f7230 100644 --- a/crates/blockifier/src/fee/fee_test.rs +++ b/crates/blockifier/src/fee/fee_test.rs @@ -144,7 +144,7 @@ fn test_discounted_gas_overdraft( let charge_fee = true; let report = PostExecutionReport::new( &mut state, - &block_context.to_tx_context(&tx).unwrap(), + &block_context.to_tx_context(&tx), &tx_receipt, charge_fee, ) diff --git a/crates/blockifier/src/fee/gas_usage_test.rs b/crates/blockifier/src/fee/gas_usage_test.rs index b83517acd83..1d89c913dbe 100644 --- a/crates/blockifier/src/fee/gas_usage_test.rs +++ b/crates/blockifier/src/fee/gas_usage_test.rs @@ -205,9 +205,8 @@ fn test_get_message_segment_length( #[rstest] fn test_compute_discounted_gas_from_gas_vector() { - let tx_context = BlockContext::create_for_testing() - .to_tx_context(&account_invoke_tx(invoke_tx_args! {})) - .unwrap(); + let tx_context = + BlockContext::create_for_testing().to_tx_context(&account_invoke_tx(invoke_tx_args! {})); let gas_usage = GasVector { l1_gas: 100, l1_data_gas: 2, ..Default::default() }; let actual_result = compute_discounted_gas_from_gas_vector(&gas_usage, &tx_context); diff --git a/crates/blockifier/src/test_utils/prices.rs b/crates/blockifier/src/test_utils/prices.rs index 0cd544c4a89..f605d42ff42 100644 --- a/crates/blockifier/src/test_utils/prices.rs +++ b/crates/blockifier/src/test_utils/prices.rs @@ -72,11 +72,7 @@ fn fee_transfer_resources( state, &mut ExecutionResources::default(), &mut EntryPointExecutionContext::new( - Arc::new( - block_context - .to_tx_context(&account_invoke_tx(InvokeTxArgs::default())) - .unwrap(), - ), + Arc::new(block_context.to_tx_context(&account_invoke_tx(InvokeTxArgs::default()))), ExecutionMode::Execute, false, ), diff --git a/crates/blockifier/src/transaction/account_transaction.rs b/crates/blockifier/src/transaction/account_transaction.rs index c15939e1432..57922613429 100644 --- a/crates/blockifier/src/transaction/account_transaction.rs +++ b/crates/blockifier/src/transaction/account_transaction.rs @@ -33,7 +33,6 @@ use crate::transaction::constants; use crate::transaction::errors::{ TransactionExecutionError, TransactionFeeError, - TransactionInfoCreationError, TransactionPreValidationError, }; use crate::transaction::objects::{ @@ -681,7 +680,7 @@ impl ExecutableTransaction for AccountTransaction { block_context: &BlockContext, execution_flags: ExecutionFlags, ) -> TransactionExecutionResult { - let tx_context = Arc::new(block_context.to_tx_context(self)?); + let tx_context = Arc::new(block_context.to_tx_context(self)); self.verify_tx_version(tx_context.tx_info.version())?; // Nonce and fee check should be done before running user code. @@ -738,8 +737,7 @@ impl ExecutableTransaction for AccountTransaction { } impl TransactionInfoCreator for AccountTransaction { - // TODO(Nimrod): This function should return `TransactionInfo` without a result. - fn create_tx_info(&self) -> Result { + fn create_tx_info(&self) -> TransactionInfo { match self { Self::Declare(tx) => tx.create_tx_info(), Self::DeployAccount(tx) => tx.create_tx_info(), diff --git a/crates/blockifier/src/transaction/account_transactions_test.rs b/crates/blockifier/src/transaction/account_transactions_test.rs index dd957479b73..d33063c6bf1 100644 --- a/crates/blockifier/src/transaction/account_transactions_test.rs +++ b/crates/blockifier/src/transaction/account_transactions_test.rs @@ -171,7 +171,7 @@ fn test_fee_enforcement( ); let account_tx = AccountTransaction::DeployAccount(deploy_account_tx); - let enforce_fee = account_tx.create_tx_info().unwrap().enforce_fee(); + let enforce_fee = account_tx.create_tx_info().enforce_fee(); let result = account_tx.execute(state, &block_context, true, true); assert_eq!(result.is_err(), enforce_fee); } @@ -652,7 +652,7 @@ fn test_fail_declare(block_context: BlockContext, max_fee: Fee) { ); // Fail execution, assert nonce and balance are unchanged. - let tx_info = declare_account_tx.create_tx_info().unwrap(); + let tx_info = declare_account_tx.create_tx_info(); let initial_balance = state .get_fee_token_balance(account_address, chain_info.fee_token_address(&tx_info.fee_type())) .unwrap(); @@ -929,7 +929,7 @@ fn test_max_fee_to_max_steps_conversion( resource_bounds: l1_resource_bounds(actual_gas_used, actual_strk_gas_price.into()), nonce: nonce_manager.next(account_address), }); - let tx_context1 = Arc::new(block_context.to_tx_context(&account_tx1).unwrap()); + let tx_context1 = Arc::new(block_context.to_tx_context(&account_tx1)); let execution_context1 = EntryPointExecutionContext::new_invoke(tx_context1, true); 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(); @@ -949,7 +949,7 @@ fn test_max_fee_to_max_steps_conversion( resource_bounds: l1_resource_bounds(2 * actual_gas_used, actual_strk_gas_price.into()), nonce: nonce_manager.next(account_address), }); - let tx_context2 = Arc::new(block_context.to_tx_context(&account_tx2).unwrap()); + let tx_context2 = Arc::new(block_context.to_tx_context(&account_tx2)); let execution_context2 = EntryPointExecutionContext::new_invoke(tx_context2, true); 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(); diff --git a/crates/blockifier/src/transaction/errors.rs b/crates/blockifier/src/transaction/errors.rs index 693c7c65087..cbd9d380857 100644 --- a/crates/blockifier/src/transaction/errors.rs +++ b/crates/blockifier/src/transaction/errors.rs @@ -112,8 +112,6 @@ pub enum TransactionExecutionError { InvalidSegmentStructure(usize, usize), #[error(transparent)] ProgramError(#[from] ProgramError), - #[error(transparent)] - TransactionInfoCreationError(#[from] TransactionInfoCreationError), } #[derive(Debug, Error)] @@ -140,12 +138,3 @@ pub enum NumericConversionError { #[error("Conversion of {0} to u128 unsuccessful.")] U128ToUsizeError(u128), } - -// TODO(Nimrod): Delete this error once `create_tx_info` stops returning a `Result`. -#[derive(Debug, Error)] -pub enum TransactionInfoCreationError { - #[error("Invalid ResourceMapping combination was given: {0}")] - InvalidResourceMapping(String), - #[error(transparent)] - StarknetAPIError(#[from] StarknetApiError), -} diff --git a/crates/blockifier/src/transaction/objects.rs b/crates/blockifier/src/transaction/objects.rs index cd8d1820185..4769eb6072b 100644 --- a/crates/blockifier/src/transaction/objects.rs +++ b/crates/blockifier/src/transaction/objects.rs @@ -37,7 +37,6 @@ use crate::transaction::constants; use crate::transaction::errors::{ TransactionExecutionError, TransactionFeeError, - TransactionInfoCreationError, TransactionPreValidationError, }; use crate::utils::{u128_from_usize, usize_from_u128}; @@ -565,5 +564,5 @@ pub enum FeeType { } pub trait TransactionInfoCreator { - fn create_tx_info(&self) -> Result; + fn create_tx_info(&self) -> TransactionInfo; } diff --git a/crates/blockifier/src/transaction/post_execution_test.rs b/crates/blockifier/src/transaction/post_execution_test.rs index 0c5d9c10cc2..95d7f7573de 100644 --- a/crates/blockifier/src/transaction/post_execution_test.rs +++ b/crates/blockifier/src/transaction/post_execution_test.rs @@ -112,7 +112,7 @@ fn test_revert_on_overdraft( resource_bounds: max_resource_bounds.clone(), nonce: nonce_manager.next(account_address), }); - let tx_info = approve_tx.create_tx_info().unwrap(); + let tx_info = approve_tx.create_tx_info(); let approval_execution_info = approve_tx.execute(&mut state, &block_context, true, true).unwrap(); assert!(!approval_execution_info.is_reverted()); diff --git a/crates/blockifier/src/transaction/transaction_execution.rs b/crates/blockifier/src/transaction/transaction_execution.rs index f11915267b5..2d4fee1fb2f 100644 --- a/crates/blockifier/src/transaction/transaction_execution.rs +++ b/crates/blockifier/src/transaction/transaction_execution.rs @@ -12,7 +12,7 @@ use crate::fee::actual_cost::TransactionReceipt; use crate::state::cached_state::TransactionalState; use crate::state::state_api::UpdatableState; use crate::transaction::account_transaction::AccountTransaction; -use crate::transaction::errors::{TransactionFeeError, TransactionInfoCreationError}; +use crate::transaction::errors::TransactionFeeError; use crate::transaction::objects::{ TransactionExecutionInfo, TransactionExecutionResult, @@ -100,7 +100,7 @@ impl Transaction { } impl TransactionInfoCreator for Transaction { - fn create_tx_info(&self) -> Result { + fn create_tx_info(&self) -> TransactionInfo { match self { Self::AccountTransaction(account_tx) => account_tx.create_tx_info(), Self::L1HandlerTransaction(l1_handler_tx) => l1_handler_tx.create_tx_info(), @@ -115,7 +115,7 @@ impl ExecutableTransaction for L1HandlerTransaction { block_context: &BlockContext, _execution_flags: ExecutionFlags, ) -> TransactionExecutionResult { - let tx_context = Arc::new(block_context.to_tx_context(self)?); + let tx_context = Arc::new(block_context.to_tx_context(self)); let mut execution_resources = ExecutionResources::default(); let mut context = EntryPointExecutionContext::new_invoke(tx_context.clone(), true); @@ -184,7 +184,7 @@ impl ExecutableTransaction for Transaction { let tx_execution_summary = tx_execution_info.summarize(); let mut tx_state_changes_keys = state.get_actual_state_changes()?.into_keys(); tx_state_changes_keys.update_sequencer_key_in_storage( - &block_context.to_tx_context(self)?, + &block_context.to_tx_context(self), &tx_execution_info, concurrency_mode, ); diff --git a/crates/blockifier/src/transaction/transactions.rs b/crates/blockifier/src/transaction/transactions.rs index 098112ecdb7..8ee1412eec0 100644 --- a/crates/blockifier/src/transaction/transactions.rs +++ b/crates/blockifier/src/transaction/transactions.rs @@ -30,7 +30,7 @@ use crate::state::cached_state::TransactionalState; use crate::state::errors::StateError; use crate::state::state_api::{State, UpdatableState}; use crate::transaction::constants; -use crate::transaction::errors::{TransactionExecutionError, TransactionInfoCreationError}; +use crate::transaction::errors::TransactionExecutionError; use crate::transaction::objects::{ CommonAccountFields, CurrentTransactionInfo, @@ -268,7 +268,7 @@ impl Executable for DeclareTransaction { } impl TransactionInfoCreator for DeclareTransaction { - fn create_tx_info(&self) -> Result { + fn create_tx_info(&self) -> TransactionInfo { // TODO(Nir, 01/11/2023): Consider to move this (from all get_tx_info methods). let common_fields = CommonAccountFields { transaction_hash: self.tx_hash(), @@ -282,19 +282,19 @@ impl TransactionInfoCreator for DeclareTransaction { match &self.tx { starknet_api::transaction::DeclareTransaction::V0(tx) | starknet_api::transaction::DeclareTransaction::V1(tx) => { - Ok(TransactionInfo::Deprecated(DeprecatedTransactionInfo { + TransactionInfo::Deprecated(DeprecatedTransactionInfo { common_fields, max_fee: tx.max_fee, - })) + }) } starknet_api::transaction::DeclareTransaction::V2(tx) => { - Ok(TransactionInfo::Deprecated(DeprecatedTransactionInfo { + TransactionInfo::Deprecated(DeprecatedTransactionInfo { common_fields, max_fee: tx.max_fee, - })) + }) } starknet_api::transaction::DeclareTransaction::V3(tx) => { - Ok(TransactionInfo::Current(CurrentTransactionInfo { + TransactionInfo::Current(CurrentTransactionInfo { common_fields, resource_bounds: tx.resource_bounds.clone(), tip: tx.tip, @@ -302,7 +302,7 @@ impl TransactionInfoCreator for DeclareTransaction { fee_data_availability_mode: tx.fee_data_availability_mode, paymaster_data: tx.paymaster_data.clone(), account_deployment_data: tx.account_deployment_data.clone(), - })) + }) } } } @@ -391,7 +391,7 @@ impl Executable for DeployAccountTransaction { } impl TransactionInfoCreator for DeployAccountTransaction { - fn create_tx_info(&self) -> Result { + fn create_tx_info(&self) -> TransactionInfo { let common_fields = CommonAccountFields { transaction_hash: self.tx_hash(), version: self.version(), @@ -403,13 +403,13 @@ impl TransactionInfoCreator for DeployAccountTransaction { match &self.tx() { starknet_api::transaction::DeployAccountTransaction::V1(tx) => { - Ok(TransactionInfo::Deprecated(DeprecatedTransactionInfo { + TransactionInfo::Deprecated(DeprecatedTransactionInfo { common_fields, max_fee: tx.max_fee, - })) + }) } starknet_api::transaction::DeployAccountTransaction::V3(tx) => { - Ok(TransactionInfo::Current(CurrentTransactionInfo { + TransactionInfo::Current(CurrentTransactionInfo { common_fields, resource_bounds: tx.resource_bounds.clone(), tip: tx.tip, @@ -417,7 +417,7 @@ impl TransactionInfoCreator for DeployAccountTransaction { fee_data_availability_mode: tx.fee_data_availability_mode, paymaster_data: tx.paymaster_data.clone(), account_deployment_data: AccountDeploymentData::default(), - })) + }) } } } @@ -509,7 +509,7 @@ impl Executable for InvokeTransaction { } impl TransactionInfoCreator for InvokeTransaction { - fn create_tx_info(&self) -> Result { + fn create_tx_info(&self) -> TransactionInfo { let common_fields = CommonAccountFields { transaction_hash: self.tx_hash(), version: self.version(), @@ -521,19 +521,19 @@ impl TransactionInfoCreator for InvokeTransaction { match &self.tx() { starknet_api::transaction::InvokeTransaction::V0(tx) => { - Ok(TransactionInfo::Deprecated(DeprecatedTransactionInfo { + TransactionInfo::Deprecated(DeprecatedTransactionInfo { common_fields, max_fee: tx.max_fee, - })) + }) } starknet_api::transaction::InvokeTransaction::V1(tx) => { - Ok(TransactionInfo::Deprecated(DeprecatedTransactionInfo { + TransactionInfo::Deprecated(DeprecatedTransactionInfo { common_fields, max_fee: tx.max_fee, - })) + }) } starknet_api::transaction::InvokeTransaction::V3(tx) => { - Ok(TransactionInfo::Current(CurrentTransactionInfo { + TransactionInfo::Current(CurrentTransactionInfo { common_fields, resource_bounds: tx.resource_bounds.clone(), tip: tx.tip, @@ -541,7 +541,7 @@ impl TransactionInfoCreator for InvokeTransaction { fee_data_availability_mode: tx.fee_data_availability_mode, paymaster_data: tx.paymaster_data.clone(), account_deployment_data: tx.account_deployment_data.clone(), - })) + }) } } } @@ -607,8 +607,8 @@ impl Executable for L1HandlerTransaction { } impl TransactionInfoCreator for L1HandlerTransaction { - fn create_tx_info(&self) -> Result { - Ok(TransactionInfo::Deprecated(DeprecatedTransactionInfo { + fn create_tx_info(&self) -> TransactionInfo { + TransactionInfo::Deprecated(DeprecatedTransactionInfo { common_fields: CommonAccountFields { transaction_hash: self.tx_hash, version: self.tx.version, @@ -618,6 +618,6 @@ impl TransactionInfoCreator for L1HandlerTransaction { only_query: false, }, max_fee: Fee::default(), - })) + }) } } diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index 1c1b3c53742..a865a1b6e8b 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -422,7 +422,7 @@ fn test_invoke_tx( let sender_address = invoke_tx.sender_address(); let account_tx = AccountTransaction::Invoke(invoke_tx); - let tx_context = block_context.to_tx_context(&account_tx).unwrap(); + let tx_context = block_context.to_tx_context(&account_tx); let actual_execution_info = account_tx.execute(state, block_context, true, true).unwrap(); @@ -792,7 +792,7 @@ fn assert_failure_if_resource_bounds_exceed_balance( block_context: &BlockContext, invalid_tx: AccountTransaction, ) { - match block_context.to_tx_context(&invalid_tx).unwrap().tx_info { + match block_context.to_tx_context(&invalid_tx).tx_info { TransactionInfo::Deprecated(context) => { assert_matches!( invalid_tx.execute(state, block_context, true, true).unwrap_err(), @@ -1035,7 +1035,7 @@ fn test_invalid_nonce( let invalid_nonce = nonce!(1_u8); let invalid_tx = account_invoke_tx(invoke_tx_args! { nonce: invalid_nonce, ..valid_invoke_tx_args.clone() }); - let invalid_tx_context = block_context.to_tx_context(&invalid_tx).unwrap(); + let invalid_tx_context = block_context.to_tx_context(&invalid_tx); let pre_validation_err = invalid_tx .perform_pre_validation_stage(&mut transactional_state, &invalid_tx_context, false, true) .unwrap_err(); @@ -1055,7 +1055,7 @@ fn test_invalid_nonce( let valid_tx = account_invoke_tx(invoke_tx_args! { nonce: valid_nonce, ..valid_invoke_tx_args.clone() }); - let valid_tx_context = block_context.to_tx_context(&valid_tx).unwrap(); + let valid_tx_context = block_context.to_tx_context(&valid_tx); valid_tx .perform_pre_validation_stage(&mut transactional_state, &valid_tx_context, false, false) .unwrap(); @@ -1064,7 +1064,7 @@ fn test_invalid_nonce( let invalid_nonce = nonce!(0_u8); let invalid_tx = account_invoke_tx(invoke_tx_args! { nonce: invalid_nonce, ..valid_invoke_tx_args.clone() }); - let invalid_tx_context = block_context.to_tx_context(&invalid_tx).unwrap(); + let invalid_tx_context = block_context.to_tx_context(&invalid_tx); let pre_validation_err = invalid_tx .perform_pre_validation_stage(&mut transactional_state, &invalid_tx_context, false, false) .unwrap_err(); @@ -1180,7 +1180,7 @@ fn test_declare_tx( undeclared_class_hash == class_hash ); let fee_type = &account_tx.fee_type(); - let tx_context = &block_context.to_tx_context(&account_tx).unwrap(); + let tx_context = &block_context.to_tx_context(&account_tx); let actual_execution_info = account_tx.execute(state, block_context, true, true).unwrap(); // Build expected validate call info. @@ -1323,7 +1323,7 @@ fn test_deploy_account_tx( let account_tx = AccountTransaction::DeployAccount(deploy_account); let fee_type = &account_tx.fee_type(); - let tx_context = &block_context.to_tx_context(&account_tx).unwrap(); + let tx_context = &block_context.to_tx_context(&account_tx); let actual_execution_info = account_tx.execute(state, block_context, true, true).unwrap(); // Build expected validate call info. @@ -1465,7 +1465,7 @@ fn test_fail_deploy_account_undeclared_class_hash( deploy_account_tx_args! {resource_bounds: max_resource_bounds, class_hash: undeclared_hash }, &mut nonce_manager, ); - let tx_context = block_context.to_tx_context(&deploy_account).unwrap(); + let tx_context = block_context.to_tx_context(&deploy_account); let fee_type = tx_context.tx_info.fee_type(); // Fund account, so as not to fail pre-validation. diff --git a/crates/native_blockifier/src/py_validator.rs b/crates/native_blockifier/src/py_validator.rs index 29340474467..8398e48c1a5 100644 --- a/crates/native_blockifier/src/py_validator.rs +++ b/crates/native_blockifier/src/py_validator.rs @@ -91,7 +91,7 @@ impl PyValidator { if account_tx.tx_type() != TransactionType::InvokeFunction { return Ok(false); } - let tx_info = account_tx.create_tx_info()?; + let tx_info = account_tx.create_tx_info(); let nonce = self.stateful_validator.get_nonce(tx_info.sender_address())?; let deploy_account_not_processed =