Skip to content

build: impl serialize for filled tree #116

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
May 22, 2024

Conversation

AvivYossef-starkware
Copy link
Collaborator

@AvivYossef-starkware AvivYossef-starkware commented May 15, 2024

This change is Reviewable

@codecov-commenter
Copy link

codecov-commenter commented May 15, 2024

Codecov Report

Attention: Patch coverage is 0% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 71.83%. Comparing base (c5a134e) to head (2e06b90).

Files Patch % Lines
...itter/src/patricia_merkle_tree/filled_tree/tree.rs 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #116      +/-   ##
==========================================
- Coverage   72.03%   71.83%   -0.20%     
==========================================
  Files          31       31              
  Lines        1087     1090       +3     
  Branches     1087     1090       +3     
==========================================
  Hits          783      783              
- Misses        267      270       +3     
  Partials       37       37              

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

Copy link
Contributor

@amosStarkware amosStarkware 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: 0 of 1 files reviewed, 4 unresolved discussions (waiting on @AvivYossef-starkware and @dorimedini-starkware)


crates/committer/src/patricia_merkle_tree/filled_tree/tree.rs line 17 at r1 (raw file):

pub(crate) trait FilledTree<L: LeafData> {
    /// Serializes the tree into storage. Returns hash set of keys of the serialized nodes,
    /// if successful.

Please add:
/// Serializes the tree and returns the resulting storage keys and values.

Code quote:

    /// Serializes the tree into storage. Returns hash set of keys of the serialized nodes,
    /// if successful.

crates/committer/src/patricia_merkle_tree/filled_tree/tree.rs line 17 at r1 (raw file):

pub(crate) trait FilledTree<L: LeafData> {
    #[allow(dead_code)]
    fn serialize(&self) -> HashMap<StorageKey, StorageValue>;

Code quote (i):

fn serialize(&self) -> HashMap<StorageKey, StorageValue>;

Code snippet (ii):

fn serialize(&self) -> Result<HashMap<StorageKey, StorageValue>>;

crates/committer/src/patricia_merkle_tree/filled_tree/tree.rs line 42 at r1 (raw file):

    /// to a storage key and its serialized storage value.
    /// This function iterates over each node in the tree, using the node's `db_key` as the hashmap key
    /// and the result of the node's `serialize` method as the value.

please delete - no need to explain the implementation in the docstring.

Code quote:

    /// Serializes the current state of the tree into a hashmap where each key-value pair corresponds
    /// to a storage key and its serialized storage value.
    /// This function iterates over each node in the tree, using the node's `db_key` as the hashmap key
    /// and the result of the node's `serialize` method as the value.

crates/committer/src/patricia_merkle_tree/filled_tree/tree.rs line 48 at r1 (raw file):

            serialize_tree_map.insert(node.db_key(), node.serialize());
        }
        serialize_tree_map

Code quote (i):

        let mut serialize_tree_map: HashMap<StorageKey, StorageValue> = HashMap::new();
        for (_node_index, node) in self.tree_map.iter() {
            serialize_tree_map.insert(node.db_key(), node.serialize());
        }
        serialize_tree_map

Code snippet (ii):

        self.get_all_nodes()
            .iter()
            .map(|(_, node)| (node.db_key(), node.serialize()))
            .collect()

@AvivYossef-starkware AvivYossef-starkware force-pushed the aviv/impl_filledtree_serialize branch from 6413af5 to 23a959e Compare May 15, 2024 13:01
@AvivYossef-starkware AvivYossef-starkware force-pushed the aviv/refactor_leaf_data branch 3 times, most recently from 0184ff8 to 7a44f0d Compare May 15, 2024 13:16
@AvivYossef-starkware AvivYossef-starkware force-pushed the aviv/impl_filledtree_serialize branch 2 times, most recently from d6f7eb9 to 8e9a49e Compare May 19, 2024 10:20
@AvivYossef-starkware AvivYossef-starkware changed the base branch from aviv/refactor_leaf_data to dori/move-filled-tree-creation-to-filled-tree-trait May 19, 2024 10:24
Copy link
Collaborator Author

@AvivYossef-starkware AvivYossef-starkware left a comment

Choose a reason for hiding this comment

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

there is a separate PR for the first commit.

Reviewable status: 0 of 6 files reviewed, 4 unresolved discussions (waiting on @amosStarkware and @dorimedini-starkware)


crates/committer/src/patricia_merkle_tree/filled_tree/tree.rs line 17 at r1 (raw file):

Previously, amosStarkware wrote…

Please add:
/// Serializes the tree and returns the resulting storage keys and values.

See below.


crates/committer/src/patricia_merkle_tree/filled_tree/tree.rs line 17 at r1 (raw file):

pub(crate) trait FilledTree<L: LeafData> {
    #[allow(dead_code)]
    fn serialize(&self) -> HashMap<StorageKey, StorageValue>;

Why Result?
It's always successful.


crates/committer/src/patricia_merkle_tree/filled_tree/tree.rs line 42 at r1 (raw file):

Previously, amosStarkware wrote…

please delete - no need to explain the implementation in the docstring.

Done.


crates/committer/src/patricia_merkle_tree/filled_tree/tree.rs line 48 at r1 (raw file):

            serialize_tree_map.insert(node.db_key(), node.serialize());
        }
        serialize_tree_map

Done.

@dorimedini-starkware dorimedini-starkware force-pushed the dori/move-filled-tree-creation-to-filled-tree-trait branch 3 times, most recently from 2aa06b9 to d1a5e76 Compare May 20, 2024 12:11
@AvivYossef-starkware AvivYossef-starkware changed the base branch from dori/move-filled-tree-creation-to-filled-tree-trait to aviv/refactor_leaf_data May 22, 2024 06:33
@AvivYossef-starkware AvivYossef-starkware force-pushed the aviv/impl_filledtree_serialize branch from 8e9a49e to 55c75a9 Compare May 22, 2024 06:48
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 6 of 6 files at r4, all commit messages.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @amosStarkware and @AvivYossef-starkware)


crates/committer/src/patricia_merkle_tree/filled_tree/tree.rs line 190 at r4 (raw file):

}

impl<L: LeafData + DBObject> FilledTree<L> for FilledTreeImpl<L> {

see comment in previous PR

Suggestion:

<L: LeafData>

crates/committer/src/patricia_merkle_tree/filled_tree/tree.rs line 220 at r4 (raw file):

            .iter()
            .map(|(_, node)| (node.get_db_key(&node.suffix()), node.serialize()))
            .collect::<HashMap<StorageKey, StorageValue>>()

are you sure you need the turbofish? compiler should know (return type)

Suggestion:

.collect()

@AvivYossef-starkware AvivYossef-starkware force-pushed the aviv/refactor_leaf_data branch 2 times, most recently from 2c6c42b to ddbdbce Compare May 22, 2024 12:49
@AvivYossef-starkware AvivYossef-starkware force-pushed the aviv/impl_filledtree_serialize branch from 55c75a9 to 2e06b90 Compare May 22, 2024 13:08
@AvivYossef-starkware AvivYossef-starkware changed the base branch from aviv/refactor_leaf_data to main May 22, 2024 13:08
Copy link
Collaborator Author

@AvivYossef-starkware AvivYossef-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: 2 of 6 files reviewed, 6 unresolved discussions (waiting on @amosStarkware and @dorimedini-starkware)


crates/committer/src/patricia_merkle_tree/filled_tree/tree.rs line 190 at r4 (raw file):

Previously, dorimedini-starkware wrote…

see comment in previous PR

Done.


crates/committer/src/patricia_merkle_tree/filled_tree/tree.rs line 220 at r4 (raw file):

Previously, dorimedini-starkware wrote…

are you sure you need the turbofish? compiler should know (return type)

Not needed.

Copy link
Contributor

@amosStarkware amosStarkware left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 6 files at r4, 4 of 4 files at r5, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @dorimedini-starkware)

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 all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @AvivYossef-starkware)

@AvivYossef-starkware AvivYossef-starkware added this pull request to the merge queue May 22, 2024
Merged via the queue into main with commit b5df579 May 22, 2024
19 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.

4 participants