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

chore(sync): receive statediffchunk from network #2118

Merged

Conversation

eitanm-starkware
Copy link
Contributor

@eitanm-starkware eitanm-starkware commented Jun 18, 2024

This change is Reviewable

@eitanm-starkware eitanm-starkware force-pushed the shahak/pass_to_eitan_state_diff_chunk_in_syncv branch from 0bab7bd to 560f761 Compare June 19, 2024 10:35
Copy link
Contributor

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

Reviewed 3 of 8 files at r1, all commit messages.
Reviewable status: 3 of 8 files reviewed, all discussions resolved

@eitanm-starkware eitanm-starkware force-pushed the shahak/pass_to_eitan_state_diff_chunk_in_syncv branch 2 times, most recently from c84d6aa to 1e1421f Compare June 19, 2024 10:57
Copy link

codecov bot commented Jun 19, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.

Project coverage is 66.00%. Comparing base (cd6f096) to head (94340b3).

Files Patch % Lines
crates/papyrus_p2p_sync/src/client/state_diff.rs 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2118      +/-   ##
==========================================
+ Coverage   65.86%   66.00%   +0.14%     
==========================================
  Files         136      136              
  Lines       18113    18102      -11     
  Branches    18113    18102      -11     
==========================================
+ Hits        11930    11949      +19     
+ Misses       4888     4858      -30     
  Partials     1295     1295              

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

Copy link
Contributor

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

Reviewed 4 of 8 files at r1, 1 of 2 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on @eitanm-starkware)


crates/papyrus_p2p_sync/src/state_diff.rs line 48 at r3 (raw file):

    #[latency_histogram("p2p_sync_state_diff_parse_data_for_block_latency_seconds", true)]
    fn parse_data_for_block<'a>(
        state_diff_chunks_receiver: &'a mut DataReceiver,

This rename is unnecessary. in the sync server we call it just state_diff
Whatever you prefer


crates/papyrus_p2p_sync/src/state_diff.rs line 124 at r3 (raw file):

                chunk_deployed_contract.insert(contract_diff.contract_address, class_hash);
            }
            unite_state_diffs_field(&mut state_diff.deployed_contracts, chunk_deployed_contract)?;

The function unite_state_diffs_field was only useful in the old code. Now it will be cleaner to remove this function and just call state_diff.deployed_contracts.insert(...) and return error if the return value is some
Alternatively, you can create a function like unite_state_diffs_field that receives only 1 entry from the chunk


crates/papyrus_p2p_sync/src/state_diff_test.rs line 61 at r3 (raw file):

        create_block_hashes_and_signatures(HEADER_QUERY_LENGTH.try_into().unwrap());
    let mut rng = get_rng();
    let state_diffs = (0..HEADER_QUERY_LENGTH)

This means just one state diff per header. Add a 3rd constant for NUM_CHUNKS_PER_BLOCK and have each element in the vector be a vector of chunks


crates/papyrus_p2p_sync/src/state_diff_test.rs line 132 at r3 (raw file):

                assert_eq!(block_number.unchecked_next(), txn.get_state_marker().unwrap());

                let expected_state_diff = txn.get_state_diff(block_number).unwrap().unwrap();

Swap the names. This is state_diff/actual_state_diff, and the one below is expected_state_diff


crates/papyrus_p2p_sync/src/state_diff_test.rs line 133 at r3 (raw file):

                let expected_state_diff = txn.get_state_diff(block_number).unwrap().unwrap();
                let state_diff = match state_diff_chunk {

Consider moving to hardcoded state diff chunks and expected state diff instead


crates/papyrus_p2p_sync/src/state_diff_test.rs line 180 at r3 (raw file):

}

async fn validate_state_diff_fails(

Move this and the function below it to either the bottom of the file or the top of the file


crates/papyrus_p2p_sync/src/state_diff_test.rs line 254 at r3 (raw file):

}

pub fn create_random_state_diff_chunk(rng: &mut ChaCha8Rng) -> StateDiffChunk {

remove pub


crates/papyrus_p2p_sync/src/state_diff_test.rs line 283 at r3 (raw file):

#[tokio::test]
async fn state_diff_not_splitted_correctly() {

Why did you erase this test? You can do it by having a ContractDiff of size 2

@eitanm-starkware eitanm-starkware force-pushed the shahak/pass_to_eitan_state_diff_chunk_in_syncv branch from 1e1421f to f88976e Compare July 1, 2024 10:31
Copy link
Contributor

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

Reviewed 9 of 10 files at r4, all commit messages.
Reviewable status: 11 of 12 files reviewed, 11 unresolved discussions (waiting on @eitanm-starkware)


crates/papyrus_p2p_sync/src/client/state_diff.rs line 121 at r4 (raw file):

            }
            unite_state_diffs_field(&mut state_diff.nonces, chunk_nonce)?;
            match state_diff.storage_diffs.get_mut(&contract_diff.contract_address) {

Do this only if !contract_diff.storage_diff.is_empty()


crates/papyrus_p2p_sync/src/client/state_diff_test.rs line 133 at r4 (raw file):

                assert_eq!(block_number.unchecked_next(), txn.get_state_marker().unwrap());

                let expected_state_diff = txn.get_state_diff(block_number).unwrap().unwrap();

Replace names. See comment below in the old file


crates/papyrus_p2p_sync/src/client/state_diff_test.rs line 134 at r4 (raw file):

                let expected_state_diff = txn.get_state_diff(block_number).unwrap().unwrap();
                let state_diff = match state_diff_chunk {

Add a comment that each chunk is a separate state diff, and add a TODO to test the positive flow of multiple chunks per block


crates/papyrus_p2p_sync/src/client/state_diff_test.rs line 285 at r4 (raw file):

#[tokio::test]
async fn state_diff_not_splitted_correctly() {

Why did you remove this test? You can change the 2nd chunk to be a contract diff with class_hash and nonce


crates/papyrus_p2p_sync/src/state_diff.rs line 124 at r3 (raw file):

Previously, ShahakShama wrote…

The function unite_state_diffs_field was only useful in the old code. Now it will be cleaner to remove this function and just call state_diff.deployed_contracts.insert(...) and return error if the return value is some
Alternatively, you can create a function like unite_state_diffs_field that receives only 1 entry from the chunk

This comment is still true


crates/papyrus_p2p_sync/src/state_diff_test.rs line 61 at r3 (raw file):

Previously, ShahakShama wrote…

This means just one state diff per header. Add a 3rd constant for NUM_CHUNKS_PER_BLOCK and have each element in the vector be a vector of chunks

This comment is still true. You can put a TODO for now like I wrote above


crates/papyrus_p2p_sync/src/state_diff_test.rs line 132 at r3 (raw file):

Previously, ShahakShama wrote…

Swap the names. This is state_diff/actual_state_diff, and the one below is expected_state_diff

This comment is still true. See where I commented above


crates/papyrus_p2p_sync/src/state_diff_test.rs line 133 at r3 (raw file):

Previously, ShahakShama wrote…

Consider moving to hardcoded state diff chunks and expected state diff instead

This comment is still true for adding more chunks per block. maybe you can do 2 tests, one where there are multiple blocks with one chunk per block, and one with multiple chunks for 1 block


crates/papyrus_p2p_sync/src/state_diff_test.rs line 180 at r3 (raw file):

Previously, ShahakShama wrote…

Move this and the function below it to either the bottom of the file or the top of the file

This comment is still true


crates/papyrus_p2p_sync/src/state_diff_test.rs line 254 at r3 (raw file):

Previously, ShahakShama wrote…

remove pub

This comment is still true


crates/papyrus_p2p_sync/src/state_diff_test.rs line 283 at r3 (raw file):

Previously, ShahakShama wrote…

Why did you erase this test? You can do it by having a ContractDiff of size 2

This comment is still true. See above

Copy link
Contributor Author

@eitanm-starkware eitanm-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: 11 of 12 files reviewed, 11 unresolved discussions (waiting on @ShahakShama)


crates/papyrus_p2p_sync/src/client/state_diff.rs line 121 at r4 (raw file):

Previously, ShahakShama wrote…

Do this only if !contract_diff.storage_diff.is_empty()

if it's empty then we add a new input..


crates/papyrus_p2p_sync/src/client/state_diff_test.rs line 133 at r4 (raw file):

Previously, ShahakShama wrote…

Replace names. See comment below in the old file

Done.


crates/papyrus_p2p_sync/src/client/state_diff_test.rs line 134 at r4 (raw file):

Previously, ShahakShama wrote…

Add a comment that each chunk is a separate state diff, and add a TODO to test the positive flow of multiple chunks per block

added comment above for constant


crates/papyrus_p2p_sync/src/client/state_diff_test.rs line 285 at r4 (raw file):

Previously, ShahakShama wrote…

Why did you remove this test? You can change the 2nd chunk to be a contract diff with class_hash and nonce

Done.


crates/papyrus_p2p_sync/src/state_diff.rs line 48 at r3 (raw file):

Previously, ShahakShama wrote…

This rename is unnecessary. in the sync server we call it just state_diff
Whatever you prefer

we are receiving chunks and forwarding thinstatediff. i think it makes it clear.


crates/papyrus_p2p_sync/src/state_diff.rs line 124 at r3 (raw file):

Previously, ShahakShama wrote…

This comment is still true

Done.


crates/papyrus_p2p_sync/src/state_diff_test.rs line 61 at r3 (raw file):

Previously, ShahakShama wrote…

This comment is still true. You can put a TODO for now like I wrote above

Done.


crates/papyrus_p2p_sync/src/state_diff_test.rs line 132 at r3 (raw file):

Previously, ShahakShama wrote…

This comment is still true. See where I commented above

Done.


crates/papyrus_p2p_sync/src/state_diff_test.rs line 133 at r3 (raw file):

Previously, ShahakShama wrote…

This comment is still true for adding more chunks per block. maybe you can do 2 tests, one where there are multiple blocks with one chunk per block, and one with multiple chunks for 1 block

this is part of the TODO i wrote above.


crates/papyrus_p2p_sync/src/state_diff_test.rs line 180 at r3 (raw file):

Previously, ShahakShama wrote…

This comment is still true

Done.


crates/papyrus_p2p_sync/src/state_diff_test.rs line 254 at r3 (raw file):

Previously, ShahakShama wrote…

This comment is still true

Done.


crates/papyrus_p2p_sync/src/state_diff_test.rs line 283 at r3 (raw file):

Previously, ShahakShama wrote…

This comment is still true. See above

Done.

@eitanm-starkware eitanm-starkware force-pushed the shahak/pass_to_eitan_state_diff_chunk_in_syncv branch 3 times, most recently from 6dcac95 to f06a5a5 Compare July 1, 2024 13:39
ShahakShama
ShahakShama previously approved these changes Jul 1, 2024
Copy link
Contributor

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

:lgtm:

Reviewed 1 of 1 files at r6, 1 of 1 files at r7, all commit messages.
Reviewable status: 11 of 12 files reviewed, all discussions resolved (waiting on @eitanm-starkware)

Copy link
Contributor

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

Reviewed 3 of 3 files at r8, all commit messages.
Reviewable status: 11 of 12 files reviewed, all discussions resolved (waiting on @eitanm-starkware)

Copy link
Contributor

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

Reviewed 1 of 10 files at r4.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @eitanm-starkware)

@eitanm-starkware eitanm-starkware added this pull request to the merge queue Jul 1, 2024
Merged via the queue into main with commit 2291692 Jul 1, 2024
34 checks passed
@eitanm-starkware eitanm-starkware deleted the shahak/pass_to_eitan_state_diff_chunk_in_syncv branch July 1, 2024 14:22
@github-actions github-actions bot locked and limited conversation to collaborators Jul 3, 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