@@ -2,6 +2,7 @@ use std::collections::HashMap;
22
33use serde_json:: json;
44use starknet_api:: hash:: HashOutput ;
5+ use starknet_patricia:: db_layout:: NodeLayoutFor ;
56use starknet_patricia:: patricia_merkle_tree:: filled_tree:: tree:: { FilledTree , FilledTreeImpl } ;
67use starknet_patricia:: patricia_merkle_tree:: node_data:: leaf:: {
78 Leaf ,
@@ -18,29 +19,28 @@ use starknet_patricia::patricia_merkle_tree::updated_skeleton_tree::tree::{
1819use starknet_patricia_storage:: db_object:: HasStaticPrefix ;
1920use starknet_patricia_storage:: map_storage:: MapStorage ;
2021
21- use crate :: db:: facts_db:: db:: FactsNodeLayout ;
2222use crate :: db:: trie_traversal:: create_original_skeleton_tree;
2323
24- // TODO(Ariel, 14/12/2025): make this generic over the layout.
25- pub async fn tree_computation_flow < L , TH > (
24+ pub async fn tree_computation_flow < L , Layout , TH > (
2625 leaf_modifications : LeafModifications < L > ,
2726 storage : & mut MapStorage ,
2827 root_hash : HashOutput ,
2928 config : impl OriginalSkeletonTreeConfig ,
30- key_context : & <L as HasStaticPrefix >:: KeyContext ,
29+ key_context : & <Layout :: DbLeaf as HasStaticPrefix >:: KeyContext ,
3130) -> FilledTreeImpl < L >
3231where
3332 TH : TreeHashFunction < L > + ' static ,
3433 L : Leaf + ' static ,
34+ Layout : NodeLayoutFor < L > + ' static ,
3535{
3636 let mut sorted_leaf_indices: Vec < NodeIndex > = leaf_modifications. keys ( ) . copied ( ) . collect ( ) ;
3737 let sorted_leaf_indices = SortedLeafIndices :: new ( & mut sorted_leaf_indices) ;
38- let mut original_skeleton = create_original_skeleton_tree :: < L , FactsNodeLayout > (
38+ let mut original_skeleton = create_original_skeleton_tree :: < Layout :: DbLeaf , Layout > (
3939 storage,
4040 root_hash,
4141 sorted_leaf_indices,
4242 & config,
43- & leaf_modifications,
43+ & leaf_modifications. iter ( ) . map ( | ( k , v ) | ( * k , v . clone ( ) . into ( ) ) ) . collect ( ) ,
4444 None ,
4545 key_context,
4646 )
@@ -64,27 +64,36 @@ where
6464 )
6565 . expect ( "Failed to create the updated skeleton tree" ) ;
6666
67- FilledTreeImpl :: < L > :: create_with_existing_leaves :: < TH > ( updated_skeleton, leaf_modifications)
67+ FilledTreeImpl :: create_with_existing_leaves :: < TH > ( updated_skeleton, leaf_modifications)
6868 . await
6969 . expect ( "Failed to create the filled tree" )
7070}
7171
72- pub async fn single_tree_flow_test < L : Leaf + ' static , TH : TreeHashFunction < L > + ' static > (
72+ pub async fn single_tree_flow_test <
73+ L : Leaf + ' static ,
74+ Layout : for < ' a > NodeLayoutFor < L > + ' static ,
75+ TH : TreeHashFunction < L > + ' static ,
76+ > (
7377 leaf_modifications : LeafModifications < L > ,
7478 storage : & mut MapStorage ,
7579 root_hash : HashOutput ,
7680 config : impl OriginalSkeletonTreeConfig ,
77- key_context : & <L as HasStaticPrefix >:: KeyContext ,
81+ key_context : & <Layout :: DbLeaf as HasStaticPrefix >:: KeyContext ,
7882) -> String {
7983 // Move from leaf number to actual index.
8084 let leaf_modifications = leaf_modifications
8185 . into_iter ( )
8286 . map ( |( k, v) | ( NodeIndex :: FIRST_LEAF + k, v) )
83- . collect :: < LeafModifications < L > > ( ) ;
87+ . collect :: < LeafModifications < _ > > ( ) ;
8488
85- let filled_tree =
86- tree_computation_flow :: < L , TH > ( leaf_modifications, storage, root_hash, config, key_context)
87- . await ;
89+ let filled_tree: FilledTreeImpl < L > = tree_computation_flow :: < L , Layout , TH > (
90+ leaf_modifications,
91+ storage,
92+ root_hash,
93+ config,
94+ key_context,
95+ )
96+ . await ;
8897
8998 let hash_result = filled_tree. get_root_hash ( ) ;
9099
@@ -93,7 +102,7 @@ pub async fn single_tree_flow_test<L: Leaf + 'static, TH: TreeHashFunction<L> +
93102 let json_hash = & json ! ( hash_result. 0 . to_hex_string( ) ) ;
94103 result_map. insert ( "root_hash" , json_hash) ;
95104 // Serlialize the storage modifications.
96- let json_storage = & json ! ( filled_tree. serialize( key_context) . unwrap( ) ) ;
105+ let json_storage = & json ! ( filled_tree. serialize:: < Layout > ( key_context) . unwrap( ) ) ;
97106 result_map. insert ( "storage_changes" , json_storage) ;
98107 serde_json:: to_string ( & result_map) . expect ( "serialization failed" )
99108}
0 commit comments