diff --git a/crates/native_blockifier/src/py_block_executor.rs b/crates/native_blockifier/src/py_block_executor.rs index b4ae3950cc..47b3f64a0a 100644 --- a/crates/native_blockifier/src/py_block_executor.rs +++ b/crates/native_blockifier/src/py_block_executor.rs @@ -4,14 +4,18 @@ use std::sync::Arc; use blockifier::block::{BlockInfo, GasPrices}; use blockifier::context::{BlockContext, ChainInfo, FeeTokenAddresses}; use blockifier::state::cached_state::{GlobalContractCache, GLOBAL_CONTRACT_CACHE_SIZE_FOR_TEST}; +use blockifier::transaction::objects::TransactionExecutionInfo; +use blockifier::transaction::transaction_execution::Transaction; use blockifier::versioned_constants::VersionedConstants; use pyo3::prelude::*; +use serde::Serialize; use starknet_api::block::{BlockNumber, BlockTimestamp}; use starknet_api::core::{ChainId, ContractAddress}; use starknet_api::hash::StarkFelt; use crate::errors::{NativeBlockifierError, NativeBlockifierResult}; use crate::py_state_diff::{PyBlockInfo, PyStateDiff}; +use crate::py_transaction::py_tx; use crate::py_transaction_execution_info::PyBouncerInfo; use crate::py_utils::{int_to_chain_id, py_attr, versioned_constants_with_overrides, PyFelt}; use crate::state_readers::papyrus_state::PapyrusReader; @@ -22,6 +26,14 @@ use crate::transaction_executor::{RawTransactionExecutionInfo, TransactionExecut #[path = "py_block_executor_test.rs"] mod py_block_executor_test; +#[pyclass] +#[derive(Debug, Serialize)] +pub(crate) struct TypedTransactionExecutionInfo { + #[serde(flatten)] + pub info: TransactionExecutionInfo, + pub tx_type: String, +} + #[pyclass] pub struct PyBlockExecutor { pub general_config: PyGeneralConfig, @@ -90,7 +102,13 @@ impl PyBlockExecutor { raw_contract_class: Option<&str>, ) -> NativeBlockifierResult<(RawTransactionExecutionInfo, PyBouncerInfo)> { let charge_fee = true; - self.tx_executor().execute(tx, raw_contract_class, charge_fee) + let tx_type: &str = tx.getattr("tx_type")?.getattr("name")?.extract()?; + let tx: Transaction = py_tx(tx, raw_contract_class)?; + let (tx_execution_info, py_bouncer_info) = self.tx_executor().execute(tx, charge_fee)?; + let typed_tx_execution_info = + TypedTransactionExecutionInfo { info: tx_execution_info, tx_type: tx_type.to_string() }; + let raw_tx_execution_info = serde_json::to_vec(&typed_tx_execution_info)?; + Ok((raw_tx_execution_info, py_bouncer_info)) } /// Returns the state diff and a list of contract class hash with the corresponding list of diff --git a/crates/native_blockifier/src/py_validator.rs b/crates/native_blockifier/src/py_validator.rs index 54ca0cc4d7..277f47ef1c 100644 --- a/crates/native_blockifier/src/py_validator.rs +++ b/crates/native_blockifier/src/py_validator.rs @@ -12,9 +12,9 @@ use starknet_api::core::Nonce; use starknet_api::hash::StarkFelt; use crate::errors::NativeBlockifierResult; -use crate::py_block_executor::PyGeneralConfig; +use crate::py_block_executor::{PyGeneralConfig, TypedTransactionExecutionInfo}; use crate::py_state_diff::PyBlockInfo; -use crate::py_transaction::py_account_tx; +use crate::py_transaction::{py_account_tx, py_tx}; use crate::py_transaction_execution_info::PyBouncerInfo; use crate::py_utils::{versioned_constants_with_overrides, PyFelt}; use crate::state_readers::py_state_reader::PyStateReader; @@ -129,7 +129,14 @@ impl PyValidator { raw_contract_class: Option<&str>, ) -> NativeBlockifierResult<(RawTransactionExecutionInfo, PyBouncerInfo)> { let limit_execution_steps_by_resource_bounds = true; - self.tx_executor.execute(tx, raw_contract_class, limit_execution_steps_by_resource_bounds) + let tx_type: &str = tx.getattr("tx_type")?.getattr("name")?.extract()?; + let tx: Transaction = py_tx(tx, raw_contract_class)?; + let (tx_execution_info, py_bouncer_info) = + self.tx_executor.execute(tx, limit_execution_steps_by_resource_bounds)?; + let typed_tx_execution_info = + TypedTransactionExecutionInfo { info: tx_execution_info, tx_type: tx_type.to_string() }; + let raw_tx_execution_info = serde_json::to_vec(&typed_tx_execution_info)?; + Ok((raw_tx_execution_info, py_bouncer_info)) } } diff --git a/crates/native_blockifier/src/transaction_executor.rs b/crates/native_blockifier/src/transaction_executor.rs index 2bf8c29cc4..26cb7315bd 100644 --- a/crates/native_blockifier/src/transaction_executor.rs +++ b/crates/native_blockifier/src/transaction_executor.rs @@ -18,27 +18,16 @@ use blockifier::transaction::transactions::{ExecutableTransaction, ValidatableTr use blockifier::versioned_constants::VersionedConstants; use cairo_vm::vm::runners::builtin_runner::HASH_BUILTIN_NAME; use cairo_vm::vm::runners::cairo_runner::ExecutionResources as VmExecutionResources; -use pyo3::prelude::*; -use serde::Serialize; use starknet_api::core::ClassHash; use crate::errors::{NativeBlockifierError, NativeBlockifierResult}; use crate::py_block_executor::{into_block_context, PyGeneralConfig}; use crate::py_state_diff::{PyBlockInfo, PyStateDiff}; -use crate::py_transaction::py_tx; use crate::py_transaction_execution_info::PyBouncerInfo; use crate::py_utils::PyFelt; pub(crate) type RawTransactionExecutionInfo = Vec; -#[pyclass] -#[derive(Debug, Serialize)] -pub(crate) struct TypedTransactionExecutionInfo { - #[serde(flatten)] - info: TransactionExecutionInfo, - tx_type: String, -} - pub struct TransactionExecutor { pub block_context: BlockContext, @@ -81,12 +70,10 @@ impl TransactionExecutor { /// (used for counting purposes). pub fn execute( &mut self, - tx: &PyAny, - raw_contract_class: Option<&str>, + // tx: &PyAny, + tx: Transaction, charge_fee: bool, - ) -> NativeBlockifierResult<(RawTransactionExecutionInfo, PyBouncerInfo)> { - let tx_type: &str = tx.getattr("tx_type")?.getattr("name")?.extract()?; - let tx: Transaction = py_tx(tx, raw_contract_class)?; + ) -> NativeBlockifierResult<(TransactionExecutionInfo, PyBouncerInfo)> { let l1_handler_payload_size: usize = if let Transaction::L1HandlerTransaction(l1_handler_tx) = &tx { l1_handler_tx.payload_size() @@ -144,14 +131,7 @@ impl TransactionExecutor { self.staged_for_commit_state = Some( transactional_state.stage(tx_executed_class_hashes, tx_visited_storage_entries), ); - - let typed_tx_execution_info = TypedTransactionExecutionInfo { - info: tx_execution_info, - tx_type: tx_type.to_string(), - }; - let raw_tx_execution_info = serde_json::to_vec(&typed_tx_execution_info)?; - - Ok((raw_tx_execution_info, py_bouncer_info)) + Ok((tx_execution_info, py_bouncer_info)) } Err(error) => { transactional_state.abort();