Skip to content

Commit 13d764f

Browse files
committed
starknet_committer,starknet_patricia: move db_layout
1 parent 63b3ab4 commit 13d764f

File tree

8 files changed

+27
-32
lines changed

8 files changed

+27
-32
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;
78
use starknet_patricia::patricia_merkle_tree::filled_tree::node_serde::FactNodeDeserializationContext;
89
use starknet_patricia::patricia_merkle_tree::filled_tree::tree::FilledTree;
@@ -17,10 +18,8 @@ use starknet_patricia_storage::map_storage::MapStorage;
1718
use starknet_patricia_storage::storage_trait::{DbHashMap, Storage};
1819

1920
use crate::block_committer::input::{ReaderConfig, StarknetStorageValue};
20-
use crate::db::db_layout::NodeLayout;
2121
use crate::db::facts_db::types::{FactsDbInitialRead, FactsSubTree};
2222
use crate::db::forest_trait::{read_forest, ForestReader, ForestWriter};
23-
use crate::db::index_db::leaves::TrieType;
2423
use crate::forest::filled_forest::FilledForest;
2524
use crate::forest::forest_errors::ForestResult;
2625
use crate::forest::original_skeleton_forest::{ForestSortedIndices, OriginalSkeletonForest};

crates/starknet_committer/src/db/forest_trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ use std::collections::HashMap;
33
use async_trait::async_trait;
44
use serde::{Deserialize, Serialize};
55
use starknet_api::core::ContractAddress;
6+
use starknet_patricia::db_layout::NodeLayout;
67
use starknet_patricia::patricia_merkle_tree::node_data::leaf::{Leaf, LeafModifications};
78
use starknet_patricia::patricia_merkle_tree::types::NodeIndex;
89
use starknet_patricia_storage::errors::SerializationResult;
910
use starknet_patricia_storage::storage_trait::{DbHashMap, DbKey, DbValue, Storage};
1011

1112
use crate::block_committer::input::{InputContext, ReaderConfig, StarknetStorageValue};
12-
use crate::db::db_layout::NodeLayout;
1313
use crate::db::facts_db::types::FactsDbInitialRead;
1414
use crate::db::serde_db_utils::DbBlockNumber;
1515
use crate::db::trie_traversal::{create_classes_trie, create_contracts_trie, create_storage_tries};

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::collections::HashMap;
22

33
use async_trait::async_trait;
44
use starknet_api::core::ContractAddress;
5+
use starknet_patricia::db_layout::{NodeLayout, TrieType};
56
use starknet_patricia::patricia_merkle_tree::filled_tree::tree::FilledTree;
67
use starknet_patricia::patricia_merkle_tree::node_data::leaf::{Leaf, LeafModifications};
78
use starknet_patricia::patricia_merkle_tree::types::NodeIndex;
@@ -11,14 +12,12 @@ use starknet_patricia_storage::errors::SerializationResult;
1112
use starknet_patricia_storage::storage_trait::{DbHashMap, Storage};
1213

1314
use crate::block_committer::input::{ReaderConfig, StarknetStorageValue};
14-
use crate::db::db_layout::NodeLayout;
1515
use crate::db::facts_db::types::FactsDbInitialRead;
1616
use crate::db::forest_trait::{read_forest, ForestReader, ForestWriter};
1717
use crate::db::index_db::leaves::{
1818
IndexLayoutCompiledClassHash,
1919
IndexLayoutContractState,
2020
IndexLayoutStarknetStorageValue,
21-
TrieType,
2221
};
2322
use crate::db::index_db::types::{
2423
EmptyNodeData,

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

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::sync::LazyLock;
22

3-
use starknet_api::core::{ClassHash, ContractAddress, Nonce, PATRICIA_KEY_UPPER_BOUND};
3+
use starknet_api::core::{ClassHash, Nonce, PATRICIA_KEY_UPPER_BOUND};
44
use starknet_api::hash::HashOutput;
5+
use starknet_patricia::db_layout::TrieType;
56
use starknet_patricia::patricia_merkle_tree::node_data::errors::LeafResult;
67
use starknet_patricia::patricia_merkle_tree::node_data::leaf::Leaf;
78
use starknet_patricia_storage::db_object::{
@@ -16,7 +17,6 @@ use starknet_types_core::felt::Felt;
1617
use crate::block_committer::input::StarknetStorageValue;
1718
use crate::patricia_merkle_tree::leaf::leaf_impl::ContractState;
1819
use crate::patricia_merkle_tree::types::CompiledClassHash;
19-
2020
// Wrap the leaves types so that we can implement the [DBObject] trait differently in index
2121
// layout.
2222
#[derive(
@@ -46,23 +46,13 @@ static CONTRACTS_TREE_PREFIX: LazyLock<[u8; 32]> =
4646
static CLASSES_TREE_PREFIX: LazyLock<[u8; 32]> =
4747
LazyLock::new(|| (*FIRST_AVAILABLE_PREFIX_FELT + Felt::ONE).to_bytes_be());
4848

49-
// TODO(Ariel): Delete this enum and use `CommitmentType` instead.
50-
#[derive(Debug, PartialEq)]
51-
pub enum TrieType {
52-
ContractsTrie,
53-
ClassesTrie,
54-
StorageTrie(ContractAddress),
55-
}
56-
57-
impl TrieType {
58-
fn db_prefix(&self) -> DbKeyPrefix {
59-
match self {
60-
Self::ContractsTrie => DbKeyPrefix::new((&CONTRACTS_TREE_PREFIX[..]).into()),
61-
Self::ClassesTrie => DbKeyPrefix::new((&CLASSES_TREE_PREFIX[..]).into()),
62-
Self::StorageTrie(contract_address) => {
63-
let prefix = contract_address.to_bytes_be().to_vec();
64-
DbKeyPrefix::new(prefix.into())
65-
}
49+
fn trie_type_db_prefix(trie_type: &TrieType) -> DbKeyPrefix {
50+
match trie_type {
51+
TrieType::ContractsTrie => DbKeyPrefix::new((&CONTRACTS_TREE_PREFIX[..]).into()),
52+
TrieType::ClassesTrie => DbKeyPrefix::new((&CLASSES_TREE_PREFIX[..]).into()),
53+
TrieType::StorageTrie(contract_address) => {
54+
let prefix = contract_address.to_bytes_be().to_vec();
55+
DbKeyPrefix::new(prefix.into())
6656
}
6757
}
6858
}
@@ -73,7 +63,7 @@ macro_rules! impl_has_static_prefix_for_index_layouts {
7363
impl HasStaticPrefix for $ty {
7464
type KeyContext = TrieType;
7565
fn get_static_prefix(key_context: &Self::KeyContext) -> DbKeyPrefix {
76-
key_context.db_prefix()
66+
trie_type_db_prefix(key_context)
7767
}
7868
}
7969
)*

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
ReaderConfig,
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::OriginalSkeletonTrieConfig;

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
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;
53
use starknet_patricia_storage::db_object::{DBObject, HasStaticPrefix};
64

7-
use crate::db::index_db::leaves::TrieType;
5+
use crate::patricia_merkle_tree::filled_tree::node::FilledNode;
6+
use crate::patricia_merkle_tree::node_data::leaf::Leaf;
7+
use crate::patricia_merkle_tree::traversal::SubTreeTrait;
8+
9+
// TODO(Ariel): Delete this enum and use `CommitmentType` instead.
10+
#[derive(Debug, PartialEq)]
11+
pub enum TrieType {
12+
ContractsTrie,
13+
ClassesTrie,
14+
StorageTrie(ContractAddress),
15+
}
816

917
/// Specifies the trie db layout.
1018
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)