Skip to content

Commit 7e2f4c8

Browse files
authored
committer: move facts db struct (#10307)
1 parent a5341eb commit 7e2f4c8

File tree

9 files changed

+70
-53
lines changed

9 files changed

+70
-53
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
pub mod facts_db;
12
pub mod forest_trait;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use std::collections::HashMap;
2+
3+
use starknet_api::core::ContractAddress;
4+
use starknet_api::hash::HashOutput;
5+
use starknet_patricia::patricia_merkle_tree::node_data::leaf::LeafModifications;
6+
use starknet_patricia::patricia_merkle_tree::types::NodeIndex;
7+
use starknet_patricia_storage::storage_trait::Storage;
8+
9+
use crate::block_committer::input::{ConfigImpl, StarknetStorageValue};
10+
use crate::db::forest_trait::{ForestReader, ForestWriter};
11+
use crate::forest::filled_forest::FilledForest;
12+
use crate::forest::forest_errors::ForestResult;
13+
use crate::forest::original_skeleton_forest::{ForestSortedIndices, OriginalSkeletonForest};
14+
use crate::patricia_merkle_tree::leaf::leaf_impl::ContractState;
15+
use crate::patricia_merkle_tree::types::CompiledClassHash;
16+
17+
pub struct FactsDb<S: Storage> {
18+
// TODO(Yoav): Define StorageStats trait and impl it here. Then, make the storage field
19+
// private.
20+
pub storage: S,
21+
}
22+
23+
impl<S: Storage> FactsDb<S> {
24+
pub fn new(storage: S) -> Self {
25+
Self { storage }
26+
}
27+
28+
pub fn consume_storage(self) -> S {
29+
self.storage
30+
}
31+
}
32+
33+
impl<'a, S: Storage> ForestReader<'a> for FactsDb<S> {
34+
fn read(
35+
&mut self,
36+
contracts_trie_root_hash: HashOutput,
37+
classes_trie_root_hash: HashOutput,
38+
storage_updates: &'a HashMap<ContractAddress, LeafModifications<StarknetStorageValue>>,
39+
classes_updates: &'a LeafModifications<CompiledClassHash>,
40+
forest_sorted_indices: &'a ForestSortedIndices<'a>,
41+
config: ConfigImpl,
42+
) -> ForestResult<(OriginalSkeletonForest<'a>, HashMap<NodeIndex, ContractState>)> {
43+
// TODO(Yoav): Move here OriginalSkeletonForest constructor with all the (facts)
44+
// storage-related functions.
45+
OriginalSkeletonForest::create(
46+
&mut self.storage,
47+
contracts_trie_root_hash,
48+
classes_trie_root_hash,
49+
storage_updates,
50+
classes_updates,
51+
forest_sorted_indices,
52+
&config,
53+
)
54+
}
55+
}
56+
57+
impl<S: Storage> ForestWriter for FactsDb<S> {
58+
fn write(&mut self, filled_forest: &FilledForest) -> usize {
59+
filled_forest.write_to_storage(&mut self.storage)
60+
}
61+
}

crates/starknet_committer/src/db/forest_trait.rs

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use starknet_api::core::ContractAddress;
44
use starknet_api::hash::HashOutput;
55
use starknet_patricia::patricia_merkle_tree::node_data::leaf::LeafModifications;
66
use starknet_patricia::patricia_merkle_tree::types::NodeIndex;
7-
use starknet_patricia_storage::storage_trait::Storage;
87

98
use crate::block_committer::input::{ConfigImpl, StarknetStorageValue};
109
use crate::forest::filled_forest::FilledForest;
@@ -34,49 +33,3 @@ pub trait ForestWriter {
3433
}
3534

3635
pub trait ForestStorage<'a>: ForestReader<'a> + ForestWriter {}
37-
38-
pub struct FactsDb<S: Storage> {
39-
// TODO(Yoav): Define StorageStats trait and impl it here. Then, make the storage field
40-
// private.
41-
pub storage: S,
42-
}
43-
44-
impl<S: Storage> FactsDb<S> {
45-
pub fn new(storage: S) -> Self {
46-
Self { storage }
47-
}
48-
49-
pub fn consume_storage(self) -> S {
50-
self.storage
51-
}
52-
}
53-
54-
impl<'a, S: Storage> ForestReader<'a> for FactsDb<S> {
55-
fn read(
56-
&mut self,
57-
contracts_trie_root_hash: HashOutput,
58-
classes_trie_root_hash: HashOutput,
59-
storage_updates: &'a HashMap<ContractAddress, LeafModifications<StarknetStorageValue>>,
60-
classes_updates: &'a LeafModifications<CompiledClassHash>,
61-
forest_sorted_indices: &'a ForestSortedIndices<'a>,
62-
config: ConfigImpl,
63-
) -> ForestResult<(OriginalSkeletonForest<'a>, HashMap<NodeIndex, ContractState>)> {
64-
// TODO(Yoav): Move here OriginalSkeletonForest constructor with all the (facts)
65-
// storage-related functions.
66-
OriginalSkeletonForest::create(
67-
&mut self.storage,
68-
contracts_trie_root_hash,
69-
classes_trie_root_hash,
70-
storage_updates,
71-
classes_updates,
72-
forest_sorted_indices,
73-
&config,
74-
)
75-
}
76-
}
77-
78-
impl<S: Storage> ForestWriter for FactsDb<S> {
79-
fn write(&mut self, filled_forest: &FilledForest) -> usize {
80-
filled_forest.write_to_storage(&mut self.storage)
81-
}
82-
}

crates/starknet_committer_and_os_cli/src/committer_cli/commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use starknet_committer::block_committer::commit::commit_block;
22
use starknet_committer::block_committer::input::Config;
3-
use starknet_committer::db::forest_trait::FactsDb;
3+
use starknet_committer::db::facts_db::FactsDb;
44
use starknet_patricia_storage::map_storage::MapStorage;
55
use tracing::info;
66
use tracing::level_filters::LevelFilter;

crates/starknet_committer_and_os_cli/src/committer_cli/filled_tree_output/filled_forest.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use serde::Serialize;
2-
use starknet_committer::db::forest_trait::{FactsDb, ForestWriter};
2+
use starknet_committer::db::facts_db::FactsDb;
3+
use starknet_committer::db::forest_trait::ForestWriter;
34
use starknet_committer::forest::filled_forest::FilledForest;
45
use starknet_patricia_storage::map_storage::MapStorage;
56

crates/starknet_committer_cli/src/commands.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use starknet_committer::block_committer::input::{
1414
};
1515
use starknet_committer::block_committer::state_diff_generator::generate_random_state_diff;
1616
use starknet_committer::block_committer::timing_util::{Action, TimeMeasurement};
17-
use starknet_committer::db::forest_trait::{FactsDb, ForestWriter};
17+
use starknet_committer::db::facts_db::FactsDb;
18+
use starknet_committer::db::forest_trait::ForestWriter;
1819
use starknet_patricia_storage::storage_trait::{AsyncStorage, DbKey, Storage, StorageStats};
1920
use starknet_types_core::felt::Felt;
2021
use tokio::task::JoinSet;

crates/starknet_os_flow_tests/src/initial_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use starknet_api::transaction::constants::DEPLOY_CONTRACT_FUNCTION_ENTRY_POINT_N
3131
use starknet_api::transaction::fields::{Calldata, ContractAddressSalt, ValidResourceBounds};
3232
use starknet_api::{calldata, deploy_account_tx_args, invoke_tx_args};
3333
use starknet_committer::block_committer::input::StateDiff;
34-
use starknet_committer::db::forest_trait::FactsDb;
34+
use starknet_committer::db::facts_db::FactsDb;
3535
use starknet_patricia_storage::map_storage::MapStorage;
3636
use starknet_types_core::felt::Felt;
3737

crates/starknet_os_flow_tests/src/test_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use starknet_api::test_utils::{NonceManager, CHAIN_ID_FOR_TESTS};
3737
use starknet_api::transaction::fields::{Calldata, Tip};
3838
use starknet_api::transaction::MessageToL1;
3939
use starknet_committer::block_committer::input::{IsSubset, StarknetStorageKey, StateDiff};
40-
use starknet_committer::db::forest_trait::FactsDb;
40+
use starknet_committer::db::facts_db::FactsDb;
4141
use starknet_os::hints::hint_implementation::state_diff_encryption::utils::compute_public_keys;
4242
use starknet_os::io::os_input::{
4343
OsBlockInput,

crates/starknet_os_flow_tests/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use starknet_committer::block_committer::input::{
4545
StarknetStorageValue,
4646
StateDiff,
4747
};
48-
use starknet_committer::db::forest_trait::FactsDb;
48+
use starknet_committer::db::facts_db::FactsDb;
4949
use starknet_committer::patricia_merkle_tree::leaf::leaf_impl::ContractState;
5050
use starknet_committer::patricia_merkle_tree::tree::fetch_previous_and_new_patricia_paths;
5151
use starknet_committer::patricia_merkle_tree::types::{

0 commit comments

Comments
 (0)