@@ -9,12 +9,15 @@ use apollo_gateway_config::config::RpcStateReaderConfig;
99use assert_matches:: assert_matches;
1010use blockifier:: abi:: constants;
1111use blockifier:: blockifier:: config:: TransactionExecutorConfig ;
12- use blockifier:: blockifier:: transaction_executor:: TransactionExecutor ;
12+ use blockifier:: blockifier:: transaction_executor:: {
13+ TransactionExecutionOutput ,
14+ TransactionExecutor ,
15+ } ;
1316use blockifier:: blockifier_versioned_constants:: VersionedConstants ;
1417use blockifier:: bouncer:: BouncerConfig ;
1518use blockifier:: context:: BlockContext ;
1619use blockifier:: execution:: contract_class:: RunnableCompiledClass ;
17- use blockifier:: state:: cached_state:: CommitmentStateDiff ;
20+ use blockifier:: state:: cached_state:: { CommitmentStateDiff , StateMaps } ;
1821use blockifier:: state:: contract_class_manager:: ContractClassManager ;
1922use blockifier:: state:: errors:: StateError ;
2023use blockifier:: state:: global_cache:: CompiledClasses ;
@@ -475,11 +478,36 @@ impl ConsecutiveRpcStateReaders {
475478 ) )
476479 }
477480
481+ /// Executes a single transaction.
482+ /// Returns the execution output, initial reads and the block context.
483+ pub fn execute_single_api_tx (
484+ self ,
485+ tx : Transaction ,
486+ ) -> ReexecutionResult < ( TransactionExecutionOutput , StateMaps , BlockContext ) > {
487+ let chain_id = self . next_block_state_reader . chain_id . clone ( ) ;
488+ let transaction_hash = tx. calculate_transaction_hash ( & chain_id) ?;
489+
490+ let blockifier_txs = self
491+ . next_block_state_reader
492+ . api_txs_to_blockifier_txs_next_block ( vec ! [ ( tx, transaction_hash) ] ) ?;
493+ let blockifier_tx = blockifier_txs
494+ . first ( )
495+ . expect ( "API to Blockifier transaction conversion returned empty list" ) ;
496+
497+ let mut transaction_executor = self . pre_process_and_create_executor ( None ) ?;
498+ let block_context = transaction_executor. block_context . as_ref ( ) . clone ( ) ;
499+
500+ let ( tx_execution_info, state_diff) = transaction_executor. execute ( blockifier_tx) ?;
501+ let initial_reads =
502+ transaction_executor. block_state . as_ref ( ) . unwrap ( ) . get_initial_reads ( ) ?;
503+ Ok ( ( ( tx_execution_info, state_diff) , initial_reads, block_context) )
504+ }
505+
478506 /// Executes a single transaction from a JSON file or given a transaction hash, using RPC to
479507 /// fetch block context. Does not assert correctness, only prints the execution result.
480508 pub fn execute_single_transaction ( self , tx_input : TransactionInput ) -> ReexecutionResult < ( ) > {
481509 // Get transaction and hash based on input method.
482- let ( transaction, transaction_hash ) = match tx_input {
510+ let ( transaction, _ ) = match tx_input {
483511 TransactionInput :: FromHash { tx_hash } => {
484512 // Fetch transaction from the next block (the block containing the transaction to
485513 // execute).
@@ -503,20 +531,7 @@ impl ConsecutiveRpcStateReaders {
503531 }
504532 } ;
505533
506- // Convert transaction to BlockifierTransaction using api_txs_to_blockifier_txs_next_block.
507- let blockifier_tx = self
508- . next_block_state_reader
509- . api_txs_to_blockifier_txs_next_block ( vec ! [ ( transaction, transaction_hash) ] ) ?;
510-
511- // Create transaction executor.
512- let mut transaction_executor = self . pre_process_and_create_executor ( None ) ?;
513-
514- // Execute transaction (should be single element).
515- let execution_results = transaction_executor. execute_txs ( & blockifier_tx, None ) ;
516-
517- // We expect exactly one execution result since we executed a single transaction.
518- let res =
519- execution_results. first ( ) . expect ( "Expected exactly one execution result, but got none" ) ;
534+ let ( res, _, _) = self . execute_single_api_tx ( transaction) ?;
520535
521536 println ! ( "Execution result: {:?}" , res) ;
522537
0 commit comments