@@ -178,9 +178,9 @@ where
178178 l1_data_gas_prices : block_env. l1_data_gas_prices . clone ( ) ,
179179 } ;
180180
181- let provider = self . storage . provider_mut ( ) ;
181+ let provider_mut = self . storage . provider_mut ( ) ;
182182 let block = commit_block (
183- provider ,
183+ & provider_mut ,
184184 partial_header,
185185 transactions,
186186 & receipts,
@@ -194,10 +194,12 @@ where
194194 // TODO: maybe should change the arguments for insert_block_with_states_and_receipts to
195195 // accept ReceiptWithTxHash instead to avoid this conversion.
196196 let receipts = receipts. into_iter ( ) . map ( |r| r. receipt ) . collect :: < Vec < _ > > ( ) ;
197- self . store_block ( block, execution_output. states , receipts, traces) ?;
197+ store_block ( & provider_mut , block, execution_output. states , receipts, traces) ?;
198198
199199 info ! ( target: LOG_TARGET , %block_number, %tx_count, "Block mined." ) ;
200200
201+ provider_mut. commit ( ) ?;
202+
201203 Ok ( MinedBlockOutcome {
202204 block_hash,
203205 block_number,
@@ -206,28 +208,6 @@ where
206208 } )
207209 }
208210
209- fn store_block (
210- & self ,
211- block : SealedBlockWithStatus ,
212- states : StateUpdatesWithClasses ,
213- receipts : Vec < Receipt > ,
214- traces : Vec < TypedTransactionExecutionInfo > ,
215- ) -> Result < ( ) , BlockProductionError > {
216- // Validate that all declared classes have their corresponding class artifacts
217- if let Err ( missing) = states. validate_classes ( ) {
218- return Err ( BlockProductionError :: InconsistentState ( format ! (
219- "missing class artifacts for declared classes: {:#?}" ,
220- missing,
221- ) ) ) ;
222- }
223-
224- let provider_mut = self . storage . provider_mut ( ) ;
225- provider_mut. insert_block_with_states_and_receipts ( block, states, receipts, traces) ?;
226- provider_mut. commit ( ) ?;
227-
228- Ok ( ( ) )
229- }
230-
231211 pub fn mine_empty_block (
232212 & self ,
233213 block_env : & BlockEnv ,
@@ -349,8 +329,10 @@ where
349329
350330 info ! ( "Genesis has already been initialized" ) ;
351331 } else {
332+ let provider_mut = self . storage . provider_mut ( ) ;
333+
352334 let block = commit_genesis_block (
353- self . storage . provider_mut ( ) ,
335+ & provider_mut,
354336 header,
355337 transactions,
356338 & receipts,
@@ -362,8 +344,9 @@ where
362344 // TODO: maybe should change the arguments for insert_block_with_states_and_receipts to
363345 // accept ReceiptWithTxHash instead to avoid this conversion.
364346 let receipts = receipts. into_iter ( ) . map ( |r| r. receipt ) . collect :: < Vec < _ > > ( ) ;
365- self . store_block ( block, output. states , receipts, traces) ?;
347+ store_block ( & provider_mut , block, output. states , receipts, traces) ?;
366348
349+ provider_mut. commit ( ) ?;
367350 info ! ( "Genesis initialized" ) ;
368351 }
369352
@@ -558,6 +541,25 @@ impl<'a, P: TrieWriter> UncommittedBlock<'a, P> {
558541 }
559542}
560543
544+ fn store_block (
545+ provider_mut : & impl BlockWriter ,
546+ block : SealedBlockWithStatus ,
547+ states : StateUpdatesWithClasses ,
548+ receipts : Vec < Receipt > ,
549+ traces : Vec < TypedTransactionExecutionInfo > ,
550+ ) -> Result < ( ) , BlockProductionError > {
551+ // Validate that all declared classes have their corresponding class artifacts
552+ if let Err ( missing) = states. validate_classes ( ) {
553+ return Err ( BlockProductionError :: InconsistentState ( format ! (
554+ "missing class artifacts for declared classes: {:#?}" ,
555+ missing,
556+ ) ) ) ;
557+ }
558+
559+ provider_mut. insert_block_with_states_and_receipts ( block, states, receipts, traces) ?;
560+ Ok ( ( ) )
561+ }
562+
561563// TODO: create a dedicated struct for this contract.
562564// https://docs.starknet.io/architecture-and-concepts/network-architecture/starknet-state/#address_0x1
563565fn update_block_hash_registry_contract (
@@ -587,8 +589,8 @@ fn update_block_hash_registry_contract(
587589 Ok ( ( ) )
588590}
589591
590- fn commit_block (
591- provider : impl ProviderRW ,
592+ fn commit_block < P : BlockHashProvider + TrieWriter > (
593+ provider : P ,
592594 header : PartialHeader ,
593595 transactions : Vec < TxWithHash > ,
594596 receipts : & [ ReceiptWithTxHash ] ,
0 commit comments