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

refactor(sync): make changes to allow easily adding more types to sync #1803

Merged
merged 1 commit into from
Mar 12, 2024

Conversation

ShahakShama
Copy link
Contributor

@ShahakShama ShahakShama commented Mar 12, 2024

  • fix(sync): sleep when sync receives None and remove timeout hack
  • refactor(sync): make changes to allow easily adding more types to sync

This change is Reviewable

@ShahakShama ShahakShama changed the base branch from main to shahak/remove_p2p_sync_timout_hack March 12, 2024 08:48
@ShahakShama ShahakShama force-pushed the shahak/remove_p2p_sync_timout_hack branch from 436be8f to b1f7587 Compare March 12, 2024 08:52
Copy link

codecov bot commented Mar 12, 2024

Codecov Report

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

Project coverage is 72.14%. Comparing base (bade592) to head (8507d96).

Files Patch % Lines
crates/papyrus_p2p_sync/src/header.rs 71.42% 8 Missing and 6 partials ⚠️
crates/papyrus_p2p_sync/src/stream_factory.rs 74.46% 9 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1803      +/-   ##
==========================================
+ Coverage   72.12%   72.14%   +0.02%     
==========================================
  Files         139      141       +2     
  Lines       19925    20013      +88     
  Branches    19925    20013      +88     
==========================================
+ Hits        14370    14439      +69     
- Misses       3396     3406      +10     
- Partials     2159     2168       +9     

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

@ShahakShama ShahakShama force-pushed the shahak/refactor_p2p_sync_to_allow_more_data_types branch from 5901135 to a2c85e6 Compare March 12, 2024 08:56
@ShahakShama ShahakShama force-pushed the shahak/remove_p2p_sync_timout_hack branch from b1f7587 to f59b775 Compare March 12, 2024 09:20
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.

please move some code out of this file and into sub modules.
I'm letting it up to you to decide what and to where

Reviewed 2 of 3 files at r1, all commit messages.
Reviewable status: 2 of 3 files reviewed, 3 unresolved discussions (waiting on @ShahakShama)


crates/papyrus_p2p_sync/src/lib.rs line 118 at r1 (raw file):

        loop {
            let data = data_stream.next().await.expect("Sync data stream should never end")?;
            data.write_to_storage(&mut self.storage_writer)?;

why not use map?


crates/papyrus_p2p_sync/src/lib.rs line 127 at r1 (raw file):

}

struct HeaderData {

use signedheader struct


crates/papyrus_p2p_sync/src/lib.rs line 179 at r1 (raw file):

                    + u64::try_from(num_blocks_per_query)
                        .expect("Failed converting usize to u64");
                debug!("Downloading blocks [{}, {})", current_block_number.0, end_block_number);

add data type to this printout

@ShahakShama ShahakShama force-pushed the shahak/refactor_p2p_sync_to_allow_more_data_types branch 2 times, most recently from cf208d6 to d88b072 Compare March 12, 2024 10:04
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: 2 of 3 files reviewed, 3 unresolved discussions (waiting on @nagmo-starkware)


crates/papyrus_p2p_sync/src/lib.rs line 118 at r1 (raw file):

Previously, nagmo-starkware wrote…

why not use map?

The resulting code looks like:

        let mut writer_stream = data_stream.map(|data_result| {
            data_result?.write_to_storage(&mut self.storage_writer)?;
            Ok::<(), P2PSyncError>(())
        });
        loop {
            writer_stream.next().await.expect("Sync stream should never end")?;
        }

IMO the previous code was prettier. If you disagree I can do the code above


crates/papyrus_p2p_sync/src/lib.rs line 127 at r1 (raw file):

Previously, nagmo-starkware wrote…

use signedheader struct

Done.


crates/papyrus_p2p_sync/src/lib.rs line 179 at r1 (raw file):

Previously, nagmo-starkware wrote…

add data type to this printout

Done.

Base automatically changed from shahak/remove_p2p_sync_timout_hack to main March 12, 2024 11:26
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 all commit messages.
Reviewable status: 2 of 3 files reviewed, 2 unresolved discussions (waiting on @ShahakShama)


crates/papyrus_p2p_sync/src/lib.rs line 118 at r1 (raw file):

Previously, ShahakShama wrote…

The resulting code looks like:

        let mut writer_stream = data_stream.map(|data_result| {
            data_result?.write_to_storage(&mut self.storage_writer)?;
            Ok::<(), P2PSyncError>(())
        });
        loop {
            writer_stream.next().await.expect("Sync stream should never end")?;
        }

IMO the previous code was prettier. If you disagree I can do the code above

what about this?
I'm fine with whatever you decide

Code snippet:

loop {
    data_stream.map(|data_result| {
        data_result?.write_to_storage(&mut self.storage_writer)
    })
    .next()
    .await
    .expect("Sync stream should never end")?;
}

crates/papyrus_p2p_sync/src/lib.rs line 127 at r1 (raw file):

Previously, ShahakShama wrote…

Done.

I meant to remove the HeaderData struct completly

@ShahakShama ShahakShama force-pushed the shahak/refactor_p2p_sync_to_allow_more_data_types branch from d88b072 to c9d9fb2 Compare March 12, 2024 11:52
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: 2 of 3 files reviewed, 1 unresolved discussion (waiting on @nagmo-starkware)


crates/papyrus_p2p_sync/src/lib.rs line 127 at r1 (raw file):

Previously, nagmo-starkware wrote…

I meant to remove the HeaderData struct completly

Done.

@ShahakShama ShahakShama force-pushed the shahak/refactor_p2p_sync_to_allow_more_data_types branch from c9d9fb2 to c4b7873 Compare March 12, 2024 12:41
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.

Done

Reviewable status: 1 of 5 files reviewed, all discussions resolved (waiting on @nagmo-starkware)

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:

Reviewable status: 1 of 5 files reviewed, all discussions resolved

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 2 files at r3, 1 of 1 files at r5, all commit messages.
Reviewable status: 3 of 5 files reviewed, all discussions resolved

@ShahakShama ShahakShama added this pull request to the merge queue Mar 12, 2024
Merged via the queue into main with commit fefd1e4 Mar 12, 2024
15 of 16 checks passed
@ShahakShama ShahakShama deleted the shahak/refactor_p2p_sync_to_allow_more_data_types branch March 12, 2024 14:52
@github-actions github-actions bot locked and limited conversation to collaborators Mar 14, 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