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(sync): add state diff sync to p2p sync #1812

Merged
merged 1 commit into from
Mar 25, 2024

Conversation

ShahakShama
Copy link
Contributor

@ShahakShama ShahakShama commented Mar 14, 2024

This change is Reviewable

Copy link
Contributor Author

@ShahakShama ShahakShama 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 8 files reviewed, 1 unresolved discussion (waiting on @nagmo-starkware and @ShahakShama)


Cargo.toml line 128 at r1 (raw file):

[patch.crates-io]
starknet_api = { git = "https://github.com/starkware-libs/starknet-api", branch = "shahak/ThinStateDiff_is_empty" }

Note to self: fix this once https://reviewable.io/reviews/starkware-libs/starknet-api/192 is merged

@ShahakShama ShahakShama force-pushed the shahak/state_diff_p2p_sync branch 2 times, most recently from c50257b to 2bf0963 Compare March 14, 2024 13:37
Copy link

codecov bot commented Mar 14, 2024

Codecov Report

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

Project coverage is 72.02%. Comparing base (ad8e8f6) to head (e78b88b).

Files Patch % Lines
crates/papyrus_p2p_sync/src/state_diff.rs 76.37% 17 Missing and 13 partials ⚠️
crates/papyrus_p2p_sync/src/stream_factory.rs 55.55% 8 Missing and 4 partials ⚠️
crates/papyrus_p2p_sync/src/header.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1812      +/-   ##
==========================================
+ Coverage   71.99%   72.02%   +0.02%     
==========================================
  Files         142      143       +1     
  Lines       20369    20522     +153     
  Branches    20369    20522     +153     
==========================================
+ Hits        14664    14780     +116     
- Misses       3531     3552      +21     
- Partials     2174     2190      +16     

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

Copy link
Contributor

@nagmo-starkware nagmo-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 8 files at r1, 5 of 7 files at r2, all commit messages.
Reviewable status: 8 of 10 files reviewed, 7 unresolved discussions (waiting on @ShahakShama)


crates/papyrus_p2p_sync/src/header.rs line 43 at r2 (raw file):

    const DATA_TYPE: DataType = DataType::SignedBlockHeader;
    const BLOCK_NUMBER_LIMIT: BlockNumberLimit = BlockNumberLimit::Unlimited;
    const SHOULD_LOG_ADDED_BLOCK: bool = false;

I think it should be set to true


crates/papyrus_p2p_sync/src/lib.rs line 69 at r2 (raw file):

            num_headers_per_query: 10000,
            // State diffs are split into multiple messages, so big queries can lead to a lot of
            // messages in the network buffers.

did you test it to be the case? or is it your estimation?
the network buffer is configurable so normally the application side is doing what makes most sense applicatively and if needed changes the default network buffer size. (usually it's not needed since it is dynamically sized)


crates/papyrus_p2p_sync/src/lib.rs line 102 at r2 (raw file):

        "Received an empty state diff part from the network (this is a potential DDoS vector)."
    )]
    EmptyStateDiffPart,

maybe we should just fail to convert it in the converter?


crates/papyrus_p2p_sync/src/lib.rs line 110 at r2 (raw file):

         {missing_field}"
    )]
    OldHeaderInStorage { block_number: BlockNumber, missing_field: &'static str },

that means we need to re-sync from genesis? please add it to the error message to make it more helpful


crates/papyrus_p2p_sync/src/state_diff.rs line 25 at r2 (raw file):

    ) -> Result<(), StorageError> {
        // TODO(shahak): Add a way to write ThinStateDiff to the storage.
        let state_diff = StateDiff {

why not use a conversion function? (From/ TryFrom)


crates/papyrus_p2p_sync/src/state_diff.rs line 74 at r2 (raw file):

            let mut prev_result_len = 0;
            let mut result_len = 0;
            let target_len = storage_reader

Suggestion:

num_expected_state_diffs

crates/papyrus_p2p_sync/src/state_diff.rs line 96 at r2 (raw file):

                        return Ok(None);
                    } else {
                        return Err(P2PSyncError::WrongStateDiffLength {

I don't understand this error. what's possible length?

Copy link
Contributor Author

@ShahakShama ShahakShama 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: 8 of 10 files reviewed, 7 unresolved discussions (waiting on @nagmo-starkware and @ShahakShama)


crates/papyrus_p2p_sync/src/header.rs line 43 at r2 (raw file):

Previously, nagmo-starkware wrote…

I think it should be set to true

I've set it to true everywhere and removed this variable


crates/papyrus_p2p_sync/src/lib.rs line 69 at r2 (raw file):

Previously, nagmo-starkware wrote…

did you test it to be the case? or is it your estimation?
the network buffer is configurable so normally the application side is doing what makes most sense applicatively and if needed changes the default network buffer size. (usually it's not needed since it is dynamically sized)

Yes, I initially set it to 1000 and the node failed so I tuned it down to 100. I can instead increase the header buffer limit from 100,000 to 1,000,000 if you prefer


crates/papyrus_p2p_sync/src/lib.rs line 102 at r2 (raw file):

Previously, nagmo-starkware wrote…

maybe we should just fail to convert it in the converter?

I'm not sure which is better so I've added a TODO to consider


crates/papyrus_p2p_sync/src/lib.rs line 110 at r2 (raw file):

Previously, nagmo-starkware wrote…

that means we need to re-sync from genesis? please add it to the error message to make it more helpful

It means we need to re-sync from the given block number. Added to the error message


crates/papyrus_p2p_sync/src/state_diff.rs line 25 at r2 (raw file):

Previously, nagmo-starkware wrote…

why not use a conversion function? (From/ TryFrom)

It's a hack. I don't want other people to accidentally use it. In general you can't convert ThinStateDiff to StateDiff


crates/papyrus_p2p_sync/src/state_diff.rs line 74 at r2 (raw file):

            let mut prev_result_len = 0;
            let mut result_len = 0;
            let target_len = storage_reader

Done


crates/papyrus_p2p_sync/src/state_diff.rs line 96 at r2 (raw file):

Previously, nagmo-starkware wrote…

I don't understand this error. what's possible length?

The length that the block's state diff could be

Copy link
Contributor Author

@ShahakShama ShahakShama 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: 8 of 10 files reviewed, 7 unresolved discussions (waiting on @nagmo-starkware)


crates/papyrus_p2p_sync/src/lib.rs line 110 at r2 (raw file):

Previously, ShahakShama wrote…

It means we need to re-sync from the given block number. Added to the error message

Done.

@ShahakShama ShahakShama force-pushed the shahak/state_diff_p2p_sync branch 2 times, most recently from 36e76ef to 4d6acb2 Compare March 20, 2024 12:48
Copy link
Contributor

@nagmo-starkware nagmo-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: 3 of 10 files reviewed, 1 unresolved discussion (waiting on @ShahakShama)


crates/papyrus_p2p_sync/src/lib.rs line 69 at r2 (raw file):

Previously, ShahakShama wrote…

Yes, I initially set it to 1000 and the node failed so I tuned it down to 100. I can instead increase the header buffer limit from 100,000 to 1,000,000 if you prefer

no I think we should change the socket buffer. resolving for now


crates/papyrus_p2p_sync/src/state_diff.rs line 96 at r2 (raw file):

Previously, ShahakShama wrote…

The length that the block's state diff could be

f2f

Copy link
Contributor Author

@ShahakShama ShahakShama 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: 3 of 10 files reviewed, 1 unresolved discussion (waiting on @nagmo-starkware)


crates/papyrus_p2p_sync/src/state_diff.rs line 96 at r2 (raw file):

Previously, nagmo-starkware wrote…

f2f

I still think it's useful information. Improved the message

Copy link
Contributor

@nagmo-starkware nagmo-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 7 files at r2, 3 of 6 files at r3, 3 of 3 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ShahakShama)

@ShahakShama ShahakShama added this pull request to the merge queue Mar 25, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 25, 2024
@ShahakShama ShahakShama added this pull request to the merge queue Mar 25, 2024
Merged via the queue into main with commit d487422 Mar 25, 2024
18 of 19 checks passed
@ShahakShama ShahakShama deleted the shahak/state_diff_p2p_sync branch March 25, 2024 09:15
@github-actions github-actions bot locked and limited conversation to collaborators Mar 28, 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