Skip to content

Commit 7d94911

Browse files
committed
starknet_committer,starknet_patricia: remove generic config
1 parent eb8d709 commit 7d94911

File tree

8 files changed

+32
-72
lines changed

8 files changed

+32
-72
lines changed

crates/starknet_committer/src/block_committer/input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl From<ThinStateDiff> for StateDiff {
119119
}
120120

121121
/// Trait contains all optional configurations of the committer.
122-
pub trait Config: Debug + Eq + PartialEq {
122+
pub trait Config: Debug + Eq + PartialEq + Send + Sync {
123123
/// Indicates whether a warning should be given in case of a trivial state update.
124124
/// If the configuration is set, it requires that the storage will contain the original data for
125125
/// the modified leaves. Otherwise, it is not required.

crates/starknet_committer/src/db/external_test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub async fn tree_computation_flow<L, TH>(
2525
leaf_modifications: LeafModifications<L>,
2626
storage: &mut MapStorage,
2727
root_hash: HashOutput,
28-
config: impl OriginalSkeletonTreeConfig<L>,
28+
config: impl OriginalSkeletonTreeConfig,
2929
) -> FilledTreeImpl<L>
3030
where
3131
TH: TreeHashFunction<L> + 'static,
@@ -73,7 +73,7 @@ pub async fn single_tree_flow_test<
7373
leaf_modifications: LeafModifications<L>,
7474
storage: &mut MapStorage,
7575
root_hash: HashOutput,
76-
config: impl OriginalSkeletonTreeConfig<L>,
76+
config: impl OriginalSkeletonTreeConfig,
7777
) -> String {
7878
// Move from leaf number to actual index.
7979
let leaf_modifications = leaf_modifications

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ use starknet_patricia::patricia_merkle_tree::node_data::inner_node::{
1010
NodeData,
1111
};
1212
use starknet_patricia::patricia_merkle_tree::node_data::leaf::{Leaf, LeafModifications};
13-
use starknet_patricia::patricia_merkle_tree::original_skeleton_tree::config::{
14-
NoCompareOriginalSkeletonTrieConfig,
15-
OriginalSkeletonTreeConfig,
16-
};
13+
use starknet_patricia::patricia_merkle_tree::original_skeleton_tree::config::OriginalSkeletonTreeConfig;
1714
use starknet_patricia::patricia_merkle_tree::original_skeleton_tree::node::OriginalSkeletonNode;
1815
use starknet_patricia::patricia_merkle_tree::original_skeleton_tree::tree::{
1916
OriginalSkeletonTreeImpl,
@@ -29,6 +26,7 @@ use crate::db::db_layout::NodeLayout;
2926
use crate::db::facts_db::db::FactsNodeLayout;
3027
use crate::db::facts_db::traversal::get_roots_from_storage;
3128
use crate::db::facts_db::types::FactsSubTree;
29+
use crate::patricia_merkle_tree::tree::OriginalSkeletonTrieDontCompareConfig;
3230

3331
#[cfg(test)]
3432
#[path = "create_facts_tree_test.rs"]
@@ -54,7 +52,7 @@ async fn fetch_nodes<'a, L, Layout>(
5452
subtrees: Vec<Layout::SubTree>,
5553
storage: &mut impl Storage,
5654
leaf_modifications: &LeafModifications<L>,
57-
config: &impl OriginalSkeletonTreeConfig<L>,
55+
config: &impl OriginalSkeletonTreeConfig,
5856
mut previous_leaves: Option<&mut HashMap<NodeIndex, L>>,
5957
key_context: &<L as HasStaticPrefix>::KeyContext,
6058
) -> OriginalSkeletonTreeResult<()>
@@ -155,7 +153,7 @@ pub async fn create_original_skeleton_tree<'a, L: Leaf>(
155153
storage: &mut impl Storage,
156154
root_hash: HashOutput,
157155
sorted_leaf_indices: SortedLeafIndices<'a>,
158-
config: &impl OriginalSkeletonTreeConfig<L>,
156+
config: &impl OriginalSkeletonTreeConfig,
159157
leaf_modifications: &LeafModifications<L>,
160158
key_context: &<L as HasStaticPrefix>::KeyContext,
161159
) -> OriginalSkeletonTreeResult<OriginalSkeletonTreeImpl<'a>> {
@@ -190,7 +188,7 @@ pub async fn create_original_skeleton_tree_and_get_previous_leaves<'a, L: Leaf>(
190188
root_hash: HashOutput,
191189
sorted_leaf_indices: SortedLeafIndices<'a>,
192190
leaf_modifications: &LeafModifications<L>,
193-
config: &impl OriginalSkeletonTreeConfig<L>,
191+
config: &impl OriginalSkeletonTreeConfig,
194192
key_context: &<L as HasStaticPrefix>::KeyContext,
195193
) -> OriginalSkeletonTreeResult<(OriginalSkeletonTreeImpl<'a>, HashMap<NodeIndex, L>)> {
196194
if sorted_leaf_indices.is_empty() {
@@ -228,7 +226,7 @@ pub async fn get_leaves<'a, L: Leaf>(
228226
sorted_leaf_indices: SortedLeafIndices<'a>,
229227
key_context: &<L as HasStaticPrefix>::KeyContext,
230228
) -> OriginalSkeletonTreeResult<HashMap<NodeIndex, L>> {
231-
let config = NoCompareOriginalSkeletonTrieConfig::default();
229+
let config = OriginalSkeletonTrieDontCompareConfig;
232230
let leaf_modifications = LeafModifications::new();
233231
let (_, previous_leaves) = create_original_skeleton_tree_and_get_previous_leaves(
234232
storage,
@@ -320,7 +318,7 @@ fn handle_child_subtree<'a, SubTree: SubTreeTrait<'a>>(
320318
fn log_warning_for_empty_leaves<L: Leaf, T: Borrow<NodeIndex> + Debug>(
321319
leaf_indices: &[T],
322320
leaf_modifications: &LeafModifications<L>,
323-
config: &impl OriginalSkeletonTreeConfig<L>,
321+
config: &impl OriginalSkeletonTreeConfig,
324322
) -> OriginalSkeletonTreeResult<()> {
325323
if !config.compare_modified_leaves() {
326324
return Ok(());

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use starknet_patricia::patricia_merkle_tree::external_test_utils::{
1313
create_unmodified_subtree_skeleton_node,
1414
AdditionHash,
1515
MockLeaf,
16-
OriginalSkeletonMockTrieConfig,
1716
};
1817
use starknet_patricia::patricia_merkle_tree::node_data::leaf::LeafModifications;
1918
use starknet_patricia::patricia_merkle_tree::original_skeleton_tree::node::OriginalSkeletonNode;
@@ -24,6 +23,7 @@ use starknet_patricia_storage::storage_trait::{DbHashMap, DbKey, DbValue};
2423
use starknet_types_core::felt::Felt;
2524

2625
use crate::db::facts_db::create_facts_tree::create_original_skeleton_tree;
26+
use crate::patricia_merkle_tree::tree::OriginalSkeletonTrieConfig;
2727

2828
#[tokio::test]
2929
#[rstest]
@@ -208,7 +208,7 @@ async fn test_create_tree(
208208
.into_iter()
209209
.map(|(idx, leaf)| (NodeIndex::from_subtree_index(idx, subtree_height), leaf))
210210
.collect();
211-
let config = OriginalSkeletonMockTrieConfig::new(compare_modified_leaves);
211+
let config = OriginalSkeletonTrieConfig::new(compare_modified_leaves);
212212
let mut sorted_leaf_indices: Vec<NodeIndex> = leaf_modifications.keys().copied().collect();
213213
let sorted_leaf_indices = SortedLeafIndices::new(&mut sorted_leaf_indices);
214214
let skeleton_tree = create_original_skeleton_tree(

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ use crate::forest::filled_forest::FilledForest;
3737
use crate::forest::forest_errors::{ForestError, ForestResult};
3838
use crate::forest::original_skeleton_forest::{ForestSortedIndices, OriginalSkeletonForest};
3939
use crate::patricia_merkle_tree::leaf::leaf_impl::ContractState;
40-
use crate::patricia_merkle_tree::tree::{
41-
OriginalSkeletonClassesTrieConfig,
42-
OriginalSkeletonContractsTrieConfig,
43-
OriginalSkeletonStorageTrieConfig,
44-
};
40+
use crate::patricia_merkle_tree::tree::OriginalSkeletonTrieConfig;
4541
use crate::patricia_merkle_tree::types::CompiledClassHash;
4642

4743
pub struct FactsNodeLayout {}
@@ -80,7 +76,7 @@ impl<S: Storage> FactsDb<S> {
8076
contracts_trie_root_hash,
8177
contracts_trie_sorted_indices,
8278
&HashMap::new(),
83-
&OriginalSkeletonContractsTrieConfig::new(),
79+
&OriginalSkeletonTrieConfig::new(true),
8480
&EmptyKeyContext,
8581
)
8682
.await?)
@@ -101,8 +97,7 @@ impl<S: Storage> FactsDb<S> {
10197
let contract_state = original_contracts_trie_leaves
10298
.get(&contract_address_into_node_index(address))
10399
.ok_or(ForestError::MissingContractCurrentState(*address))?;
104-
let config =
105-
OriginalSkeletonStorageTrieConfig::new(config.warn_on_trivial_modifications());
100+
let config = OriginalSkeletonTrieConfig::new(config.warn_on_trivial_modifications());
106101

107102
let original_skeleton = create_original_skeleton_tree(
108103
&mut self.storage,
@@ -125,7 +120,7 @@ impl<S: Storage> FactsDb<S> {
125120
config: &impl Config,
126121
contracts_trie_sorted_indices: SortedLeafIndices<'a>,
127122
) -> ForestResult<OriginalSkeletonTreeImpl<'a>> {
128-
let config = OriginalSkeletonClassesTrieConfig::new(config.warn_on_trivial_modifications());
123+
let config = OriginalSkeletonTrieConfig::new(config.warn_on_trivial_modifications());
129124

130125
Ok(create_original_skeleton_tree(
131126
&mut self.storage,

crates/starknet_committer/src/patricia_merkle_tree/tree.rs

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

33
use starknet_api::core::{ClassHash, ContractAddress};
44
use starknet_api::hash::HashOutput;
5-
use starknet_patricia::generate_trie_config;
65
use starknet_patricia::patricia_merkle_tree::original_skeleton_tree::config::OriginalSkeletonTreeConfig;
76
use starknet_patricia::patricia_merkle_tree::traversal::TraversalResult;
87
use starknet_patricia::patricia_merkle_tree::types::{NodeIndex, SortedLeafIndices};
@@ -24,21 +23,28 @@ use crate::patricia_merkle_tree::types::{
2423
RootHashes,
2524
StarknetForestProofs,
2625
};
27-
generate_trie_config!(OriginalSkeletonStorageTrieConfig, StarknetStorageValue);
2826

29-
generate_trie_config!(OriginalSkeletonClassesTrieConfig, CompiledClassHash);
27+
pub(crate) struct OriginalSkeletonTrieConfig {
28+
compare_modified_leaves: bool,
29+
}
3030

31-
pub(crate) struct OriginalSkeletonContractsTrieConfig;
31+
impl OriginalSkeletonTrieConfig {
32+
pub(crate) fn new(should_compare_modified_leaves: bool) -> Self {
33+
Self { compare_modified_leaves: should_compare_modified_leaves }
34+
}
35+
}
3236

33-
impl OriginalSkeletonTreeConfig<ContractState> for OriginalSkeletonContractsTrieConfig {
37+
impl OriginalSkeletonTreeConfig for OriginalSkeletonTrieConfig {
3438
fn compare_modified_leaves(&self) -> bool {
35-
false
39+
self.compare_modified_leaves
3640
}
3741
}
3842

39-
impl OriginalSkeletonContractsTrieConfig {
40-
pub(crate) fn new() -> Self {
41-
Self
43+
pub(crate) struct OriginalSkeletonTrieDontCompareConfig;
44+
45+
impl OriginalSkeletonTreeConfig for OriginalSkeletonTrieDontCompareConfig {
46+
fn compare_modified_leaves(&self) -> bool {
47+
false
4248
}
4349
}
4450

crates/starknet_patricia/src/patricia_merkle_tree/external_test_utils.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ use super::node_data::leaf::Leaf;
2121
use super::original_skeleton_tree::node::OriginalSkeletonNode;
2222
use super::types::{NodeIndex, SubTreeHeight};
2323
use crate::felt::u256_from_felt;
24-
use crate::generate_trie_config;
2524
use crate::patricia_merkle_tree::errors::TypesError;
2625
use crate::patricia_merkle_tree::node_data::errors::{LeafError, LeafResult};
27-
use crate::patricia_merkle_tree::original_skeleton_tree::config::OriginalSkeletonTreeConfig;
2826

2927
#[derive(Debug, PartialEq, Clone, Copy, Default, Eq)]
3028
pub struct MockLeaf(pub Felt);
@@ -68,8 +66,6 @@ impl Leaf for MockLeaf {
6866
}
6967
}
7068

71-
generate_trie_config!(OriginalSkeletonMockTrieConfig, MockLeaf);
72-
7369
pub fn u256_try_into_felt(value: &U256) -> Result<Felt, TypesError<U256>> {
7470
if *value > u256_from_felt(&Felt::MAX) {
7571
return Err(TypesError::ConversionError {
Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,6 @@
1-
use crate::patricia_merkle_tree::node_data::leaf::Leaf;
2-
31
/// Configures the creation of an original skeleton tree.
4-
pub trait OriginalSkeletonTreeConfig<L: Leaf> {
2+
pub trait OriginalSkeletonTreeConfig {
53
/// Configures whether modified leaves should be compared to the previous leaves and log out a
64
/// warning when encountering a trivial modification.
75
fn compare_modified_leaves(&self) -> bool;
86
}
9-
10-
// TODO(Aviv 05/08/2024): Move this macro to starknet_committer crate
11-
#[macro_export]
12-
macro_rules! generate_trie_config {
13-
($struct_name:ident, $leaf_type:ty) => {
14-
pub struct $struct_name {
15-
compare_modified_leaves: bool,
16-
}
17-
18-
impl $struct_name {
19-
#[allow(dead_code)]
20-
pub fn new(compare_modified_leaves: bool) -> Self {
21-
Self { compare_modified_leaves }
22-
}
23-
}
24-
25-
impl OriginalSkeletonTreeConfig<$leaf_type> for $struct_name {
26-
fn compare_modified_leaves(&self) -> bool {
27-
self.compare_modified_leaves
28-
}
29-
}
30-
};
31-
}
32-
33-
#[derive(Default)]
34-
/// Generic config that doesn't compare the modified leaves.
35-
pub struct NoCompareOriginalSkeletonTrieConfig<L: Leaf>(std::marker::PhantomData<L>);
36-
37-
impl<L: Leaf> OriginalSkeletonTreeConfig<L> for NoCompareOriginalSkeletonTrieConfig<L> {
38-
fn compare_modified_leaves(&self) -> bool {
39-
false
40-
}
41-
}

0 commit comments

Comments
 (0)