@@ -3,15 +3,15 @@ use std::collections::HashMap;
33use async_trait:: async_trait;
44use serde:: { Deserialize , Serialize } ;
55use starknet_api:: core:: ContractAddress ;
6- use starknet_patricia:: db_layout:: NodeLayoutFor ;
76use starknet_patricia:: patricia_merkle_tree:: filled_tree:: tree:: FilledTree ;
87use starknet_patricia:: patricia_merkle_tree:: node_data:: leaf:: LeafModifications ;
98use starknet_patricia:: patricia_merkle_tree:: types:: NodeIndex ;
10- use starknet_patricia_storage:: db_object:: { EmptyKeyContext , HasStaticPrefix } ;
9+ use starknet_patricia_storage:: db_object:: EmptyKeyContext ;
1110use starknet_patricia_storage:: errors:: SerializationResult ;
1211use starknet_patricia_storage:: storage_trait:: { DbHashMap , DbKey , DbValue , Storage } ;
1312
1413use crate :: block_committer:: input:: { InputContext , ReaderConfig , StarknetStorageValue } ;
14+ use crate :: db:: db_layout:: DbLayout ;
1515use crate :: db:: facts_db:: types:: FactsDbInitialRead ;
1616use crate :: db:: serde_db_utils:: DbBlockNumber ;
1717use crate :: db:: trie_traversal:: { create_classes_trie, create_contracts_trie, create_storage_tries} ;
@@ -81,30 +81,24 @@ pub(crate) async fn read_forest<'a, S, Layout>(
8181) -> ForestResult < ( OriginalSkeletonForest < ' a > , HashMap < NodeIndex , ContractState > ) >
8282where
8383 S : Storage ,
84- Layout : NodeLayoutFor < StarknetStorageValue >
85- + NodeLayoutFor < ContractState >
86- + NodeLayoutFor < CompiledClassHash > ,
87- <Layout as NodeLayoutFor < StarknetStorageValue > >:: DbLeaf :
88- HasStaticPrefix < KeyContext = ContractAddress > ,
89- <Layout as NodeLayoutFor < ContractState > >:: DbLeaf : HasStaticPrefix < KeyContext = EmptyKeyContext > ,
90- <Layout as NodeLayoutFor < CompiledClassHash > >:: DbLeaf :
91- HasStaticPrefix < KeyContext = EmptyKeyContext > ,
84+ Layout : DbLayout ,
9285{
93- let ( contracts_trie, original_contracts_trie_leaves) = create_contracts_trie :: < Layout > (
94- storage,
95- context. 0 . contracts_trie_root_hash ,
96- forest_sorted_indices. contracts_trie_sorted_indices ,
97- )
98- . await ?;
99- let storage_tries = create_storage_tries :: < Layout > (
86+ let ( contracts_trie, original_contracts_trie_leaves) =
87+ create_contracts_trie :: < Layout :: NodeLayout > (
88+ storage,
89+ context. 0 . contracts_trie_root_hash ,
90+ forest_sorted_indices. contracts_trie_sorted_indices ,
91+ )
92+ . await ?;
93+ let storage_tries = create_storage_tries :: < Layout :: NodeLayout > (
10094 storage,
10195 storage_updates,
10296 & original_contracts_trie_leaves,
10397 & config,
10498 & forest_sorted_indices. storage_tries_sorted_indices ,
10599 )
106100 . await ?;
107- let classes_trie = create_classes_trie :: < Layout > (
101+ let classes_trie = create_classes_trie :: < Layout :: NodeLayout > (
108102 storage,
109103 classes_updates,
110104 context. 0 . classes_trie_root_hash ,
@@ -120,31 +114,23 @@ where
120114}
121115
122116/// Helper function containing layout-common write logic.
123- pub ( crate ) fn serialize_forest < Layout > (
117+ pub ( crate ) fn serialize_forest < Layout : DbLayout > (
124118 filled_forest : & FilledForest ,
125- ) -> SerializationResult < DbHashMap >
126- where
127- Layout : NodeLayoutFor < StarknetStorageValue >
128- + NodeLayoutFor < ContractState >
129- + NodeLayoutFor < CompiledClassHash > ,
130- <Layout as NodeLayoutFor < StarknetStorageValue > >:: DbLeaf :
131- HasStaticPrefix < KeyContext = ContractAddress > ,
132- <Layout as NodeLayoutFor < ContractState > >:: DbLeaf : HasStaticPrefix < KeyContext = EmptyKeyContext > ,
133- <Layout as NodeLayoutFor < CompiledClassHash > >:: DbLeaf :
134- HasStaticPrefix < KeyContext = EmptyKeyContext > ,
135- {
119+ ) -> SerializationResult < DbHashMap > {
136120 let mut serialized_forest = DbHashMap :: new ( ) ;
137121
138122 // Storage tries.
139123 for ( contract_address, tree) in & filled_forest. storage_tries {
140- serialized_forest. extend ( tree. serialize :: < Layout > ( contract_address) ?) ;
124+ serialized_forest. extend ( tree. serialize :: < Layout :: NodeLayout > ( contract_address) ?) ;
141125 }
142126
143127 // Contracts trie.
144- serialized_forest. extend ( filled_forest. contracts_trie . serialize :: < Layout > ( & EmptyKeyContext ) ?) ;
128+ serialized_forest
129+ . extend ( filled_forest. contracts_trie . serialize :: < Layout :: NodeLayout > ( & EmptyKeyContext ) ?) ;
145130
146131 // Classes trie.
147- serialized_forest. extend ( filled_forest. classes_trie . serialize :: < Layout > ( & EmptyKeyContext ) ?) ;
132+ serialized_forest
133+ . extend ( filled_forest. classes_trie . serialize :: < Layout :: NodeLayout > ( & EmptyKeyContext ) ?) ;
148134
149135 Ok ( serialized_forest)
150136}
0 commit comments