Skip to content

Commit cd6a0d4

Browse files
committed
starknet_committer,starknet_patricia: remove generic config
1 parent 27aaa03 commit cd6a0d4

File tree

7 files changed

+23
-54
lines changed

7 files changed

+23
-54
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
@@ -24,7 +24,7 @@ pub async fn tree_computation_flow<L, TH>(
2424
leaf_modifications: LeafModifications<L>,
2525
storage: &mut MapStorage,
2626
root_hash: HashOutput,
27-
config: impl OriginalSkeletonTreeConfig<L>,
27+
config: impl OriginalSkeletonTreeConfig,
2828
) -> FilledTreeImpl<L>
2929
where
3030
TH: TreeHashFunction<L> + 'static,
@@ -72,7 +72,7 @@ pub async fn single_tree_flow_test<
7272
leaf_modifications: LeafModifications<L>,
7373
storage: &mut MapStorage,
7474
root_hash: HashOutput,
75-
config: impl OriginalSkeletonTreeConfig<L>,
75+
config: impl OriginalSkeletonTreeConfig,
7676
) -> String {
7777
// Move from leaf number to actual index.
7878
let leaf_modifications = leaf_modifications

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ use crate::db::db_layout::NodeLayout;
2828
use crate::db::facts_db::db::FactsNodeLayout;
2929
use crate::db::facts_db::traversal::get_roots_from_storage;
3030
use crate::db::facts_db::types::FactsSubTree;
31+
use crate::db::trie_traversal::fetch_nodes;
32+
use crate::patricia_merkle_tree::tree::OriginalSkeletonTrieDontCompareConfig;
3133

3234
#[cfg(test)]
3335
#[path = "create_facts_tree_test.rs"]

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/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)