@@ -16,8 +16,10 @@ use starknet_api::block::{
1616 BlockInfo , BlockNumber , BlockTimestamp , FeeType , GasPrice , GasPricePerToken , GasPriceVector ,
1717 GasPrices ,
1818} ;
19+ use starknet_api:: block_hash:: block_hash_calculator:: calculate_block_commitments;
1920use starknet_api:: core:: SequencerContractAddress ;
2021use starknet_api:: data_availability:: DataAvailabilityMode ;
22+ use starknet_api:: state:: ThinStateDiff as ThinStateDiffImported ;
2123use starknet_api:: transaction:: fields:: { GasVectorComputationMode , Tip } ;
2224use starknet_api:: transaction:: { TransactionHasher , TransactionVersion } ;
2325use starknet_rs_core:: types:: { Felt , Hash256 , MsgFromL1 } ;
@@ -372,6 +374,9 @@ impl Starknet {
372374 // Update gas prices in the block header
373375 let header = & mut new_block. header . block_header_without_hash ;
374376
377+ let starknet_version = header. starknet_version ;
378+ let l1_da_mode = header. l1_da_mode ;
379+
375380 // Set L1 gas prices
376381 header. l1_gas_price = GasPricePerToken {
377382 price_in_fri : GasPrice ( self . next_block_gas . gas_price_fri . get ( ) ) ,
@@ -417,6 +422,33 @@ impl Starknet {
417422 }
418423 } ) ;
419424
425+ let transaction_data: Vec <
426+ starknet_api:: block_hash:: block_hash_calculator:: TransactionHashingData ,
427+ > = new_block
428+ . get_transactions ( )
429+ . iter ( )
430+ // filter map is used here, although in normal conditions unwrap should be safe. Every transaction hash that has been added to preconfirmed block should be present in transactions collection
431+ // changes should be done later so this is not even possible
432+ . filter_map ( |tx_hash| self . transactions . get_by_hash ( * tx_hash) )
433+ . map ( |tx| tx. into ( ) )
434+ . collect ( ) ;
435+
436+ let thin_state_diff: ThinStateDiffImported = self . pre_confirmed_state_diff . clone ( ) . into ( ) ;
437+
438+ let commitments = calculate_block_commitments (
439+ & transaction_data,
440+ & thin_state_diff,
441+ l1_da_mode,
442+ & starknet_version,
443+ ) ;
444+
445+ new_block. set_counts (
446+ transaction_data. len ( ) ,
447+ transaction_data. iter ( ) . map ( |tx| tx. transaction_output . events . len ( ) ) . sum ( ) ,
448+ thin_state_diff. len ( ) ,
449+ ) ;
450+ new_block. set_commitments ( commitments) ;
451+
420452 // insert pre_confirmed block in the blocks collection and connect it to the state diff
421453 self . blocks . insert ( new_block, self . pre_confirmed_state_diff . clone ( ) ) ;
422454 self . pre_confirmed_state_diff = StateDiff :: default ( ) ;
@@ -1992,29 +2024,6 @@ mod tests {
19922024 assert_eq ! ( block_number2. 0 , added_block2. header. block_header_without_hash. block_number. 0 ) ;
19932025 }
19942026
1995- #[ test]
1996- fn gets_block_txs_count ( ) {
1997- let config = StarknetConfig :: default ( ) ;
1998- let mut starknet = Starknet :: new ( & config) . unwrap ( ) ;
1999-
2000- starknet. generate_new_block_and_state ( ) . unwrap ( ) ;
2001-
2002- let num_no_transactions = starknet. get_block_txs_count ( & CustomBlockId :: Number ( 1 ) ) ;
2003-
2004- assert_eq ! ( num_no_transactions. unwrap( ) , 0 ) ;
2005-
2006- let tx = dummy_declare_tx_v3_with_hash ( ) ;
2007-
2008- // add transaction hash to pre_confirmed block
2009- starknet. blocks . pre_confirmed_block . add_transaction ( * tx. get_transaction_hash ( ) ) ;
2010-
2011- starknet. generate_new_block_and_state ( ) . unwrap ( ) ;
2012-
2013- let num_one_transaction = starknet. get_block_txs_count ( & CustomBlockId :: Number ( 2 ) ) ;
2014-
2015- assert_eq ! ( num_one_transaction. unwrap( ) , 1 ) ;
2016- }
2017-
20182027 #[ test]
20192028 fn returns_chain_id ( ) {
20202029 let config = StarknetConfig :: default ( ) ;
0 commit comments