diff --git a/crates/native_blockifier/src/py_block_executor.rs b/crates/native_blockifier/src/py_block_executor.rs index 6954fb2b8d..1bd211fea3 100644 --- a/crates/native_blockifier/src/py_block_executor.rs +++ b/crates/native_blockifier/src/py_block_executor.rs @@ -27,13 +27,12 @@ use crate::errors::{ NativeBlockifierResult, }; use crate::py_state_diff::{PyBlockInfo, PyStateDiff}; -use crate::py_transaction::{py_tx, PyClassInfo}; +use crate::py_transaction::{get_py_tx_type, py_tx, PyClassInfo, PY_TX_PARSING_ERR}; use crate::py_transaction_execution_info::PyBouncerConfig; use crate::py_utils::{int_to_chain_id, PyFelt}; use crate::state_readers::papyrus_state::PapyrusReader; use crate::storage::{PapyrusStorage, Storage, StorageConfig}; -pub(crate) type RawTransactionExecutionInfo = Vec; pub(crate) type PyVisitedSegmentsMapping = Vec<(PyFelt, Vec)>; #[cfg(test)] @@ -164,8 +163,8 @@ impl PyBlockExecutor { optional_py_class_info: Option, ) -> NativeBlockifierResult> { let charge_fee = true; - let tx_type: String = tx.getattr("tx_type")?.getattr("name")?.extract()?; - let tx: Transaction = py_tx(tx, optional_py_class_info)?; + 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, charge_fee)?; let typed_tx_execution_info = TypedTransactionExecutionInfo { info: ThinTransactionExecutionInfo::from_tx_execution_info( @@ -177,39 +176,14 @@ impl PyBlockExecutor { // Convert to PyBytes: let raw_tx_execution_info = Python::with_gil(|py| { - let bytes_tx_execution_info = serde_json::to_vec(&typed_tx_execution_info).unwrap(); + let bytes_tx_execution_info = serde_json::to_vec(&typed_tx_execution_info) + .expect("Failed serializing execution info."); PyBytes::new(py, &bytes_tx_execution_info).into() }); Ok(raw_tx_execution_info) } - #[pyo3(signature = (txs_with_class_infos))] - pub fn execute_txs( - &mut self, - txs_with_class_infos: Vec<(&PyAny, Option)>, - ) -> NativeBlockifierResult> { - let charge_fee = true; - let mut result_vec = Vec::new(); - - for (tx, optional_py_class_info) in txs_with_class_infos.into_iter() { - let tx_type: String = tx.getattr("tx_type")?.getattr("name")?.extract()?; - let tx: Transaction = py_tx(tx, optional_py_class_info)?; - let tx_execution_info = self.tx_executor().execute(&tx, charge_fee)?; - let typed_tx_execution_info = TypedTransactionExecutionInfo { - info: ThinTransactionExecutionInfo::from_tx_execution_info( - &self.tx_executor().block_context, - tx_execution_info, - ), - tx_type, - }; - let raw_tx_execution_info = serde_json::to_vec(&typed_tx_execution_info)?; - result_vec.push(raw_tx_execution_info); - } - - Ok(result_vec) - } - /// Returns the state diff and a list of contract class hash with the corresponding list of /// visited segment values. pub fn finalize(&mut self) -> NativeBlockifierResult<(PyStateDiff, PyVisitedSegmentsMapping)> { diff --git a/crates/native_blockifier/src/py_transaction.rs b/crates/native_blockifier/src/py_transaction.rs index 085fe8c836..e793cd5144 100644 --- a/crates/native_blockifier/src/py_transaction.rs +++ b/crates/native_blockifier/src/py_transaction.rs @@ -17,6 +17,8 @@ use crate::py_deploy_account::py_deploy_account; use crate::py_invoke_function::py_invoke_function; use crate::py_l1_handler::py_l1_handler; +pub(crate) const PY_TX_PARSING_ERR: &str = "Failed parsing Py transaction."; + // Structs. #[derive(Clone, Eq, Ord, PartialEq, PartialOrd)] @@ -122,7 +124,7 @@ pub fn py_tx( tx: &PyAny, optional_py_class_info: Option, ) -> NativeBlockifierResult { - let tx_type: &str = tx.getattr("tx_type")?.getattr("name")?.extract()?; + let tx_type = get_py_tx_type(tx)?; let tx_type: TransactionType = tx_type.parse().map_err(NativeBlockifierInputError::ParseError)?; @@ -141,6 +143,11 @@ pub fn py_tx( TransactionType::L1Handler => py_l1_handler(tx)?.into(), }) } + +pub fn get_py_tx_type(tx: &PyAny) -> NativeBlockifierResult<&str> { + Ok(tx.getattr("tx_type")?.getattr("name")?.extract()?) +} + #[derive(FromPyObject)] pub struct PyClassInfo { raw_contract_class: String, diff --git a/crates/native_blockifier/src/py_validator.rs b/crates/native_blockifier/src/py_validator.rs index d681735b2b..635b0bd52e 100644 --- a/crates/native_blockifier/src/py_validator.rs +++ b/crates/native_blockifier/src/py_validator.rs @@ -10,7 +10,7 @@ use starknet_api::transaction::TransactionHash; use crate::errors::NativeBlockifierResult; use crate::py_block_executor::{into_block_context_args, PyGeneralConfig}; use crate::py_state_diff::PyBlockInfo; -use crate::py_transaction::{py_account_tx, PyClassInfo}; +use crate::py_transaction::{py_account_tx, PyClassInfo, PY_TX_PARSING_ERR}; use crate::py_utils::PyFelt; use crate::state_readers::py_state_reader::PyStateReader; @@ -65,7 +65,7 @@ impl PyValidator { optional_py_class_info: Option, deploy_account_tx_hash: Option, ) -> NativeBlockifierResult<()> { - let account_tx = py_account_tx(tx, optional_py_class_info)?; + let account_tx = py_account_tx(tx, optional_py_class_info).expect(PY_TX_PARSING_ERR); let deploy_account_tx_hash = deploy_account_tx_hash.map(|hash| TransactionHash(hash.0)); self.stateful_validator.perform_validations(account_tx, deploy_account_tx_hash)?;