@@ -2,7 +2,13 @@ use std::path::PathBuf;
22use std:: sync:: LazyLock ;
33use std:: { env, fs} ;
44
5- use apollo_batcher:: cende_client_types:: { CendeBlockMetadata , CendePreconfirmedBlock } ;
5+ use apollo_batcher:: cende_client_types:: {
6+ CendeBlockMetadata ,
7+ CendePreconfirmedBlock ,
8+ CendePreconfirmedTransaction ,
9+ StarknetClientStateDiff ,
10+ StarknetClientTransactionReceipt ,
11+ } ;
612use apollo_batcher:: pre_confirmed_cende_client:: CendeWritePreconfirmedBlock ;
713use apollo_batcher_types:: batcher_types:: Round ;
814use apollo_class_manager_types:: MockClassManagerClient ;
@@ -15,9 +21,11 @@ use apollo_infra_utils::compile_time_cargo_manifest_dir;
1521use blockifier:: blockifier_versioned_constants:: VersionedConstants ;
1622use blockifier:: bouncer:: BouncerConfig ;
1723use blockifier:: context:: { BlockContext , ChainInfo } ;
18- use blockifier:: state:: cached_state:: StateMaps ;
24+ use blockifier:: state:: cached_state:: { CachedState , StateMaps } ;
1925use blockifier:: test_utils:: contracts:: FeatureContractTrait ;
2026use blockifier:: test_utils:: dict_state_reader:: DictStateReader ;
27+ use blockifier:: transaction:: account_transaction:: AccountTransaction as BlockifierAccountTx ;
28+ use blockifier:: transaction:: transactions:: ExecutableTransaction ;
2129use blockifier_test_utils:: contracts:: FeatureContract ;
2230use expect_test:: expect_file;
2331use google_cloud_storage:: client:: { Client , ClientConfig } ;
@@ -52,7 +60,12 @@ use starknet_api::transaction::fields::{
5260 Tip ,
5361 TransactionSignature ,
5462} ;
55- use starknet_api:: transaction:: { DeclareTransaction , TransactionHasher , TransactionVersion } ;
63+ use starknet_api:: transaction:: {
64+ DeclareTransaction ,
65+ TransactionHasher ,
66+ TransactionOffsetInBlock ,
67+ TransactionVersion ,
68+ } ;
5669use starknet_committer:: db:: facts_db:: FactsDb ;
5770use starknet_committer:: db:: forest_trait:: StorageInitializer ;
5871use starknet_patricia_storage:: map_storage:: MapStorage ;
@@ -107,7 +120,6 @@ struct BlobFactory {
107120 next_txs : Vec < TxPair > ,
108121
109122 // Context.
110- #[ expect( dead_code) ]
111123 state : DictStateReader ,
112124 #[ expect( dead_code) ]
113125 committer_storage : FactsDb < MapStorage > ,
@@ -219,11 +231,6 @@ impl BlobFactory {
219231 // Data generation
220232 // =====================
221233
222- fn next_block_number ( & self ) -> usize {
223- self . blocks . len ( )
224- }
225-
226- #[ expect( dead_code) ]
227234 fn next_block_context ( & self ) -> BlockContext {
228235 let block_number = BlockNumber ( u64:: try_from ( self . blocks . len ( ) ) . unwrap ( ) ) ;
229236 BlockContext :: new (
@@ -251,17 +258,54 @@ impl BlobFactory {
251258
252259 /// Creates a preconfirmed block for the given block. Should be called for the last block only -
253260 /// no commitment is computed.
254- fn make_preconfirmed_block_from_remaining_txs ( & self ) -> CendeWritePreconfirmedBlock {
255- // TODO(Dori): implement.
261+ fn make_preconfirmed_block_from_remaining_txs ( self ) -> CendeWritePreconfirmedBlock {
262+ let block_context = self . next_block_context ( ) ;
263+ let block_info = block_context. block_info ( ) . clone ( ) ;
264+ let mut transactions = vec ! [ ] ;
265+ let mut transaction_receipts = vec ! [ ] ;
266+ let mut transaction_state_diffs = vec ! [ ] ;
267+ let Self { mut state, next_txs, .. } = self ;
268+
269+ for ( tx_index, ( executable, internal) ) in next_txs. into_iter ( ) . enumerate ( ) {
270+ let tx_hash = match & internal {
271+ InternalConsensusTransaction :: RpcTransaction ( tx) => tx. tx_hash ,
272+ InternalConsensusTransaction :: L1Handler ( _) => {
273+ panic ! ( "unexpected L1Handler in test" )
274+ }
275+ } ;
276+
277+ let mut tx_state = CachedState :: new ( state. clone ( ) ) ;
278+ let execution_info = BlockifierAccountTx :: new_for_sequencing ( executable. clone ( ) )
279+ . execute ( & mut tx_state, & block_context)
280+ . unwrap ( ) ;
281+
282+ let state_changes = tx_state. to_state_diff ( ) . unwrap ( ) ;
283+
284+ let receipt = StarknetClientTransactionReceipt :: from ( (
285+ tx_hash,
286+ TransactionOffsetInBlock ( tx_index) ,
287+ & execution_info,
288+ None ,
289+ ) ) ;
290+ let tx_state_diff = StarknetClientStateDiff :: from ( state_changes. state_maps ) . 0 ;
291+
292+ transactions. push ( CendePreconfirmedTransaction :: from ( internal. clone ( ) ) ) ;
293+ transaction_receipts. push ( Some ( receipt) ) ;
294+ transaction_state_diffs. push ( Some ( tx_state_diff) ) ;
295+
296+ // Update the state for the next tx.
297+ state = tx_state. state ;
298+ }
299+
256300 CendeWritePreconfirmedBlock {
257- block_number : BlockNumber ( u64 :: try_from ( self . next_block_number ( ) ) . unwrap ( ) ) ,
301+ block_number : block_info . block_number ,
258302 round : Round :: default ( ) ,
259303 write_iteration : 0 ,
260304 pre_confirmed_block : CendePreconfirmedBlock {
261- metadata : CendeBlockMetadata :: new ( BlockInfo :: default ( ) ) ,
262- transactions : vec ! [ ] ,
263- transaction_receipts : vec ! [ ] ,
264- transaction_state_diffs : vec ! [ ] ,
305+ metadata : CendeBlockMetadata :: new ( block_info ) ,
306+ transactions,
307+ transaction_receipts,
308+ transaction_state_diffs,
265309 } ,
266310 }
267311 }
0 commit comments