Skip to content

Commit 62631be

Browse files
committed
starknet_committer,starknet_patricia: move db_layout
1 parent 214f11b commit 62631be

File tree

7 files changed

+33
-35
lines changed

7 files changed

+33
-35
lines changed

crates/starknet_committer/src/db.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
mod db_layout;
21
#[cfg(any(feature = "testing", test))]
32
pub mod external_test_utils;
43
pub mod facts_db;

crates/starknet_committer/src/db/facts_db/db.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::collections::HashMap;
33
use async_trait::async_trait;
44
use starknet_api::core::ContractAddress;
55
use starknet_api::hash::HashOutput;
6+
use starknet_patricia::db_layout::{NodeLayout, TrieType};
67
use starknet_patricia::patricia_merkle_tree::filled_tree::node::{FactDbFilledNode, FilledNode};
78
use starknet_patricia::patricia_merkle_tree::filled_tree::node_serde::FactNodeDeserializationContext;
89
use starknet_patricia::patricia_merkle_tree::filled_tree::tree::FilledTree;
@@ -21,10 +22,8 @@ use starknet_patricia_storage::storage_trait::{
2122
};
2223

2324
use crate::block_committer::input::{FactsDbInitialRead, ReaderConfig, StarknetStorageValue};
24-
use crate::db::db_layout::NodeLayout;
2525
use crate::db::facts_db::types::FactsSubTree;
2626
use crate::db::forest_trait::{ForestMetadata, ForestMetadataType, ForestReader, ForestWriter};
27-
use crate::db::index_db::leaves::TrieType;
2827
use crate::db::trie_traversal::{create_classes_trie, create_contracts_trie, create_storage_tries};
2928
use crate::forest::filled_forest::FilledForest;
3029
use crate::forest::forest_errors::ForestResult;

crates/starknet_committer/src/db/index_db/db.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::collections::HashMap;
33
use async_trait::async_trait;
44
use starknet_api::core::ContractAddress;
55
use starknet_api::hash::HashOutput;
6+
use starknet_patricia::db_layout::{NodeLayout, TrieType};
67
use starknet_patricia::patricia_merkle_tree::filled_tree::node::FilledNode;
78
use starknet_patricia::patricia_merkle_tree::filled_tree::tree::FilledTree;
89
use starknet_patricia::patricia_merkle_tree::node_data::leaf::{Leaf, LeafModifications};
@@ -13,13 +14,11 @@ use starknet_patricia_storage::errors::SerializationResult;
1314
use starknet_patricia_storage::storage_trait::{DbHashMap, DbKey, Storage};
1415

1516
use crate::block_committer::input::{FactsDbInitialRead, ReaderConfig, StarknetStorageValue};
16-
use crate::db::db_layout::NodeLayout;
1717
use crate::db::forest_trait::{ForestMetadata, ForestMetadataType, ForestReader, ForestWriter};
1818
use crate::db::index_db::leaves::{
1919
IndexLayoutCompiledClassHash,
2020
IndexLayoutContractState,
2121
IndexLayoutStarknetStorageValue,
22-
TrieType,
2322
};
2423
use crate::db::index_db::types::{IndexFilledNode, IndexLayoutSubTree, IndexNodeContext};
2524
use crate::db::trie_traversal::{create_classes_trie, create_contracts_trie, create_storage_tries};

crates/starknet_committer/src/db/index_db/leaves.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use starknet_api::core::{ClassHash, ContractAddress, Nonce};
1+
use starknet_api::core::{ClassHash, Nonce};
22
use starknet_api::hash::HashOutput;
3+
use starknet_patricia::db_layout::TrieType;
34
use starknet_patricia::patricia_merkle_tree::node_data::errors::LeafResult;
45
use starknet_patricia::patricia_merkle_tree::node_data::leaf::Leaf;
56
use starknet_patricia_storage::db_object::{
@@ -14,7 +15,6 @@ use starknet_types_core::felt::Felt;
1415
use crate::block_committer::input::StarknetStorageValue;
1516
use crate::patricia_merkle_tree::leaf::leaf_impl::ContractState;
1617
use crate::patricia_merkle_tree::types::CompiledClassHash;
17-
1818
// Wrap the leaves types so that we can implement the [DBObject] trait differently in index
1919
// layout.
2020
#[derive(
@@ -28,27 +28,6 @@ pub struct IndexLayoutCompiledClassHash(pub CompiledClassHash);
2828
#[derive(Clone, Debug, Default, Eq, PartialEq, derive_more::From)]
2929
pub struct IndexLayoutStarknetStorageValue(pub StarknetStorageValue);
3030

31-
// TODO(Ariel): Delete this enum and use `CommitmentType` instead.
32-
#[derive(Debug, PartialEq)]
33-
pub enum TrieType {
34-
ContractsTrie,
35-
ClassesTrie,
36-
StorageTrie(ContractAddress),
37-
}
38-
39-
impl TrieType {
40-
fn db_prefix(&self) -> DbKeyPrefix {
41-
match self {
42-
TrieType::ContractsTrie => DbKeyPrefix::new(b"CONTRACTS_TREE_PREFIX".into()),
43-
TrieType::ClassesTrie => DbKeyPrefix::new(b"CLASSES_TREE_PREFIX".into()),
44-
TrieType::StorageTrie(contract_address) => {
45-
let prefix = contract_address.to_bytes_be().to_vec();
46-
DbKeyPrefix::new(prefix.into())
47-
}
48-
}
49-
}
50-
}
51-
5231
macro_rules! impl_has_static_prefix_for_index_layouts {
5332
($($ty:ty),* $(,)?) => {
5433
$(

crates/starknet_committer/src/db/trie_traversal.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::fmt::Debug;
44

55
use starknet_api::core::ContractAddress;
66
use starknet_api::hash::HashOutput;
7+
use starknet_patricia::db_layout::{NodeLayout, TrieType};
78
use starknet_patricia::patricia_merkle_tree::filled_tree::node::FilledNode;
89
use starknet_patricia::patricia_merkle_tree::node_data::inner_node::{
910
BinaryData,
@@ -33,8 +34,6 @@ use crate::block_committer::input::{
3334
Config,
3435
StarknetStorageValue,
3536
};
36-
use crate::db::db_layout::NodeLayout;
37-
use crate::db::index_db::leaves::TrieType;
3837
use crate::forest::forest_errors::{ForestError, ForestResult};
3938
use crate::patricia_merkle_tree::leaf::leaf_impl::ContractState;
4039
use crate::patricia_merkle_tree::tree::{

crates/starknet_committer/src/db/db_layout.rs renamed to crates/starknet_patricia/src/db_layout.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
1+
use starknet_api::core::ContractAddress;
12
use starknet_api::hash::HashOutput;
2-
use starknet_patricia::patricia_merkle_tree::filled_tree::node::FilledNode;
3-
use starknet_patricia::patricia_merkle_tree::node_data::leaf::Leaf;
4-
use starknet_patricia::patricia_merkle_tree::traversal::SubTreeTrait;
5-
use starknet_patricia::patricia_merkle_tree::types::{NodeIndex, SortedLeafIndices};
63
use starknet_patricia_storage::db_object::{DBObject, HasStaticPrefix};
4+
use starknet_patricia_storage::storage_trait::DbKeyPrefix;
5+
6+
use crate::patricia_merkle_tree::filled_tree::node::FilledNode;
7+
use crate::patricia_merkle_tree::node_data::leaf::Leaf;
8+
use crate::patricia_merkle_tree::traversal::SubTreeTrait;
9+
use crate::patricia_merkle_tree::types::{NodeIndex, SortedLeafIndices};
10+
11+
// TODO(Ariel): Delete this enum and use `CommitmentType` instead.
12+
#[derive(Debug, PartialEq)]
13+
pub enum TrieType {
14+
ContractsTrie,
15+
ClassesTrie,
16+
StorageTrie(ContractAddress),
17+
}
718

8-
use crate::db::index_db::leaves::TrieType;
19+
impl TrieType {
20+
pub fn db_prefix(&self) -> DbKeyPrefix {
21+
match self {
22+
TrieType::ContractsTrie => DbKeyPrefix::new(b"CONTRACTS_TREE_PREFIX".into()),
23+
TrieType::ClassesTrie => DbKeyPrefix::new(b"CLASSES_TREE_PREFIX".into()),
24+
TrieType::StorageTrie(contract_address) => {
25+
let prefix = contract_address.to_bytes_be().to_vec();
26+
DbKeyPrefix::new(prefix.into())
27+
}
28+
}
29+
}
30+
}
931

1032
/// Specifies the trie db layout.
1133
pub trait NodeLayout<'a, L: Leaf> {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
pub mod db_layout;
12
pub mod felt;
23
pub mod patricia_merkle_tree;

0 commit comments

Comments
 (0)