Skip to content

refactor: remove tree height field from updated skeleton tree #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
17 changes: 4 additions & 13 deletions crates/committer/src/patricia_merkle_tree/filled_tree/tree_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::patricia_merkle_tree::node_data::inner_node::{
BinaryData, EdgeData, EdgePathLength, NodeData, PathToBottom,
};
use crate::patricia_merkle_tree::node_data::leaf::LeafDataImpl;
use crate::patricia_merkle_tree::types::{NodeIndex, TreeHeight};
use crate::patricia_merkle_tree::types::NodeIndex;
use crate::patricia_merkle_tree::updated_skeleton_tree::hash_function::TreeHashFunctionImpl;
use crate::patricia_merkle_tree::updated_skeleton_tree::node::UpdatedSkeletonNode;
use crate::patricia_merkle_tree::updated_skeleton_tree::tree::{
Expand All @@ -23,10 +23,7 @@ async fn test_filled_tree_sanity() {
let new_leaf_index = NodeIndex::ROOT;
skeleton_tree.insert(new_leaf_index, UpdatedSkeletonNode::Leaf);
let modifications = HashMap::from([(new_leaf_index, new_filled_leaf)]);
let updated_skeleton_tree = UpdatedSkeletonTreeImpl {
tree_height: TreeHeight(1),
skeleton_tree,
};
let updated_skeleton_tree = UpdatedSkeletonTreeImpl { skeleton_tree };
let root_hash =
FilledTreeImpl::create::<TreeHashFunctionImpl>(updated_skeleton_tree, modifications)
.await
Expand Down Expand Up @@ -75,10 +72,7 @@ async fn test_small_filled_tree() {
.collect();
let skeleton_tree: UpdatedSkeletonNodeMap = nodes_in_skeleton_tree.into_iter().collect();

let updated_skeleton_tree = UpdatedSkeletonTreeImpl {
tree_height: TreeHeight(7),
skeleton_tree,
};
let updated_skeleton_tree = UpdatedSkeletonTreeImpl { skeleton_tree };
let modifications = new_leaves
.iter()
.map(|(index, value)| {
Expand Down Expand Up @@ -186,10 +180,7 @@ async fn test_small_tree_with_sibling_nodes() {
];
let skeleton_tree: UpdatedSkeletonNodeMap = nodes_in_skeleton_tree.into_iter().collect();

let updated_skeleton_tree = UpdatedSkeletonTreeImpl {
tree_height: TreeHeight(7),
skeleton_tree,
};
let updated_skeleton_tree = UpdatedSkeletonTreeImpl { skeleton_tree };
let modifications = HashMap::from([(
NodeIndex::from(new_leaf_index),
LeafDataImpl::StorageValue(Felt::from_hex(new_leaf).unwrap()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::HashMap;
use crate::hash::hash_trait::HashOutput;
use crate::patricia_merkle_tree::original_skeleton_tree::errors::OriginalSkeletonTreeError;
use crate::patricia_merkle_tree::original_skeleton_tree::node::OriginalSkeletonNode;
use crate::patricia_merkle_tree::types::{NodeIndex, TreeHeight};
use crate::patricia_merkle_tree::types::NodeIndex;

use crate::storage::storage_trait::Storage;

Expand All @@ -26,10 +26,9 @@ pub(crate) trait OriginalSkeletonTree {
fn get_nodes(&self) -> &OriginalSkeletonNodeMap;

fn get_nodes_mut(&mut self) -> &mut OriginalSkeletonNodeMap;

fn get_tree_height(&self) -> &TreeHeight;
}

// TODO(Dori, 1/7/2024): Make this a tuple struct.
#[derive(Debug, Eq, PartialEq)]
pub(crate) struct OriginalSkeletonTreeImpl {
pub(crate) nodes: HashMap<NodeIndex, OriginalSkeletonNode>,
Expand All @@ -51,8 +50,4 @@ impl OriginalSkeletonTree for OriginalSkeletonTreeImpl {
fn get_nodes_mut(&mut self) -> &mut OriginalSkeletonNodeMap {
&mut self.nodes
}

fn get_tree_height(&self) -> &TreeHeight {
&TreeHeight::MAX
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ use crate::patricia_merkle_tree::updated_skeleton_tree::tree::UpdatedSkeletonTre

#[fixture]
fn updated_skeleton(
#[default(TreeHeight::MAX)] tree_height: TreeHeight,
#[default(&[])] original_skeleton: &[(NodeIndex, OriginalSkeletonNode)],
#[default(&[])] leaf_modifications: &[(U256, u8)],
) -> UpdatedSkeletonTreeImpl {
UpdatedSkeletonTreeImpl {
tree_height,
skeleton_tree: leaf_modifications
.iter()
.filter(|(_, leaf_val)| *leaf_val != 0)
Expand Down Expand Up @@ -215,8 +213,7 @@ fn test_node_from_binary_data(
#[case] _leaf_modifications: &[(U256, u8)],
#[case] expected_node: TempSkeletonNode,
#[case] expected_skeleton_additions: &[(NodeIndex, UpdatedSkeletonNode)],
#[with(TreeHeight::MAX, &[], _leaf_modifications)]
mut updated_skeleton: UpdatedSkeletonTreeImpl,
#[with(&[], _leaf_modifications)] mut updated_skeleton: UpdatedSkeletonTreeImpl,
) {
let mut expected_skeleton_tree = updated_skeleton.skeleton_tree.clone();
expected_skeleton_tree.extend(expected_skeleton_additions.iter().cloned());
Expand Down Expand Up @@ -283,8 +280,7 @@ fn test_node_from_edge_data(
#[case] _leaf_modifications: &[(U256, u8)],
#[case] expected_node: TempSkeletonNode,
#[case] expected_skeleton_additions: &[(NodeIndex, UpdatedSkeletonNode)],
#[with(TreeHeight::MAX, &[], _leaf_modifications)]
mut updated_skeleton: UpdatedSkeletonTreeImpl,
#[with(&[], _leaf_modifications)] mut updated_skeleton: UpdatedSkeletonTreeImpl,
) {
let mut expected_skeleton_tree = updated_skeleton.skeleton_tree.clone();
expected_skeleton_tree.extend(expected_skeleton_additions.iter().cloned());
Expand Down Expand Up @@ -325,7 +321,7 @@ fn test_update_node_in_empty_tree(
#[case] leaf_modifications: &[(U256, u8)],
#[case] expected_node: TempSkeletonNode,
#[case] expected_skeleton_additions: &[(NodeIndex, UpdatedSkeletonNode)],
#[with(TreeHeight::MAX, &[], leaf_modifications)] mut updated_skeleton: UpdatedSkeletonTreeImpl,
#[with(&[], leaf_modifications)] mut updated_skeleton: UpdatedSkeletonTreeImpl,
) {
let leaf_indices: Vec<NodeIndex> = leaf_modifications
.iter()
Expand Down Expand Up @@ -471,8 +467,7 @@ fn test_update_node_in_nonempty_tree(
#[case] leaf_modifications: &[(U256, u8)],
#[case] expected_node: TempSkeletonNode,
#[case] expected_skeleton_additions: &[(NodeIndex, UpdatedSkeletonNode)],
#[with(TreeHeight::MAX, &original_skeleton, leaf_modifications)]
mut updated_skeleton: UpdatedSkeletonTreeImpl,
#[with(&original_skeleton, leaf_modifications)] mut updated_skeleton: UpdatedSkeletonTreeImpl,
) {
let mut original_skeleton: OriginalSkeletonNodeMap = original_skeleton.into_iter().collect();
let leaf_indices: Vec<NodeIndex> = leaf_modifications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::HashMap;
use crate::patricia_merkle_tree::node_data::leaf::{LeafModifications, SkeletonLeaf};
use crate::patricia_merkle_tree::original_skeleton_tree::node::OriginalSkeletonNode;
use crate::patricia_merkle_tree::original_skeleton_tree::tree::OriginalSkeletonTree;
use crate::patricia_merkle_tree::types::{NodeIndex, TreeHeight};
use crate::patricia_merkle_tree::types::NodeIndex;
use crate::patricia_merkle_tree::updated_skeleton_tree::compute_updated_skeleton_tree::TempSkeletonNode;
use crate::patricia_merkle_tree::updated_skeleton_tree::errors::UpdatedSkeletonTreeError;
use crate::patricia_merkle_tree::updated_skeleton_tree::node::UpdatedSkeletonNode;
Expand Down Expand Up @@ -35,10 +35,8 @@ pub(crate) trait UpdatedSkeletonTree: Sized + Send + Sync {
/// Returns the node with the given index.
fn get_node(&self, index: NodeIndex) -> UpdatedSkeletonTreeResult<&UpdatedSkeletonNode>;
}

// TODO(Dori, 1/7/2024): Make this a tuple struct.
pub(crate) struct UpdatedSkeletonTreeImpl {
#[allow(dead_code)]
pub(crate) tree_height: TreeHeight,
pub(crate) skeleton_tree: UpdatedSkeletonNodeMap,
}

Expand All @@ -49,10 +47,7 @@ impl UpdatedSkeletonTree for UpdatedSkeletonTreeImpl {
) -> UpdatedSkeletonTreeResult<Self> {
let skeleton_tree = Self::finalize_bottom_layer(original_skeleton, leaf_modifications);

let mut updated_skeleton_tree = UpdatedSkeletonTreeImpl {
tree_height: *original_skeleton.get_tree_height(),
skeleton_tree,
};
let mut updated_skeleton_tree = UpdatedSkeletonTreeImpl { skeleton_tree };

let temp_root_node =
updated_skeleton_tree.finalize_middle_layers(original_skeleton, leaf_modifications);
Expand Down
Loading