Skip to content

Commit 76970a4

Browse files
committed
starknet_committer: impl metadata for FactsDb
1 parent 444066e commit 76970a4

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

crates/starknet_committer/src/db/facts_db.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use std::collections::HashMap;
2+
use std::sync::LazyLock;
23

34
use starknet_api::core::ContractAddress;
45
use starknet_api::hash::HashOutput;
56
use starknet_patricia::patricia_merkle_tree::node_data::leaf::LeafModifications;
67
use starknet_patricia::patricia_merkle_tree::original_skeleton_tree::tree::OriginalSkeletonTreeImpl;
78
use starknet_patricia::patricia_merkle_tree::types::{NodeIndex, SortedLeafIndices};
89
use 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

1112
use 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};
2223
use crate::forest::filled_forest::FilledForest;
2324
use crate::forest::forest_errors::{ForestError, ForestResult};
2425
use crate::forest::original_skeleton_forest::{ForestSortedIndices, OriginalSkeletonForest};
@@ -30,6 +31,9 @@ use crate::patricia_merkle_tree::tree::{
3031
};
3132
use 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+
3337
pub 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

Comments
 (0)