diff --git a/rpc-state-reader/src/execution.rs b/rpc-state-reader/src/execution.rs index b66a7ab..53d4b63 100644 --- a/rpc-state-reader/src/execution.rs +++ b/rpc-state-reader/src/execution.rs @@ -3,9 +3,16 @@ use crate::{ reader::{RpcChain, RpcStateReader}, }; use blockifier::{ - bouncer::BouncerConfig, context::{BlockContext, ChainInfo, FeeTokenAddresses}, state::{cached_state::CachedState, state_api::StateReader}, test_utils::MAX_FEE, transaction::{ - objects::{TransactionExecutionInfo, TransactionExecutionResult}, transaction_execution::Transaction as BlockiTransaction, transactions::ExecutableTransaction - }, versioned_constants::{VersionedConstants, VersionedConstantsOverrides} + bouncer::BouncerConfig, + context::{BlockContext, ChainInfo, FeeTokenAddresses}, + state::{cached_state::CachedState, state_api::StateReader}, + test_utils::MAX_FEE, + transaction::{ + objects::{TransactionExecutionInfo, TransactionExecutionResult}, + transaction_execution::Transaction as BlockiTransaction, + transactions::ExecutableTransaction, + }, + versioned_constants::{VersionedConstants, VersionedConstantsOverrides}, }; use blockifier_reexecution::state_reader::compile::{ legacy_to_contract_class_v0, sierra_to_contact_class_v1, @@ -14,7 +21,7 @@ use starknet::core::types::ContractClass as SNContractClass; use starknet_api::{ block::{BlockInfo, BlockNumber}, contract_class::ClassInfo, - core:: ContractAddress, + core::ContractAddress, felt, hash::StarkHash, patricia_key, @@ -75,28 +82,23 @@ pub fn execute_tx( // Map starknet_api transaction to blockifier's let blockifier_tx = match tx { - SNTransaction::Invoke(_) - | SNTransaction::DeployAccount(_) => - BlockiTransaction::from_api(tx, tx_hash, None, None, None, false).unwrap(), + SNTransaction::Invoke(_) | SNTransaction::DeployAccount(_) => { + BlockiTransaction::from_api(tx, tx_hash, None, None, None, false).unwrap() + } SNTransaction::Declare(ref declare_tx) => { let block_number = block_context.block_info().block_number; let network = parse_to_rpc_chain(&block_context.chain_info().chain_id.to_string()); // we need to retrieve the next block in order to get the contract_class let next_reader = RpcStateReader::new(network, block_number.next().unwrap()); - let contract_class = next_reader.get_contract_class(&declare_tx.class_hash()).unwrap(); + let contract_class = next_reader + .get_contract_class(&declare_tx.class_hash()) + .unwrap(); let class_info = calculate_class_info_for_testing(contract_class); BlockiTransaction::from_api(tx, tx_hash, Some(class_info), None, None, false).unwrap() } SNTransaction::L1Handler(_) => { - BlockiTransaction::from_api( - tx, - tx_hash, - None, - Some(MAX_FEE), - None, - false, - ).unwrap() + BlockiTransaction::from_api(tx, tx_hash, None, Some(MAX_FEE), None, false).unwrap() } _ => todo!(), }; @@ -172,28 +174,23 @@ pub fn execute_tx_configurable_with_state( // Get transaction before giving ownership of the reader let blockifier_tx = match tx { - SNTransaction::Invoke(_) - | SNTransaction::DeployAccount(_) => - BlockiTransaction::from_api(tx, tx_hash, None, None, None, false).unwrap(), + SNTransaction::Invoke(_) | SNTransaction::DeployAccount(_) => { + BlockiTransaction::from_api(tx, tx_hash, None, None, None, false).unwrap() + } SNTransaction::Declare(ref declare_tx) => { let block_number = block_context.block_info().block_number; let network = parse_to_rpc_chain(&chain_id.to_string()); // we need to retrieve the next block in order to get the contract_class let next_reader = RpcStateReader::new(network, block_number.next().unwrap()); - let contract_class = next_reader.get_contract_class(&declare_tx.class_hash()).unwrap(); + let contract_class = next_reader + .get_contract_class(&declare_tx.class_hash()) + .unwrap(); let class_info = calculate_class_info_for_testing(contract_class); BlockiTransaction::from_api(tx, tx_hash, Some(class_info), None, None, false).unwrap() } SNTransaction::L1Handler(_) => { - BlockiTransaction::from_api( - tx, - tx_hash, - None, - Some(MAX_FEE), - None, - false, - ).unwrap() + BlockiTransaction::from_api(tx, tx_hash, None, Some(MAX_FEE), None, false).unwrap() } _ => unimplemented!(), }; @@ -236,18 +233,27 @@ pub fn execute_tx_with_blockifier( transaction_hash: TransactionHash, ) -> TransactionExecutionResult { let account_transaction: BlockiTransaction = match transaction { - SNTransaction::Invoke(_) - | SNTransaction::DeployAccount(_) => - BlockiTransaction::from_api(transaction, transaction_hash, None, None, None, false)?, + SNTransaction::Invoke(_) | SNTransaction::DeployAccount(_) => { + BlockiTransaction::from_api(transaction, transaction_hash, None, None, None, false)? + } SNTransaction::Declare(ref declare_tx) => { let block_number = context.block_info().block_number; let network = parse_to_rpc_chain(&context.chain_info().chain_id.to_string()); // we need to retrieve the next block in order to get the contract_class let next_reader = RpcStateReader::new(network, block_number.next().unwrap()); - let contract_class = next_reader.get_contract_class(&declare_tx.class_hash()).unwrap(); + let contract_class = next_reader + .get_contract_class(&declare_tx.class_hash()) + .unwrap(); let class_info = calculate_class_info_for_testing(contract_class); - BlockiTransaction::from_api(transaction, transaction_hash, Some(class_info), None, None, false)? + BlockiTransaction::from_api( + transaction, + transaction_hash, + Some(class_info), + None, + None, + false, + )? } SNTransaction::L1Handler(_) => { // As L1Hanlder is not an account transaction we execute it here and return the result diff --git a/rpc-state-reader/src/reader.rs b/rpc-state-reader/src/reader.rs index 88384de..1e2a156 100644 --- a/rpc-state-reader/src/reader.rs +++ b/rpc-state-reader/src/reader.rs @@ -294,14 +294,11 @@ impl StateReader for RpcStateReader { } fn get_compiled_class(&self, class_hash: ClassHash) -> StateResult { - dbg!("ENTERED_GET_COMPILED_CLASS"); Ok(match self.get_contract_class(&class_hash)? { SNContractClass::Legacy(compressed_legacy_cc) => { - dbg!("ENTERED_LEGACY"); compile_legacy_cc(compressed_legacy_cc) } SNContractClass::Sierra(flattened_sierra_cc) => { - dbg!("ENTERED_SIERRA"); compile_sierra_cc(flattened_sierra_cc, class_hash) } }) @@ -353,9 +350,7 @@ fn compile_sierra_cc( RunnableCompiledClass::V1(casm_cc.try_into().unwrap()) } else { - dbg!("COMPILED_EXECUTOR"); let executor = utils::get_native_executor(&sierra_cc, class_hash); - dbg!("COMPILED_EXECUTOR_PASSED"); let casm = CasmContractClass::from_contract_class(sierra_cc, false, usize::MAX).unwrap(); let casm = CompiledClassV1::try_from(casm).unwrap(); diff --git a/rpc-state-reader/src/utils.rs b/rpc-state-reader/src/utils.rs index e547017..5205e7f 100644 --- a/rpc-state-reader/src/utils.rs +++ b/rpc-state-reader/src/utils.rs @@ -75,7 +75,11 @@ pub fn decode_reader(bytes: Vec) -> io::Result { pub fn get_native_executor(contract: &ContractClass, class_hash: ClassHash) -> AotContractExecutor { let cache_lock = AOT_PROGRAM_CACHE.get_or_init(|| RwLock::new(HashMap::new())); - let executor = cache_lock.read().unwrap().get(&class_hash).map(Clone::clone); + let executor = cache_lock + .read() + .unwrap() + .get(&class_hash) + .map(Clone::clone); match executor { Some(executor) => executor,