From 550ac05753fcc4a88b74c62e3b886d24e9d0df11 Mon Sep 17 00:00:00 2001 From: Yonatan Iluz Date: Thu, 13 Jun 2024 19:43:56 +0300 Subject: [PATCH] chore(native_blockifier): delete TypedTransactionExecutionInfo --- .../src/concurrency/worker_logic_test.rs | 4 +- .../src/py_block_executor.rs | 46 +++---------------- 2 files changed, 9 insertions(+), 41 deletions(-) diff --git a/crates/blockifier/src/concurrency/worker_logic_test.rs b/crates/blockifier/src/concurrency/worker_logic_test.rs index 6db82ab464..eb36cd983b 100644 --- a/crates/blockifier/src/concurrency/worker_logic_test.rs +++ b/crates/blockifier/src/concurrency/worker_logic_test.rs @@ -469,8 +469,8 @@ use rstest::rstest; #[rstest] #[case::no_overflow(Fee(50_u128), stark_felt!(100_u128), StarkFelt::ZERO)] -#[case::overflow(Fee(150_u128), stark_felt!(u128::max_value()), stark_felt!(5_u128))] -#[case::overflow_edge_case(Fee(500_u128), stark_felt!(u128::max_value()), stark_felt!(u128::max_value()-1))] +#[case::overflow(Fee(150_u128), stark_felt!(u128::MAX), stark_felt!(5_u128))] +#[case::overflow_edge_case(Fee(500_u128), stark_felt!(u128::MAX), stark_felt!(u128::MAX-1))] pub fn test_add_fee_to_sequencer_balance( #[case] actual_fee: Fee, #[case] sequencer_balance_low: StarkFelt, diff --git a/crates/native_blockifier/src/py_block_executor.rs b/crates/native_blockifier/src/py_block_executor.rs index 0142e76130..871ef4216e 100644 --- a/crates/native_blockifier/src/py_block_executor.rs +++ b/crates/native_blockifier/src/py_block_executor.rs @@ -23,7 +23,7 @@ use starknet_api::transaction::Fee; use crate::errors::{NativeBlockifierError, NativeBlockifierResult}; use crate::py_objects::{PyBouncerConfig, PyConcurrencyConfig}; use crate::py_state_diff::{PyBlockInfo, PyStateDiff}; -use crate::py_transaction::{get_py_tx_type, py_tx, PyClassInfo, PY_TX_PARSING_ERR}; +use crate::py_transaction::{py_tx, PyClassInfo, PY_TX_PARSING_ERR}; use crate::py_utils::{int_to_chain_id, into_block_number_hash_pair, PyFelt}; use crate::state_readers::papyrus_state::PapyrusReader; use crate::storage::{PapyrusStorage, Storage, StorageConfig}; @@ -71,31 +71,6 @@ impl ThinTransactionExecutionInfo { total_gas: tx_execution_info.transaction_receipt.gas, } } -} - -#[pyclass] -#[derive(Debug, Serialize)] -pub(crate) struct TypedTransactionExecutionInfo { - #[serde(flatten)] - pub info: ThinTransactionExecutionInfo, - pub tx_type: String, -} - -impl TypedTransactionExecutionInfo { - pub fn from_tx_execution_info( - block_context: &BlockContext, - tx_execution_info: TransactionExecutionInfo, - tx_type: String, - ) -> Self { - TypedTransactionExecutionInfo { - info: ThinTransactionExecutionInfo::from_tx_execution_info( - block_context, - tx_execution_info, - ), - tx_type, - } - } - pub fn serialize(self) -> RawTransactionExecutionResult { serde_json::to_vec(&self).expect(RESULT_SERIALIZE_ERR) } @@ -194,13 +169,11 @@ impl PyBlockExecutor { tx: &PyAny, optional_py_class_info: Option, ) -> NativeBlockifierResult> { - let tx_type: String = get_py_tx_type(tx).expect(PY_TX_PARSING_ERR).to_string(); let tx: Transaction = py_tx(tx, optional_py_class_info).expect(PY_TX_PARSING_ERR); let tx_execution_info = self.tx_executor().execute(&tx)?; - let typed_tx_execution_info = TypedTransactionExecutionInfo::from_tx_execution_info( + let typed_tx_execution_info = ThinTransactionExecutionInfo::from_tx_execution_info( &self.tx_executor().block_context, tx_execution_info, - tx_type, ); // Serialize and convert to PyBytes. @@ -217,15 +190,12 @@ impl PyBlockExecutor { txs_with_class_infos: Vec<(&PyAny, Option)>, ) -> Py { // Parse Py transactions. - let (tx_types, txs): (Vec, Vec) = txs_with_class_infos + let txs: Vec = txs_with_class_infos .into_iter() .map(|(tx, optional_py_class_info)| { - ( - get_py_tx_type(tx).expect(PY_TX_PARSING_ERR).to_string(), - py_tx(tx, optional_py_class_info).expect(PY_TX_PARSING_ERR), - ) + py_tx(tx, optional_py_class_info).expect(PY_TX_PARSING_ERR) }) - .unzip(); + .collect(); // Run. let results = self.tx_executor().execute_txs(&txs); @@ -236,14 +206,12 @@ impl PyBlockExecutor { let serialized_results: Vec<(bool, RawTransactionExecutionResult)> = results .into_iter() // Note: there might be less results than txs (if there is no room for all of them). - .zip(tx_types) - .map(|(result, tx_type)| match result { + .map(|result| match result { Ok(tx_execution_info) => ( true, - TypedTransactionExecutionInfo::from_tx_execution_info( + ThinTransactionExecutionInfo::from_tx_execution_info( block_context, tx_execution_info, - tx_type, ) .serialize(), ),