@@ -27,7 +27,7 @@ use starknet_patricia::patricia_merkle_tree::traversal::{
2727use starknet_patricia:: patricia_merkle_tree:: types:: { NodeIndex , SortedLeafIndices } ;
2828use starknet_patricia_storage:: db_object:: { DBObject , EmptyKeyContext , HasStaticPrefix } ;
2929use starknet_patricia_storage:: errors:: StorageError ;
30- use starknet_patricia_storage:: storage_trait:: { AsyncStorage , DbKey , Storage } ;
30+ use starknet_patricia_storage:: storage_trait:: { AsyncStorage , DbHashMap , DbKey , Storage } ;
3131use tracing:: warn;
3232
3333use crate :: block_committer:: input:: {
@@ -47,6 +47,7 @@ macro_rules! log_trivial_modification {
4747 } ;
4848}
4949
50+ #[ allow( clippy:: too_many_arguments) ]
5051/// Fetches the Patricia witnesses, required to build the original skeleton tree from storage.
5152///
5253/// Given a list of subtrees, traverses towards their leaves and fetches all non-empty,
@@ -62,6 +63,7 @@ pub(crate) async fn fetch_nodes<'a, L, Layout>(
6263 leaf_modifications : & LeafModifications < L > ,
6364 config : & impl OriginalSkeletonTreeConfig ,
6465 mut previous_leaves : Option < & mut HashMap < NodeIndex , L > > ,
66+ mut siblings_map : Option < & mut DbHashMap > ,
6567 key_context : & <L as HasStaticPrefix >:: KeyContext ,
6668) -> OriginalSkeletonTreeResult < ( ) >
6769where
7375 let should_fetch_modified_leaves =
7476 config. compare_modified_leaves ( ) || previous_leaves. is_some ( ) ;
7577 while !current_subtrees. is_empty ( ) {
76- let filled_roots =
77- get_roots_from_storage :: < L , Layout > ( & current_subtrees, storage, key_context) . await ?;
78+ let filled_roots = get_roots_from_storage :: < L , Layout > (
79+ & current_subtrees,
80+ storage,
81+ key_context,
82+ siblings_map. as_deref_mut ( ) ,
83+ )
84+ . await ?;
7885 for ( filled_root, subtree) in filled_roots. into_iter ( ) . zip ( current_subtrees. into_iter ( ) ) {
7986 if subtree. is_unmodified ( ) {
8087 handle_unmodified_subtree ( skeleton_tree, & mut next_subtrees, filled_root, subtree) ;
@@ -244,17 +251,21 @@ pub async fn get_roots_from_storage<'a, L: Leaf, Layout: NodeLayout<'a, L>>(
244251 subtrees : & [ Layout :: SubTree ] ,
245252 storage : & impl Storage ,
246253 key_context : & <L as HasStaticPrefix >:: KeyContext ,
254+ mut siblings_map : Option < & mut DbHashMap > ,
247255) -> TraversalResult < Vec < FilledNode < L , Layout :: NodeData > > > {
248256 let mut subtrees_roots = vec ! [ ] ;
249257 let db_keys: Vec < DbKey > =
250258 subtrees. iter ( ) . map ( |subtree| subtree. get_root_db_key :: < L > ( key_context) ) . collect ( ) ;
251259
252260 let db_vals = storage. mget ( & db_keys. iter ( ) . collect :: < Vec < & DbKey > > ( ) ) . await ?;
253- for ( ( subtree, optional_val) , db_key) in subtrees. iter ( ) . zip ( db_vals. iter ( ) ) . zip ( db_keys) {
261+ for ( ( subtree, optional_val) , db_key) in subtrees. iter ( ) . zip ( db_vals. into_iter ( ) ) . zip ( db_keys) {
254262 let Some ( val) = optional_val else { Err ( StorageError :: MissingKey ( db_key) ) ? } ;
255263 let filled_node =
256- Layout :: NodeDbObject :: deserialize ( val, & subtree. get_root_context ( ) ) ?. into ( ) ;
264+ Layout :: NodeDbObject :: deserialize ( & val, & subtree. get_root_context ( ) ) ?. into ( ) ;
257265 subtrees_roots. push ( filled_node) ;
266+ if subtree. is_unmodified ( ) {
267+ siblings_map. as_mut ( ) . map ( |m| m. insert ( db_key, val) ) ;
268+ }
258269 }
259270 Ok ( subtrees_roots)
260271}
@@ -279,6 +290,7 @@ pub(crate) fn log_warning_for_empty_leaves<L: Leaf, T: Borrow<NodeIndex> + Debug
279290 Ok ( ( ) )
280291}
281292
293+ #[ allow( clippy:: too_many_arguments) ]
282294/// Creates an original skeleton tree by fetching Patricia nodes from storage.
283295///
284296/// Traverses the trie from the root towards the modified leaves, collecting all nodes needed
@@ -300,6 +312,7 @@ pub async fn create_original_skeleton_tree<'a, L: Leaf, Layout: NodeLayout<'a, L
300312 config : & impl OriginalSkeletonTreeConfig ,
301313 leaf_modifications : & LeafModifications < L > ,
302314 previous_leaves : Option < & mut HashMap < NodeIndex , L > > ,
315+ siblings_map : Option < & mut DbHashMap > ,
303316 key_context : & <L as HasStaticPrefix >:: KeyContext ,
304317) -> OriginalSkeletonTreeResult < OriginalSkeletonTreeImpl < ' a > > {
305318 if sorted_leaf_indices. is_empty ( ) {
@@ -332,6 +345,7 @@ pub async fn create_original_skeleton_tree<'a, L: Leaf, Layout: NodeLayout<'a, L
332345 leaf_modifications,
333346 config,
334347 previous_leaves,
348+ siblings_map,
335349 key_context,
336350 )
337351 . await ?;
@@ -379,6 +393,7 @@ where
379393 & config,
380394 & HashMap :: new ( ) ,
381395 Some ( & mut leaves) ,
396+ None ,
382397 & EmptyKeyContext ,
383398 )
384399 . await ?;
@@ -416,6 +431,7 @@ where
416431 . map ( |( idx, value) | ( * idx, Layout :: DbLeaf :: from ( * value) ) )
417432 . collect ( ) ,
418433 None ,
434+ None ,
419435 & EmptyKeyContext ,
420436 )
421437 . await ?)
@@ -527,6 +543,7 @@ where
527543 & trie_config,
528544 & leaf_modifications,
529545 None ,
546+ None ,
530547 & address,
531548 )
532549 . await ?;
0 commit comments