Skip to content

Commit 05b0a54

Browse files
authored
starknet_committer,starknet_patricia: remove generic config (#10683)
1 parent 8f999d9 commit 05b0a54

File tree

10 files changed

+44
-78
lines changed

10 files changed

+44
-78
lines changed

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::OriginalSkeletonTrieConfig;
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 = OriginalSkeletonTrieConfig::default();
232230
let leaf_modifications = LeafModifications::new();
233231
let (_, previous_leaves) = create_original_skeleton_tree_and_get_previous_leaves(
234232
storage,
@@ -331,7 +329,7 @@ fn handle_child_subtree<'a, SubTree: SubTreeTrait<'a>>(
331329
fn log_warning_for_empty_leaves<L: Leaf, T: Borrow<NodeIndex> + Debug>(
332330
leaf_indices: &[T],
333331
leaf_modifications: &LeafModifications<L>,
334-
config: &impl OriginalSkeletonTreeConfig<L>,
332+
config: &impl OriginalSkeletonTreeConfig,
335333
) -> OriginalSkeletonTreeResult<()> {
336334
if !config.compare_modified_leaves() {
337335
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_for_tests(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: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ use crate::forest::filled_forest::FilledForest;
2929
use crate::forest::forest_errors::{ForestError, ForestResult};
3030
use crate::forest::original_skeleton_forest::{ForestSortedIndices, OriginalSkeletonForest};
3131
use crate::patricia_merkle_tree::leaf::leaf_impl::ContractState;
32-
use crate::patricia_merkle_tree::tree::{
33-
OriginalSkeletonClassesTrieConfig,
34-
OriginalSkeletonContractsTrieConfig,
35-
OriginalSkeletonStorageTrieConfig,
36-
};
32+
use crate::patricia_merkle_tree::tree::OriginalSkeletonTrieConfig;
3733
use crate::patricia_merkle_tree::types::CompiledClassHash;
3834

3935
/// Facts DB node layout.
@@ -74,7 +70,7 @@ impl<S: Storage> FactsDb<S> {
7470
contracts_trie_root_hash,
7571
contracts_trie_sorted_indices,
7672
&HashMap::new(),
77-
&OriginalSkeletonContractsTrieConfig::new(),
73+
&OriginalSkeletonTrieConfig::new_for_contracts_trie(),
7874
&EmptyKeyContext,
7975
)
8076
.await?)
@@ -95,8 +91,9 @@ impl<S: Storage> FactsDb<S> {
9591
let contract_state = original_contracts_trie_leaves
9692
.get(&contract_address_into_node_index(address))
9793
.ok_or(ForestError::MissingContractCurrentState(*address))?;
98-
let config =
99-
OriginalSkeletonStorageTrieConfig::new(config.warn_on_trivial_modifications());
94+
let config = OriginalSkeletonTrieConfig::new_for_classes_or_storage_trie(
95+
config.warn_on_trivial_modifications(),
96+
);
10097

10198
let original_skeleton = create_original_skeleton_tree(
10299
&mut self.storage,
@@ -119,7 +116,9 @@ impl<S: Storage> FactsDb<S> {
119116
config: &ReaderConfig,
120117
contracts_trie_sorted_indices: SortedLeafIndices<'a>,
121118
) -> ForestResult<OriginalSkeletonTreeImpl<'a>> {
122-
let config = OriginalSkeletonClassesTrieConfig::new(config.warn_on_trivial_modifications());
119+
let config = OriginalSkeletonTrieConfig::new_for_classes_or_storage_trie(
120+
config.warn_on_trivial_modifications(),
121+
);
123122

124123
Ok(create_original_skeleton_tree(
125124
&mut self.storage,

crates/starknet_committer/src/patricia_merkle_tree/tree.rs

Lines changed: 18 additions & 10 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,30 @@ 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+
#[derive(Default)]
28+
pub struct OriginalSkeletonTrieConfig {
29+
compare_modified_leaves: bool,
30+
}
3031

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

33-
impl OriginalSkeletonTreeConfig<ContractState> for OriginalSkeletonContractsTrieConfig {
34-
fn compare_modified_leaves(&self) -> bool {
35-
false
37+
pub fn new_for_classes_or_storage_trie(warn_on_trivial_modifications: bool) -> Self {
38+
Self { compare_modified_leaves: warn_on_trivial_modifications }
39+
}
40+
41+
#[cfg(test)]
42+
pub(crate) fn new_for_tests(should_compare_modified_leaves: bool) -> Self {
43+
Self { compare_modified_leaves: should_compare_modified_leaves }
3644
}
3745
}
3846

39-
impl OriginalSkeletonContractsTrieConfig {
40-
pub(crate) fn new() -> Self {
41-
Self
47+
impl OriginalSkeletonTreeConfig for OriginalSkeletonTrieConfig {
48+
fn compare_modified_leaves(&self) -> bool {
49+
self.compare_modified_leaves
4250
}
4351
}
4452

crates/starknet_committer_and_os_cli/benches/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
1313
use starknet_committer::block_committer::input::StarknetStorageValue;
1414
use starknet_committer::db::external_test_utils::tree_computation_flow;
1515
use starknet_committer::hash_function::hash::TreeHashFunctionImpl;
16-
use starknet_committer::patricia_merkle_tree::tree::OriginalSkeletonStorageTrieConfig;
16+
use starknet_committer::patricia_merkle_tree::tree::OriginalSkeletonTrieConfig;
1717
use starknet_committer_and_os_cli::committer_cli::commands::commit;
1818
use starknet_committer_and_os_cli::committer_cli::parse_input::cast::CommitterFactsDbInputImpl;
1919
use starknet_committer_and_os_cli::committer_cli::parse_input::read::parse_input;
@@ -48,7 +48,7 @@ pub fn single_tree_flow_benchmark(criterion: &mut Criterion) {
4848
leaf_modifications_input,
4949
&mut storage,
5050
root_hash,
51-
OriginalSkeletonStorageTrieConfig::new(false),
51+
OriginalSkeletonTrieConfig::new_for_classes_or_storage_trie(false),
5252
),
5353
);
5454
},

crates/starknet_committer_and_os_cli/src/committer_cli/tests/python_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use starknet_committer::hash_function::hash::{
1919
CONTRACT_STATE_HASH_VERSION,
2020
};
2121
use starknet_committer::patricia_merkle_tree::leaf::leaf_impl::ContractState;
22-
use starknet_committer::patricia_merkle_tree::tree::OriginalSkeletonStorageTrieConfig;
22+
use starknet_committer::patricia_merkle_tree::tree::OriginalSkeletonTrieConfig;
2323
use starknet_committer::patricia_merkle_tree::types::CompiledClassHash;
2424
use starknet_patricia::patricia_merkle_tree::filled_tree::node::FactDbFilledNode;
2525
use starknet_patricia::patricia_merkle_tree::node_data::inner_node::{
@@ -167,7 +167,7 @@ impl PythonTestRunner for CommitterPythonTestRunner {
167167
leaf_modifications,
168168
&mut storage,
169169
root_hash,
170-
OriginalSkeletonStorageTrieConfig::new(false),
170+
OriginalSkeletonTrieConfig::new_for_classes_or_storage_trie(false),
171171
)
172172
.await;
173173
// 3. Serialize and return output.

crates/starknet_committer_and_os_cli/src/committer_cli/tests/regression_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use serde_json::{Map, Value};
77
use starknet_committer::block_committer::input::StarknetStorageValue;
88
use starknet_committer::db::external_test_utils::single_tree_flow_test;
99
use starknet_committer::hash_function::hash::TreeHashFunctionImpl;
10-
use starknet_committer::patricia_merkle_tree::tree::OriginalSkeletonStorageTrieConfig;
10+
use starknet_committer::patricia_merkle_tree::tree::OriginalSkeletonTrieConfig;
1111
use tempfile::NamedTempFile;
1212

1313
use crate::committer_cli::commands::commit;
@@ -110,7 +110,7 @@ pub async fn test_regression_single_tree() {
110110
leaf_modifications,
111111
&mut storage,
112112
root_hash,
113-
OriginalSkeletonStorageTrieConfig::new(false),
113+
OriginalSkeletonTrieConfig::new_for_classes_or_storage_trie(false),
114114
)
115115
.await;
116116
let execution_time = std::time::Instant::now() - start;

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
pub(crate) const TEST_PREFIX: &[u8] = &[0];
3028

@@ -70,8 +68,6 @@ impl Leaf for MockLeaf {
7068
}
7169
}
7270

73-
generate_trie_config!(OriginalSkeletonMockTrieConfig, MockLeaf);
74-
7571
pub fn u256_try_into_felt(value: &U256) -> Result<Felt, TypesError<U256>> {
7672
if *value > u256_from_felt(&Felt::MAX) {
7773
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)