@@ -14,8 +14,9 @@ use blockifier::state::state_reader_and_contract_manager::{
1414} ;
1515use blockifier:: transaction:: account_transaction:: ExecutionFlags ;
1616use blockifier:: transaction:: transaction_execution:: Transaction as BlockifierTransaction ;
17+ use blockifier_reexecution:: state_reader:: reexecution_state_reader:: ReexecutionStateReader ;
1718use blockifier_reexecution:: state_reader:: rpc_state_reader:: RpcStateReader ;
18- use starknet_api:: block:: BlockNumber ;
19+ use starknet_api:: block:: { BlockHash , BlockNumber } ;
1920use starknet_api:: core:: { ChainId , ClassHash } ;
2021use starknet_api:: transaction:: fields:: Fee ;
2122use starknet_api:: transaction:: { InvokeTransaction , Transaction , TransactionHash } ;
@@ -36,6 +37,8 @@ pub struct VirtualBlockExecutionData {
3637 pub initial_reads : StateMaps ,
3738 /// The class hashes of all contracts executed in the virtual block.
3839 pub executed_class_hashes : HashSet < ClassHash > ,
40+ /// The block hash of the state at the start of the virtual block.
41+ pub prev_base_block_hash : BlockHash ,
3942}
4043
4144/// Executes a virtual block of transactions.
@@ -86,6 +89,7 @@ pub trait VirtualBlockExecutor {
8689 let blockifier_txs = self . convert_invoke_txs ( txs) ?;
8790 let block_context = self . block_context ( block_number) ?;
8891 let state_reader = self . state_reader ( block_number) ?;
92+ let prev_base_block_hash = self . prev_base_block_hash ( block_number) ?;
8993
9094 // Create state reader with contract manager.
9195 let state_reader_and_contract_manager =
@@ -132,6 +136,7 @@ pub trait VirtualBlockExecutor {
132136 block_context,
133137 initial_reads,
134138 executed_class_hashes,
139+ prev_base_block_hash,
135140 } )
136141 }
137142
@@ -172,6 +177,12 @@ pub trait VirtualBlockExecutor {
172177 block_number : BlockNumber ,
173178 ) -> Result < BlockContext , VirtualBlockExecutorError > ;
174179
180+ /// Returns the block hash of the state at the start of the virtual block.
181+ fn prev_base_block_hash (
182+ & self ,
183+ block_number : BlockNumber ,
184+ ) -> Result < BlockHash , VirtualBlockExecutorError > ;
185+
175186 /// Returns a state reader that implements `FetchCompiledClasses` for the given block number.
176187 /// Must be `Send + Sync + 'static` to be used in the transaction executor.
177188 fn state_reader (
@@ -219,6 +230,15 @@ impl VirtualBlockExecutor for RpcVirtualBlockExecutor {
219230 . map_err ( |e| VirtualBlockExecutorError :: ReexecutionError ( Box :: new ( e) ) )
220231 }
221232
233+ fn prev_base_block_hash (
234+ & self ,
235+ block_number : BlockNumber ,
236+ ) -> Result < BlockHash , VirtualBlockExecutorError > {
237+ self . rpc_state_reader
238+ . get_old_block_hash ( block_number)
239+ . map_err ( |e| VirtualBlockExecutorError :: ReexecutionError ( Box :: new ( e) ) )
240+ }
241+
222242 fn state_reader (
223243 & self ,
224244 _block_number : BlockNumber ,
0 commit comments