@@ -348,33 +348,14 @@ where
348348 <Layout as NodeLayoutFor < StarknetStorageValue > >:: DbLeaf :
349349 HasStaticPrefix < KeyContext = ContractAddress > ,
350350{
351- let mut storage_tries = HashMap :: new ( ) ;
352- for ( address, updates) in actual_storage_updates {
353- let sorted_leaf_indices = storage_tries_sorted_indices
354- . get ( address)
355- . ok_or ( ForestError :: MissingSortedLeafIndices ( * address) ) ?;
356- let contract_state = original_contracts_trie_leaves
357- . get ( & contract_address_into_node_index ( address) )
358- . ok_or ( ForestError :: MissingContractCurrentState ( * address) ) ?;
359- let config = OriginalSkeletonTrieConfig :: new_for_classes_or_storage_trie (
360- config. warn_on_trivial_modifications ( ) ,
361- ) ;
362-
363- let original_skeleton = create_original_skeleton_tree :: < Layout :: DbLeaf , Layout > (
364- storage,
365- contract_state. storage_root_hash ,
366- * sorted_leaf_indices,
367- & config,
368- // TODO(Ariel): Change `LeafModifications` in `actual_storage_updates` to be an
369- // iterator over borrowed data so that the conversion below is costless.
370- & updates. iter ( ) . map ( |( idx, value) | ( * idx, Layout :: DbLeaf :: from ( * value) ) ) . collect ( ) ,
371- None ,
372- address,
373- )
374- . await ?;
375- storage_tries. insert ( * address, original_skeleton) ;
376- }
377- Ok ( storage_tries)
351+ create_storage_tries_sequentially :: < Layout > (
352+ storage,
353+ actual_storage_updates,
354+ original_contracts_trie_leaves,
355+ config,
356+ storage_tries_sorted_indices,
357+ )
358+ . await
378359}
379360
380361/// Creates the contracts trie original skeleton.
@@ -438,3 +419,43 @@ where
438419 )
439420 . await ?)
440421}
422+
423+ async fn create_storage_tries_sequentially < ' a , Layout : NodeLayoutFor < StarknetStorageValue > > (
424+ storage : & impl Storage ,
425+ actual_storage_updates : & HashMap < ContractAddress , LeafModifications < StarknetStorageValue > > ,
426+ original_contracts_trie_leaves : & HashMap < NodeIndex , ContractState > ,
427+ config : & ReaderConfig ,
428+ storage_tries_sorted_indices : & HashMap < ContractAddress , SortedLeafIndices < ' a > > ,
429+ ) -> ForestResult < HashMap < ContractAddress , OriginalSkeletonTreeImpl < ' a > > >
430+ where
431+ <Layout as NodeLayoutFor < StarknetStorageValue > >:: DbLeaf :
432+ HasStaticPrefix < KeyContext = ContractAddress > ,
433+ {
434+ let mut storage_tries = HashMap :: new ( ) ;
435+ for ( address, updates) in actual_storage_updates {
436+ let sorted_leaf_indices = storage_tries_sorted_indices
437+ . get ( address)
438+ . ok_or ( ForestError :: MissingSortedLeafIndices ( * address) ) ?;
439+ let contract_state = original_contracts_trie_leaves
440+ . get ( & contract_address_into_node_index ( address) )
441+ . ok_or ( ForestError :: MissingContractCurrentState ( * address) ) ?;
442+ let config = OriginalSkeletonTrieConfig :: new_for_classes_or_storage_trie (
443+ config. warn_on_trivial_modifications ( ) ,
444+ ) ;
445+
446+ let original_skeleton = create_original_skeleton_tree :: < Layout :: DbLeaf , Layout > (
447+ storage,
448+ contract_state. storage_root_hash ,
449+ * sorted_leaf_indices,
450+ & config,
451+ // TODO(Ariel): Change `LeafModifications` in `actual_storage_updates` to be an
452+ // iterator over borrowed data so that the conversion below is costless.
453+ & updates. iter ( ) . map ( |( idx, value) | ( * idx, Layout :: DbLeaf :: from ( * value) ) ) . collect ( ) ,
454+ None ,
455+ address,
456+ )
457+ . await ?;
458+ storage_tries. insert ( * address, original_skeleton) ;
459+ }
460+ Ok ( storage_tries)
461+ }
0 commit comments