Skip to content

refactor: remove dependency on a given tree height of original skeletons #179

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
merged 1 commit into from
Jun 3, 2024

Conversation

nimrod-starkware
Copy link
Contributor

@nimrod-starkware nimrod-starkware commented Jun 2, 2024

First stage of the tree height refactor.
Small trees are now 'large' with an edge node to the root of the small tree.
Next stage is to remove the tree_height parameter inside original skeleton


This change is Reviewable

@codecov-commenter
Copy link

codecov-commenter commented Jun 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.22%. Comparing base (89b1bca) to head (7a3df56).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #179      +/-   ##
==========================================
+ Coverage   62.11%   62.22%   +0.11%     
==========================================
  Files          36       36              
  Lines        1668     1673       +5     
  Branches     1668     1673       +5     
==========================================
+ Hits         1036     1041       +5     
  Misses        583      583              
  Partials       49       49              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on @nimrod-starkware and @TzahiTaub)


crates/committer/src/patricia_merkle_tree/types.rs line 165 at r1 (raw file):

    #[cfg(test)]
    #[allow(dead_code)]
    /// Assumes self represnts an index in a smaller tree height. Returns a node index represents the

typo

Code quote:

represnts

crates/committer/src/patricia_merkle_tree/types.rs line 166 at r1 (raw file):

    #[allow(dead_code)]
    /// Assumes self represnts an index in a smaller tree height. Returns a node index represents the
    /// same index in tree of height 251 as if the smaller tree was 'planted' at the lowest leftmost

rephrase to refer to the starknet tree height, not to the number 251

Code quote:

of height 251

crates/committer/src/patricia_merkle_tree/original_skeleton_tree/create_tree.rs line 220 at r1 (raw file):

    /// 'Plants' the given smaller tree at the lowest leftmost node in order to create a tree of
    /// height TREE_HEIGHT::MAX.
    pub(crate) fn create_actual_sized_tree_from_smaller_tree(smaller_tree: Self) -> Self {

this function isn't used in this PR, correct?
if so, then it doesn't belong in this PR; please remove it (open another PR with a usage later if it's useful)

Code quote:

create_actual_sized_tree_from_smaller_tree

crates/committer/src/patricia_merkle_tree/original_skeleton_tree/create_tree_test.rs line 185 at r1 (raw file):

    let mut sorted_leaf_indices: Vec<NodeIndex> = leaf_modifications
        .keys()
        .map(|idx| idx.to_actual_tree_index(tree_height))

"actual" is confusing, please rename

Suggestion:

from_subtree_index

crates/committer/src/patricia_merkle_tree/original_skeleton_tree/create_tree_test.rs line 201 at r1 (raw file):

        .into_iter()
        .map(|(node_idx, node)| (node_idx.to_actual_tree_index(tree_height), node))
        .collect();

this mapping conversion is also done below; please make a test util out of it

Code quote:

    let mut expected_nodes: HashMap<NodeIndex, OriginalSkeletonNode> = expected_nodes
        .into_iter()
        .map(|(node_idx, node)| (node_idx.to_actual_tree_index(tree_height), node))
        .collect();

crates/committer/src/patricia_merkle_tree/original_skeleton_tree/create_tree_test.rs line 209 at r1 (raw file):

            length: EdgePathLength(TreeHeight::MAX.0 - tree_height.0),
        }),
    );

duplicated logic; write a test util for it

Suggestion:

    add_containing_tree_root(&mut expected_nodes, tree_height);

crates/committer/src/patricia_merkle_tree/original_skeleton_tree/create_tree_test.rs line 285 at r1 (raw file):

                    path: 0.into(),
                    length: EdgePathLength(251 - height),
                }),
  1. no hard coded 251
  2. reuse the logc in add_containing_tree_root (see above)

Code quote:

                NodeIndex::ROOT,
                OriginalSkeletonNode::Edge(PathToBottom {
                    path: 0.into(),
                    length: EdgePathLength(251 - height),
                }),

crates/committer/src/patricia_merkle_tree/original_skeleton_tree/create_tree_test.rs line 338 at r1 (raw file):

pub(crate) fn create_root_edge_entry(
    old_root: u8,
    small_tree_height: TreeHeight,

Suggestion:

subtree_height

Copy link
Contributor Author

@nimrod-starkware nimrod-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @dorimedini-starkware and @TzahiTaub)


crates/committer/src/patricia_merkle_tree/types.rs line 165 at r1 (raw file):

Previously, dorimedini-starkware wrote…

typo

Done


crates/committer/src/patricia_merkle_tree/types.rs line 166 at r1 (raw file):

Previously, dorimedini-starkware wrote…

rephrase to refer to the starknet tree height, not to the number 251

Done, hope that's more obvious


crates/committer/src/patricia_merkle_tree/original_skeleton_tree/create_tree.rs line 220 at r1 (raw file):

Previously, dorimedini-starkware wrote…

this function isn't used in this PR, correct?
if so, then it doesn't belong in this PR; please remove it (open another PR with a usage later if it's useful)

Done. removed


crates/committer/src/patricia_merkle_tree/original_skeleton_tree/create_tree_test.rs line 185 at r1 (raw file):

Previously, dorimedini-starkware wrote…

"actual" is confusing, please rename

Done.


crates/committer/src/patricia_merkle_tree/original_skeleton_tree/create_tree_test.rs line 201 at r1 (raw file):

Previously, dorimedini-starkware wrote…

this mapping conversion is also done below; please make a test util out of it

I used the function create_expected_skeleton which included the logic for the forest.


crates/committer/src/patricia_merkle_tree/original_skeleton_tree/create_tree_test.rs line 209 at r1 (raw file):

Previously, dorimedini-starkware wrote…

duplicated logic; write a test util for it

I used the function create_expected_skeleton which included the logic for the forest.


crates/committer/src/patricia_merkle_tree/original_skeleton_tree/create_tree_test.rs line 285 at r1 (raw file):

Previously, dorimedini-starkware wrote…
  1. no hard coded 251
  2. reuse the logc in add_containing_tree_root (see above)

Done.


crates/committer/src/patricia_merkle_tree/original_skeleton_tree/create_tree_test.rs line 338 at r1 (raw file):

pub(crate) fn create_root_edge_entry(
    old_root: u8,
    small_tree_height: TreeHeight,

Done.

@nimrod-starkware nimrod-starkware force-pushed the nimrod/tree_height/small_tree_test branch from d92462d to 0e1bf97 Compare June 2, 2024 15:33
Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 3 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @nimrod-starkware and @TzahiTaub)


crates/committer/src/patricia_merkle_tree/types.rs line 167 at r2 (raw file):

    /// the same index in the starknet state tree as if the smaller tree was 'planted' at the lowest
    /// leftmost node from the root.
    pub(crate) fn from_subtree_index(sub_tree_index: Self, subtree_height: TreeHeight) -> Self {

subtree is one word on our repo (not english but ok)

Suggestion:

subtree_index: Self, subtree_height: TreeHeight

Copy link
Contributor Author

@nimrod-starkware nimrod-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @dorimedini-starkware and @TzahiTaub)


crates/committer/src/patricia_merkle_tree/types.rs line 167 at r2 (raw file):

Previously, dorimedini-starkware wrote…

subtree is one word on our repo (not english but ok)

Done.

@nimrod-starkware nimrod-starkware force-pushed the nimrod/tree_height/small_tree_test branch from 0e1bf97 to b5e5968 Compare June 3, 2024 05:42
Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 1 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @TzahiTaub)

@nimrod-starkware nimrod-starkware force-pushed the nimrod/tree_height/small_tree_test branch from b5e5968 to 7a3df56 Compare June 3, 2024 06:56
@nimrod-starkware nimrod-starkware added this pull request to the merge queue Jun 3, 2024
Merged via the queue into main with commit 82c9f98 Jun 3, 2024
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants