Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/starknet_committer/src/block_committer/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl From<ThinStateDiff> for StateDiff {
}

/// Trait contains all optional configurations of the committer.
pub trait Config: Debug + Eq + PartialEq {
pub trait Config: Debug + Eq + PartialEq + Send + Sync {
/// Indicates whether a warning should be given in case of a trivial state update.
/// If the configuration is set, it requires that the storage will contain the original data for
/// the modified leaves. Otherwise, it is not required.
Expand Down
4 changes: 2 additions & 2 deletions crates/starknet_committer/src/db/external_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub async fn tree_computation_flow<L, TH>(
leaf_modifications: LeafModifications<L>,
storage: &mut MapStorage,
root_hash: HashOutput,
config: impl OriginalSkeletonTreeConfig<L>,
config: impl OriginalSkeletonTreeConfig,
) -> FilledTreeImpl<L>
where
TH: TreeHashFunction<L> + 'static,
Expand Down Expand Up @@ -72,7 +72,7 @@ pub async fn single_tree_flow_test<
leaf_modifications: LeafModifications<L>,
storage: &mut MapStorage,
root_hash: HashOutput,
config: impl OriginalSkeletonTreeConfig<L>,
config: impl OriginalSkeletonTreeConfig,
) -> String {
// Move from leaf number to actual index.
let leaf_modifications = leaf_modifications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ use crate::db::db_layout::NodeLayout;
use crate::db::facts_db::db::FactsNodeLayout;
use crate::db::facts_db::traversal::get_roots_from_storage;
use crate::db::facts_db::types::FactsSubTree;
use crate::db::trie_traversal::fetch_nodes;
use crate::patricia_merkle_tree::tree::OriginalSkeletonTrieDontCompareConfig;

#[cfg(test)]
#[path = "create_facts_tree_test.rs"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use starknet_patricia::patricia_merkle_tree::external_test_utils::{
create_unmodified_subtree_skeleton_node,
AdditionHash,
MockLeaf,
OriginalSkeletonMockTrieConfig,
};
use starknet_patricia::patricia_merkle_tree::node_data::leaf::LeafModifications;
use starknet_patricia::patricia_merkle_tree::original_skeleton_tree::node::OriginalSkeletonNode;
Expand All @@ -24,6 +23,7 @@ use starknet_patricia_storage::storage_trait::{DbHashMap, DbKey, DbValue};
use starknet_types_core::felt::Felt;

use crate::db::facts_db::create_facts_tree::create_original_skeleton_tree;
use crate::patricia_merkle_tree::tree::OriginalSkeletonTrieConfig;

#[tokio::test]
#[rstest]
Expand Down Expand Up @@ -208,7 +208,7 @@ async fn test_create_tree(
.into_iter()
.map(|(idx, leaf)| (NodeIndex::from_subtree_index(idx, subtree_height), leaf))
.collect();
let config = OriginalSkeletonMockTrieConfig::new(compare_modified_leaves);
let config = OriginalSkeletonTrieConfig::new(compare_modified_leaves);
let mut sorted_leaf_indices: Vec<NodeIndex> = leaf_modifications.keys().copied().collect();
let sorted_leaf_indices = SortedLeafIndices::new(&mut sorted_leaf_indices);
let skeleton_tree = create_original_skeleton_tree(
Expand Down
24 changes: 15 additions & 9 deletions crates/starknet_committer/src/patricia_merkle_tree/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::collections::HashMap;

use starknet_api::core::{ClassHash, ContractAddress};
use starknet_api::hash::HashOutput;
use starknet_patricia::generate_trie_config;
use starknet_patricia::patricia_merkle_tree::original_skeleton_tree::config::OriginalSkeletonTreeConfig;
use starknet_patricia::patricia_merkle_tree::traversal::TraversalResult;
use starknet_patricia::patricia_merkle_tree::types::{NodeIndex, SortedLeafIndices};
Expand All @@ -24,21 +23,28 @@ use crate::patricia_merkle_tree::types::{
RootHashes,
StarknetForestProofs,
};
generate_trie_config!(OriginalSkeletonStorageTrieConfig, StarknetStorageValue);

generate_trie_config!(OriginalSkeletonClassesTrieConfig, CompiledClassHash);
pub(crate) struct OriginalSkeletonTrieConfig {
compare_modified_leaves: bool,
}

pub(crate) struct OriginalSkeletonContractsTrieConfig;
impl OriginalSkeletonTrieConfig {
pub(crate) fn new(should_compare_modified_leaves: bool) -> Self {
Self { compare_modified_leaves: should_compare_modified_leaves }
}
}

impl OriginalSkeletonTreeConfig<ContractState> for OriginalSkeletonContractsTrieConfig {
impl OriginalSkeletonTreeConfig for OriginalSkeletonTrieConfig {
fn compare_modified_leaves(&self) -> bool {
false
self.compare_modified_leaves
}
}

impl OriginalSkeletonContractsTrieConfig {
pub(crate) fn new() -> Self {
Self
pub(crate) struct OriginalSkeletonTrieDontCompareConfig;

impl OriginalSkeletonTreeConfig for OriginalSkeletonTrieDontCompareConfig {
fn compare_modified_leaves(&self) -> bool {
false
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ use super::node_data::leaf::Leaf;
use super::original_skeleton_tree::node::OriginalSkeletonNode;
use super::types::{NodeIndex, SubTreeHeight};
use crate::felt::u256_from_felt;
use crate::generate_trie_config;
use crate::patricia_merkle_tree::errors::TypesError;
use crate::patricia_merkle_tree::node_data::errors::{LeafError, LeafResult};
use crate::patricia_merkle_tree::original_skeleton_tree::config::OriginalSkeletonTreeConfig;

#[derive(Debug, PartialEq, Clone, Copy, Default, Eq)]
pub struct MockLeaf(pub Felt);
Expand Down Expand Up @@ -68,8 +66,6 @@ impl Leaf for MockLeaf {
}
}

generate_trie_config!(OriginalSkeletonMockTrieConfig, MockLeaf);

pub fn u256_try_into_felt(value: &U256) -> Result<Felt, TypesError<U256>> {
if *value > u256_from_felt(&Felt::MAX) {
return Err(TypesError::ConversionError {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,6 @@
use crate::patricia_merkle_tree::node_data::leaf::Leaf;

/// Configures the creation of an original skeleton tree.
pub trait OriginalSkeletonTreeConfig<L: Leaf> {
pub trait OriginalSkeletonTreeConfig {
/// Configures whether modified leaves should be compared to the previous leaves and log out a
/// warning when encountering a trivial modification.
fn compare_modified_leaves(&self) -> bool;
}

// TODO(Aviv 05/08/2024): Move this macro to starknet_committer crate
#[macro_export]
macro_rules! generate_trie_config {
($struct_name:ident, $leaf_type:ty) => {
pub struct $struct_name {
compare_modified_leaves: bool,
}

impl $struct_name {
#[allow(dead_code)]
pub fn new(compare_modified_leaves: bool) -> Self {
Self { compare_modified_leaves }
}
}

impl OriginalSkeletonTreeConfig<$leaf_type> for $struct_name {
fn compare_modified_leaves(&self) -> bool {
self.compare_modified_leaves
}
}
};
}

#[derive(Default)]
/// Generic config that doesn't compare the modified leaves.
pub struct NoCompareOriginalSkeletonTrieConfig<L: Leaf>(std::marker::PhantomData<L>);

impl<L: Leaf> OriginalSkeletonTreeConfig<L> for NoCompareOriginalSkeletonTrieConfig<L> {
fn compare_modified_leaves(&self) -> bool {
false
}
}
Loading