11use std:: collections:: HashMap ;
2+ use std:: sync:: LazyLock ;
23
34use starknet_api:: core:: ContractAddress ;
45use starknet_api:: hash:: HashOutput ;
56use starknet_patricia:: patricia_merkle_tree:: node_data:: leaf:: LeafModifications ;
67use starknet_patricia:: patricia_merkle_tree:: original_skeleton_tree:: tree:: OriginalSkeletonTreeImpl ;
78use starknet_patricia:: patricia_merkle_tree:: types:: { NodeIndex , SortedLeafIndices } ;
89use starknet_patricia_storage:: map_storage:: MapStorage ;
9- use starknet_patricia_storage:: storage_trait:: Storage ;
10+ use starknet_patricia_storage:: storage_trait:: { create_db_key , DbKey , DbKeyPrefix , Storage } ;
1011
1112use crate :: block_committer:: input:: {
1213 contract_address_into_node_index,
@@ -18,7 +19,7 @@ use crate::db::create_facts_tree::{
1819 create_original_skeleton_tree,
1920 create_original_skeleton_tree_and_get_previous_leaves,
2021} ;
21- use crate :: db:: forest_trait:: { ForestReader , ForestWriter } ;
22+ use crate :: db:: forest_trait:: { ForestMetadata , ForestMetadataType , ForestReader , ForestWriter } ;
2223use crate :: forest:: filled_forest:: FilledForest ;
2324use crate :: forest:: forest_errors:: { ForestError , ForestResult } ;
2425use crate :: forest:: original_skeleton_forest:: { ForestSortedIndices , OriginalSkeletonForest } ;
@@ -30,6 +31,9 @@ use crate::patricia_merkle_tree::tree::{
3031} ;
3132use crate :: patricia_merkle_tree:: types:: CompiledClassHash ;
3233
34+ pub static COMMITMENT_OFFSET_KEY : LazyLock < & [ u8 ] > = LazyLock :: new ( || b"commitment_offset" ) ;
35+ pub static STATE_DIFF_HASH_PREFIX : LazyLock < & [ u8 ] > = LazyLock :: new ( || b"state_diff_hash" ) ;
36+
3337pub struct FactsDb < S : Storage > {
3438 // TODO(Yoav): Define StorageStats trait and impl it here. Then, make the storage field
3539 // private.
@@ -163,3 +167,15 @@ impl<S: Storage> ForestWriter for FactsDb<S> {
163167 filled_forest. write_to_storage ( & mut self . storage ) . await
164168 }
165169}
170+
171+ impl < S : Storage > ForestMetadata for FactsDb < S > {
172+ fn metadata_key ( metadata_type : ForestMetadataType ) -> DbKey {
173+ match metadata_type {
174+ ForestMetadataType :: CommitmentOffset => DbKey ( COMMITMENT_OFFSET_KEY . to_vec ( ) ) ,
175+ ForestMetadataType :: StateDiffHash ( block_number) => {
176+ let state_diff_hash_key_prefix = DbKeyPrefix :: new ( * STATE_DIFF_HASH_PREFIX ) ;
177+ create_db_key ( state_diff_hash_key_prefix, & block_number. 0 . to_be_bytes ( ) )
178+ }
179+ }
180+ }
181+ }
0 commit comments