diff --git a/crates/committer/src/patricia_merkle_tree/external_test_utils.rs b/crates/committer/src/patricia_merkle_tree/external_test_utils.rs index fbc35ae6..14716234 100644 --- a/crates/committer/src/patricia_merkle_tree/external_test_utils.rs +++ b/crates/committer/src/patricia_merkle_tree/external_test_utils.rs @@ -12,7 +12,7 @@ use crate::storage::map_storage::MapStorage; use rand::Rng; use super::filled_tree::tree::{FilledTree, StorageTrie}; -use super::node_data::leaf::{LeafData, LeafModifications, SkeletonLeaf}; +use super::node_data::leaf::{Leaf, LeafModifications, SkeletonLeaf}; use super::original_skeleton_tree::config::OriginalSkeletonStorageTrieConfig; use super::original_skeleton_tree::tree::{OriginalSkeletonTree, OriginalSkeletonTreeImpl}; use super::types::{NodeIndex, SortedLeafIndices}; diff --git a/crates/committer/src/patricia_merkle_tree/filled_tree/errors.rs b/crates/committer/src/patricia_merkle_tree/filled_tree/errors.rs index c611d953..073a2d37 100644 --- a/crates/committer/src/patricia_merkle_tree/filled_tree/errors.rs +++ b/crates/committer/src/patricia_merkle_tree/filled_tree/errors.rs @@ -6,10 +6,10 @@ use crate::patricia_merkle_tree::filled_tree::node::FilledNode; use crate::patricia_merkle_tree::node_data::errors::LeafError; use crate::patricia_merkle_tree::node_data::leaf::ContractState; use crate::patricia_merkle_tree::updated_skeleton_tree::errors::UpdatedSkeletonTreeError; -use crate::patricia_merkle_tree::{node_data::leaf::LeafData, types::NodeIndex}; +use crate::patricia_merkle_tree::{node_data::leaf::Leaf, types::NodeIndex}; #[derive(thiserror::Error, Debug)] -pub enum FilledTreeError { +pub enum FilledTreeError { #[error("Deleted leaf at index {0:?} appears in the updated skeleton tree.")] DeletedLeafInSkeleton(NodeIndex), #[error("Double update at node {index:?}. Existing value: {existing_value:?}.")] diff --git a/crates/committer/src/patricia_merkle_tree/filled_tree/node.rs b/crates/committer/src/patricia_merkle_tree/filled_tree/node.rs index b8319029..116209c5 100644 --- a/crates/committer/src/patricia_merkle_tree/filled_tree/node.rs +++ b/crates/committer/src/patricia_merkle_tree/filled_tree/node.rs @@ -4,7 +4,7 @@ use crate::felt::Felt; use crate::hash::hash_trait::HashOutput; use crate::impl_from_hex_for_felt_wrapper; use crate::patricia_merkle_tree::node_data::inner_node::NodeData; -use crate::patricia_merkle_tree::node_data::leaf::LeafData; +use crate::patricia_merkle_tree::node_data::leaf::Leaf; // TODO(Nimrod, 1/6/2024): Use the ClassHash defined in starknet-types-core when available. @@ -24,7 +24,7 @@ impl_from_hex_for_felt_wrapper!(CompiledClassHash); #[derive(Clone, Debug, PartialEq, Eq)] /// A node in a Patricia-Merkle tree which was modified during an update. -pub struct FilledNode { +pub struct FilledNode { pub hash: HashOutput, pub data: NodeData, } diff --git a/crates/committer/src/patricia_merkle_tree/filled_tree/node_serde.rs b/crates/committer/src/patricia_merkle_tree/filled_tree/node_serde.rs index 3af27fd1..c8b641c1 100644 --- a/crates/committer/src/patricia_merkle_tree/filled_tree/node_serde.rs +++ b/crates/committer/src/patricia_merkle_tree/filled_tree/node_serde.rs @@ -4,7 +4,7 @@ use crate::patricia_merkle_tree::filled_tree::node::FilledNode; use crate::patricia_merkle_tree::node_data::inner_node::{ BinaryData, EdgeData, EdgePathLength, NodeData, PathToBottom, }; -use crate::patricia_merkle_tree::node_data::leaf::LeafData; +use crate::patricia_merkle_tree::node_data::leaf::Leaf; use crate::storage::db_object::DBObject; use crate::storage::errors::DeserializationError; use crate::storage::storage_trait::{StorageKey, StoragePrefix, StorageValue}; @@ -27,7 +27,7 @@ pub(crate) struct LeafCompiledClassToSerialize { pub(crate) compiled_class_hash: Felt, } -impl FilledNode { +impl FilledNode { pub fn suffix(&self) -> [u8; SERIALIZE_HASH_BYTES] { self.hash.0.to_bytes_be() } @@ -37,7 +37,7 @@ impl FilledNode { } } -impl DBObject for FilledNode { +impl DBObject for FilledNode { /// This method serializes the filled node into a byte vector, where: /// - For binary nodes: Concatenates left and right hashes. /// - For edge nodes: Concatenates bottom hash, path, and path length. @@ -84,7 +84,7 @@ impl DBObject for FilledNode { } } -impl FilledNode { +impl FilledNode { /// Deserializes filled nodes. pub(crate) fn deserialize( node_hash: HashOutput, diff --git a/crates/committer/src/patricia_merkle_tree/filled_tree/tree.rs b/crates/committer/src/patricia_merkle_tree/filled_tree/tree.rs index cd294fef..6211fb63 100644 --- a/crates/committer/src/patricia_merkle_tree/filled_tree/tree.rs +++ b/crates/committer/src/patricia_merkle_tree/filled_tree/tree.rs @@ -14,7 +14,7 @@ use crate::patricia_merkle_tree::node_data::inner_node::BinaryData; use crate::patricia_merkle_tree::node_data::inner_node::EdgeData; use crate::patricia_merkle_tree::node_data::inner_node::NodeData; use crate::patricia_merkle_tree::node_data::leaf::ContractState; -use crate::patricia_merkle_tree::node_data::leaf::LeafData; +use crate::patricia_merkle_tree::node_data::leaf::Leaf; use crate::patricia_merkle_tree::node_data::leaf::LeafModifications; use crate::patricia_merkle_tree::types::NodeIndex; use crate::patricia_merkle_tree::updated_skeleton_tree::hash_function::TreeHashFunction; @@ -32,7 +32,7 @@ pub(crate) type FilledTreeResult = Result>; /// Consider a Patricia-Merkle Tree which has been updated with new leaves. /// FilledTree consists of all nodes which were modified in the update, including their updated /// data and hashes. -pub(crate) trait FilledTree: Sized { +pub(crate) trait FilledTree: Sized { /// Computes and returns the filled tree. async fn create + 'static>( updated_skeleton: impl UpdatedSkeletonTree + 'static, @@ -48,7 +48,7 @@ pub(crate) trait FilledTree: Sized { } #[derive(Debug, Eq, PartialEq)] -pub struct FilledTreeImpl { +pub struct FilledTreeImpl { pub tree_map: HashMap>, pub root_hash: HashOutput, } @@ -58,7 +58,7 @@ pub type ClassesTrie = FilledTreeImpl; pub type ContractsTrie = FilledTreeImpl; pub type StorageTrieMap = HashMap; -impl FilledTreeImpl { +impl FilledTreeImpl { fn initialize_with_placeholders( updated_skeleton: &impl UpdatedSkeletonTree, ) -> HashMap>>> { @@ -213,7 +213,7 @@ impl FilledTreeImpl { } } -impl FilledTree for FilledTreeImpl { +impl FilledTree for FilledTreeImpl { async fn create + 'static>( updated_skeleton: impl UpdatedSkeletonTree + 'static, leaf_modifications: Arc>, diff --git a/crates/committer/src/patricia_merkle_tree/node_data/inner_node.rs b/crates/committer/src/patricia_merkle_tree/node_data/inner_node.rs index 2e59ea96..20f3357a 100644 --- a/crates/committer/src/patricia_merkle_tree/node_data/inner_node.rs +++ b/crates/committer/src/patricia_merkle_tree/node_data/inner_node.rs @@ -1,7 +1,7 @@ use crate::felt::Felt; use crate::hash::hash_trait::HashOutput; use crate::patricia_merkle_tree::node_data::errors::{EdgePathError, PathToBottomError}; -use crate::patricia_merkle_tree::node_data::leaf::LeafData; +use crate::patricia_merkle_tree::node_data::leaf::Leaf; use crate::patricia_merkle_tree::types::{NodeIndex, SubTreeHeight}; use ethnum::U256; @@ -15,7 +15,7 @@ pub mod inner_node_test; #[cfg_attr(any(test, feature = "testing"), derive(EnumDiscriminants))] #[cfg_attr(any(test, feature = "testing"), strum_discriminants(derive(EnumIter)))] // A Patricia-Merkle tree node's data, i.e., the pre-image of its hash. -pub enum NodeData { +pub enum NodeData { Binary(BinaryData), Edge(EdgeData), Leaf(L), diff --git a/crates/committer/src/patricia_merkle_tree/node_data/leaf.rs b/crates/committer/src/patricia_merkle_tree/node_data/leaf.rs index 1dcc6dae..7cdde637 100644 --- a/crates/committer/src/patricia_merkle_tree/node_data/leaf.rs +++ b/crates/committer/src/patricia_merkle_tree/node_data/leaf.rs @@ -11,7 +11,7 @@ use crate::patricia_merkle_tree::node_data::errors::{LeafError, LeafResult}; use crate::patricia_merkle_tree::types::NodeIndex; use crate::storage::db_object::{DBObject, Deserializable}; -pub trait LeafData: Clone + Sync + Send + DBObject + Deserializable + Default + Debug + Eq { +pub trait Leaf: Clone + Sync + Send + DBObject + Deserializable + Default + Debug + Eq { /// Returns true if leaf is empty. fn is_empty(&self) -> bool; @@ -47,7 +47,7 @@ pub struct ContractState { pub class_hash: ClassHash, } -impl LeafData for StarknetStorageValue { +impl Leaf for StarknetStorageValue { fn is_empty(&self) -> bool { self.0 == Felt::ZERO } @@ -60,7 +60,7 @@ impl LeafData for StarknetStorageValue { } } -impl LeafData for CompiledClassHash { +impl Leaf for CompiledClassHash { fn is_empty(&self) -> bool { self.0 == Felt::ZERO } @@ -73,7 +73,7 @@ impl LeafData for CompiledClassHash { } } -impl LeafData for ContractState { +impl Leaf for ContractState { fn is_empty(&self) -> bool { self.nonce.0 == Felt::ZERO && self.class_hash.0 == Felt::ZERO diff --git a/crates/committer/src/patricia_merkle_tree/node_data/leaf_serde_test.rs b/crates/committer/src/patricia_merkle_tree/node_data/leaf_serde_test.rs index 74dfbe4d..2c86c25b 100644 --- a/crates/committer/src/patricia_merkle_tree/node_data/leaf_serde_test.rs +++ b/crates/committer/src/patricia_merkle_tree/node_data/leaf_serde_test.rs @@ -4,7 +4,7 @@ use crate::hash::hash_trait::HashOutput; use crate::patricia_merkle_tree::filled_tree::node::CompiledClassHash; use crate::patricia_merkle_tree::filled_tree::node::{ClassHash, Nonce}; use crate::patricia_merkle_tree::node_data::leaf::ContractState; -use crate::patricia_merkle_tree::node_data::leaf::LeafData; +use crate::patricia_merkle_tree::node_data::leaf::Leaf; use rstest::rstest; use std::fmt::Debug; @@ -26,7 +26,7 @@ use std::fmt::Debug; nonce: Nonce(Felt::from(23479515749555_u128)), storage_root_hash: HashOutput(Felt::from(2359743529034_u128)), class_hash: ClassHash(Felt::from(1349866415897798_u128)) }) ] -fn test_leaf_serde(#[case] leaf: L) { +fn test_leaf_serde(#[case] leaf: L) { let serialized = leaf.serialize(); let deserialized = L::deserialize(&serialized).unwrap(); assert_eq!(deserialized, leaf); @@ -36,6 +36,6 @@ fn test_leaf_serde(#[case] leaf: L) { #[case::storage_leaf(StarknetStorageValue::default())] #[case::compiled_class_leaf(CompiledClassHash::default())] #[case::contract_state_leaf(ContractState::default())] -fn test_default_is_empty(#[case] leaf: L) { +fn test_default_is_empty(#[case] leaf: L) { assert!(leaf.is_empty()) } diff --git a/crates/committer/src/patricia_merkle_tree/original_skeleton_tree/config.rs b/crates/committer/src/patricia_merkle_tree/original_skeleton_tree/config.rs index feb4b53e..d2eafd3c 100644 --- a/crates/committer/src/patricia_merkle_tree/original_skeleton_tree/config.rs +++ b/crates/committer/src/patricia_merkle_tree/original_skeleton_tree/config.rs @@ -1,12 +1,12 @@ use crate::block_committer::input::StarknetStorageValue; use crate::patricia_merkle_tree::filled_tree::node::CompiledClassHash; -use crate::patricia_merkle_tree::node_data::leaf::{ContractState, LeafData, LeafModifications}; +use crate::patricia_merkle_tree::node_data::leaf::{ContractState, Leaf, LeafModifications}; use crate::patricia_merkle_tree::original_skeleton_tree::errors::OriginalSkeletonTreeError; use crate::patricia_merkle_tree::original_skeleton_tree::tree::OriginalSkeletonTreeResult; use crate::patricia_merkle_tree::types::NodeIndex; /// Configures the creation of an original skeleton tree. -pub(crate) trait OriginalSkeletonTreeConfig { +pub(crate) 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; diff --git a/crates/committer/src/patricia_merkle_tree/original_skeleton_tree/create_tree.rs b/crates/committer/src/patricia_merkle_tree/original_skeleton_tree/create_tree.rs index ddc82518..707758da 100644 --- a/crates/committer/src/patricia_merkle_tree/original_skeleton_tree/create_tree.rs +++ b/crates/committer/src/patricia_merkle_tree/original_skeleton_tree/create_tree.rs @@ -4,7 +4,7 @@ use crate::patricia_merkle_tree::node_data::inner_node::BinaryData; use crate::patricia_merkle_tree::node_data::inner_node::EdgeData; use crate::patricia_merkle_tree::node_data::inner_node::NodeData; use crate::patricia_merkle_tree::node_data::inner_node::PathToBottom; -use crate::patricia_merkle_tree::node_data::leaf::LeafData; +use crate::patricia_merkle_tree::node_data::leaf::Leaf; use crate::patricia_merkle_tree::original_skeleton_tree::config::OriginalSkeletonTreeConfig; use crate::patricia_merkle_tree::original_skeleton_tree::tree::OriginalSkeletonTreeImpl; use crate::patricia_merkle_tree::original_skeleton_tree::tree::OriginalSkeletonTreeResult; @@ -119,7 +119,7 @@ impl OriginalSkeletonTreeImpl { /// Given a list of subtrees, traverses towards their leaves and fetches all non-empty, /// unmodified nodes. If `compare_modified_leaves` is set, function logs out a warning when /// encountering a trivial modification. Fills the previous leaf values if it is not none. - fn fetch_nodes( + fn fetch_nodes( &mut self, subtrees: Vec>, storage: &impl Storage, @@ -213,7 +213,7 @@ impl OriginalSkeletonTreeImpl { self.fetch_nodes::(next_subtrees, storage, config, previous_leaves) } - fn calculate_subtrees_roots( + fn calculate_subtrees_roots( subtrees: &[SubTree<'_>], storage: &impl Storage, ) -> OriginalSkeletonTreeResult>> { @@ -246,7 +246,7 @@ impl OriginalSkeletonTreeImpl { Ok(subtrees_roots) } - pub(crate) fn create_impl( + pub(crate) fn create_impl( storage: &impl Storage, root_hash: HashOutput, sorted_leaf_indices: SortedLeafIndices<'_>, @@ -274,7 +274,7 @@ impl OriginalSkeletonTreeImpl { Ok(skeleton_tree) } - pub(crate) fn create_and_get_previous_leaves_impl( + pub(crate) fn create_and_get_previous_leaves_impl( storage: &impl Storage, root_hash: HashOutput, sorted_leaf_indices: SortedLeafIndices<'_>, @@ -344,7 +344,7 @@ impl OriginalSkeletonTreeImpl { /// Given leaf indices that were previously empty leaves, logs out a warning for trivial /// modification if a leaf is modified to an empty leaf. /// If this check is suppressed by configuration, does nothing. - fn log_warning_for_empty_leaves + Debug>( + fn log_warning_for_empty_leaves + Debug>( leaf_indices: &[T], config: &impl OriginalSkeletonTreeConfig, ) -> OriginalSkeletonTreeResult<()> { diff --git a/crates/committer/src/patricia_merkle_tree/original_skeleton_tree/tree.rs b/crates/committer/src/patricia_merkle_tree/original_skeleton_tree/tree.rs index 6343efa5..b099044b 100644 --- a/crates/committer/src/patricia_merkle_tree/original_skeleton_tree/tree.rs +++ b/crates/committer/src/patricia_merkle_tree/original_skeleton_tree/tree.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use crate::hash::hash_trait::HashOutput; -use crate::patricia_merkle_tree::node_data::leaf::LeafData; +use crate::patricia_merkle_tree::node_data::leaf::Leaf; use crate::patricia_merkle_tree::original_skeleton_tree::config::OriginalSkeletonTreeConfig; use crate::patricia_merkle_tree::original_skeleton_tree::errors::OriginalSkeletonTreeError; use crate::patricia_merkle_tree::original_skeleton_tree::node::OriginalSkeletonNode; @@ -16,7 +16,7 @@ pub(crate) type OriginalSkeletonTreeResult = Result( + fn create( storage: &impl Storage, root_hash: HashOutput, sorted_leaf_indices: SortedLeafIndices<'_>, @@ -27,7 +27,7 @@ pub(crate) trait OriginalSkeletonTree: Sized { fn get_nodes_mut(&mut self) -> &mut OriginalSkeletonNodeMap; - fn create_and_get_previous_leaves( + fn create_and_get_previous_leaves( storage: &impl Storage, root_hash: HashOutput, sorted_leaf_indices: SortedLeafIndices<'_>, @@ -42,7 +42,7 @@ pub(crate) struct OriginalSkeletonTreeImpl { } impl OriginalSkeletonTree for OriginalSkeletonTreeImpl { - fn create( + fn create( storage: &impl Storage, root_hash: HashOutput, sorted_leaf_indices: SortedLeafIndices<'_>, @@ -59,7 +59,7 @@ impl OriginalSkeletonTree for OriginalSkeletonTreeImpl { &mut self.nodes } - fn create_and_get_previous_leaves( + fn create_and_get_previous_leaves( storage: &impl Storage, root_hash: HashOutput, sorted_leaf_indices: SortedLeafIndices<'_>, diff --git a/crates/committer/src/patricia_merkle_tree/updated_skeleton_tree/hash_function.rs b/crates/committer/src/patricia_merkle_tree/updated_skeleton_tree/hash_function.rs index 58cabf23..ad00cd46 100644 --- a/crates/committer/src/patricia_merkle_tree/updated_skeleton_tree/hash_function.rs +++ b/crates/committer/src/patricia_merkle_tree/updated_skeleton_tree/hash_function.rs @@ -7,7 +7,7 @@ use crate::patricia_merkle_tree::filled_tree::node::CompiledClassHash; use crate::patricia_merkle_tree::node_data::inner_node::{ BinaryData, EdgeData, NodeData, PathToBottom, }; -use crate::patricia_merkle_tree::node_data::leaf::{ContractState, LeafData}; +use crate::patricia_merkle_tree::node_data::leaf::{ContractState, Leaf}; #[cfg(test)] #[path = "hash_function_test.rs"] @@ -35,7 +35,7 @@ impl HashFunction for PoseidonHashFunction { } } -pub(crate) trait TreeHashFunction { +pub(crate) trait TreeHashFunction { /// Computes the hash of the given leaf. fn compute_leaf_hash(leaf_data: &L) -> HashOutput;