Skip to content
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

feat(committer): use FilledTree::create() in filled forest #495

Merged
merged 1 commit into from
Aug 20, 2024

Conversation

amosStarkware
Copy link
Collaborator

@amosStarkware amosStarkware commented Aug 18, 2024

This change is Reviewable

Copy link
Collaborator Author

@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.

+reviewer:@dorimedini-starkware
second half of this PR:
https://reviewable.io/reviews/starkware-libs/sequencer/471

Reviewable status: 0 of 4 files reviewed, all discussions resolved (waiting on @dorimedini-starkware)

Copy link

codecov bot commented Aug 18, 2024

Codecov Report

Attention: Patch coverage is 10.34483% with 78 lines in your changes missing coverage. Please review.

Project coverage is 76.41%. Comparing base (091490f) to head (eb44e1b).
Report is 1 commits behind head on main-v0.13.2.

Files Patch % Lines
...tes/starknet_committer/src/forest/filled_forest.rs 0.00% 74 Missing ⚠️
...es/starknet_committer/src/block_committer/input.rs 66.66% 4 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff                @@
##           main-v0.13.2     #495      +/-   ##
================================================
- Coverage         76.45%   76.41%   -0.05%     
================================================
  Files               314      314              
  Lines             34205    34240      +35     
  Branches          34205    34240      +35     
================================================
+ Hits              26152    26164      +12     
- Misses             5775     5798      +23     
  Partials           2278     2278              

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

@amosStarkware amosStarkware force-pushed the amos/recursive_contracts_trie_4_1 branch from 7f23470 to baddeec Compare August 19, 2024 10:59
@amosStarkware amosStarkware force-pushed the amos/recursive_contracts_trie_4_2 branch from 7bcd113 to 91dae73 Compare August 19, 2024 11:01
@amosStarkware amosStarkware force-pushed the amos/recursive_contracts_trie_4_1 branch from baddeec to a379408 Compare August 19, 2024 12:09
@amosStarkware amosStarkware force-pushed the amos/recursive_contracts_trie_4_2 branch from 91dae73 to dc3e396 Compare August 19, 2024 12:10
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, 6 unresolved discussions (waiting on @amosStarkware)


crates/starknet_committer/src/block_committer/input.rs line 19 at r1 (raw file):

impl From<&NodeIndex> for ContractAddress {
    fn from(node_index: &NodeIndex) -> ContractAddress {
        assert!(node_index.is_leaf(), "NodeIndex {:?} is not a leaf.", node_index);

if you need to assert, maybe you should consider implementing TryFrom instead of From...?

Code quote:

impl From<&NodeIndex> for ContractAddress {
    fn from(node_index: &NodeIndex) -> ContractAddress {
        assert!(node_index.is_leaf(), "NodeIndex {:?} is not a leaf.", node_index);

crates/starknet_committer/src/block_committer/input.rs line 23 at r1 (raw file):

            Felt::try_from(*node_index - NodeIndex::FIRST_LEAF)
                .expect("Unable to convert node index to felt."),
        )

there is a computation here... please add a unit test for some valid values and edge cases.
if you convert this to a TryFrom implementation, also test some invalid cases please

Code quote:

        ContractAddress(
            Felt::try_from(*node_index - NodeIndex::FIRST_LEAF)
                .expect("Unable to convert node index to felt."),
        )

crates/starknet_committer/src/forest/filled_forest.rs line 81 at r1 (raw file):

        let (contracts_trie, storage_tries) =
            contracts_trie_task.await?.map_err(ForestError::ContractsTrie)?;
        let classes_trie = classes_trie_task.await?.map_err(ForestError::ClassesTrie)?;

there are already running (in parallel) and it doesn't matter that you await each one separately, right?

Code quote:

        let (contracts_trie, storage_tries) =
            contracts_trie_task.await?.map_err(ForestError::ContractsTrie)?;
        let classes_trie = classes_trie_task.await?.map_err(ForestError::ClassesTrie)?;

crates/starknet_committer/src/forest/filled_forest.rs line 81 at r1 (raw file):

        let (contracts_trie, storage_tries) =
            contracts_trie_task.await?.map_err(ForestError::ContractsTrie)?;
        let classes_trie = classes_trie_task.await?.map_err(ForestError::ClassesTrie)?;

consider:

  1. swapping the order of awaits
  2. adding logs

the classes trie will probably finish before the contracts trie (height 251 vs 502), so better to await it first

Suggestion:

        let classes_trie = classes_trie_task.await?.map_err(ForestError::ClassesTrie)?;
        log::???!("Classes trie update complete; {x} new facts computed.");
        let (contracts_trie, storage_tries) =
            contracts_trie_task.await?.map_err(ForestError::ContractsTrie)?;
        log::???!("Contracts trie update complete; {x} new facts computed.");

crates/starknet_committer/src/forest/filled_forest.rs line 109 at r1 (raw file):

            contract_address_to_storage_updates.len(),
            contract_address_to_storage_skeleton.len()
        );

please add an informative message if this assert fails

Code quote:

        assert_eq!(
            contract_address_to_storage_updates.len(),
            contract_address_to_storage_skeleton.len()
        );

crates/starknet_committer/src/forest/filled_forest.rs line 131 at r1 (raw file):

                        .ok_or(ForestError::MissingUpdatedSkeleton(contract_address))?,
                    storage_updates,
                ),

this 4-tuple is IMO not a very nice way to describe a type...
can you open another PR on top of the current tip of your stack, to convert this 4-tuple to a struct with named fields?

Code quote:

                (
                    node_index,
                    *(address_to_nonce
                        .get(&contract_address)
                        .unwrap_or(&original_contract_state.nonce)),
                    *(address_to_class_hash
                        .get(&contract_address)
                        .unwrap_or(&original_contract_state.class_hash)),
                    contract_address_to_storage_skeleton
                        .remove(&contract_address)
                        .ok_or(ForestError::MissingUpdatedSkeleton(contract_address))?,
                    storage_updates,
                ),

@amosStarkware amosStarkware force-pushed the amos/recursive_contracts_trie_4_1 branch 3 times, most recently from 6afd858 to fcd3122 Compare August 20, 2024 08:38
@amosStarkware amosStarkware force-pushed the amos/recursive_contracts_trie_4_2 branch 2 times, most recently from f301bdb to dd3be0c Compare August 20, 2024 09:46
Copy link
Collaborator Author

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


crates/starknet_committer/src/block_committer/input.rs line 19 at r1 (raw file):

Previously, dorimedini-starkware wrote…

if you need to assert, maybe you should consider implementing TryFrom instead of From...?

Good point


crates/starknet_committer/src/block_committer/input.rs line 23 at r1 (raw file):

Previously, dorimedini-starkware wrote…

there is a computation here... please add a unit test for some valid values and edge cases.
if you convert this to a TryFrom implementation, also test some invalid cases please

Done.


crates/starknet_committer/src/forest/filled_forest.rs line 81 at r1 (raw file):

Previously, dorimedini-starkware wrote…

there are already running (in parallel) and it doesn't matter that you await each one separately, right?

right


crates/starknet_committer/src/forest/filled_forest.rs line 81 at r1 (raw file):

Previously, dorimedini-starkware wrote…

consider:

  1. swapping the order of awaits
  2. adding logs

the classes trie will probably finish before the contracts trie (height 251 vs 502), so better to await it first

Done.


crates/starknet_committer/src/forest/filled_forest.rs line 109 at r1 (raw file):

Previously, dorimedini-starkware wrote…

please add an informative message if this assert fails

Done.


crates/starknet_committer/src/forest/filled_forest.rs line 131 at r1 (raw file):

Previously, dorimedini-starkware wrote…

this 4-tuple is IMO not a very nice way to describe a type...
can you open another PR on top of the current tip of your stack, to convert this 4-tuple to a struct with named fields?

Will do and paste link here

@amosStarkware amosStarkware force-pushed the amos/recursive_contracts_trie_4_2 branch from dd3be0c to 5335149 Compare August 20, 2024 09:49
@amosStarkware amosStarkware changed the base branch from amos/recursive_contracts_trie_4_1 to main-v0.13.2 August 20, 2024 09:50
Copy link
Collaborator Author

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


crates/starknet_committer/src/forest/filled_forest.rs line 131 at r1 (raw file):

Previously, amosStarkware wrote…

Will do and paste link here

Done.
https://reviewable.io/reviews/starkware-libs/sequencer/530

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 @amosStarkware)


crates/starknet_committer/src/forest/filled_forest.rs line 101 at r3 (raw file):

                                "Got the following error when trying to convert node index {0:?} \
                                 to a contract address: {1:?}",
                                node_index, error

Suggestion:

                                "Got the following error when trying to convert node index {node_index:?} \
                                 to a contract address: {error:?}",

@amosStarkware amosStarkware force-pushed the amos/recursive_contracts_trie_4_2 branch from 5335149 to eb44e1b Compare August 20, 2024 12:15
Copy link
Collaborator Author

@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: 4 of 5 files reviewed, 1 unresolved discussion (waiting on @dorimedini-starkware)


crates/starknet_committer/src/forest/filled_forest.rs line 101 at r3 (raw file):

                                "Got the following error when trying to convert node index {0:?} \
                                 to a contract address: {1:?}",
                                node_index, error

Done.

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

@amosStarkware amosStarkware merged commit 7f4e7b3 into main-v0.13.2 Aug 20, 2024
16 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants