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(starknet_batcher): implement sync_block #2604

Merged
merged 1 commit into from
Dec 16, 2024

Conversation

ArniStarkware
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link

codecov bot commented Dec 9, 2024

Codecov Report

Attention: Patch coverage is 41.17647% with 10 lines in your changes missing coverage. Please review.

Please upload report for BASE (arni/sync_block/batcher_side_communications@390db80). Learn more about missing BASE report.

Files with missing lines Patch % Lines
crates/starknet_batcher/src/batcher.rs 41.17% 10 Missing ⚠️
Additional details and impacted files
@@                              Coverage Diff                              @@
##             arni/sync_block/batcher_side_communications   #2604   +/-   ##
=============================================================================
  Coverage                                               ?   6.39%           
=============================================================================
  Files                                                  ?     141           
  Lines                                                  ?   17233           
  Branches                                               ?   17233           
=============================================================================
  Hits                                                   ?    1102           
  Misses                                                 ?   16055           
  Partials                                               ?      76           

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

@ArniStarkware ArniStarkware force-pushed the arni/sync_block/batcher_side_communications branch from d30c9d7 to 390db80 Compare December 10, 2024 11:33
@ArniStarkware ArniStarkware force-pushed the arni/sync_block/batcher_impl branch from abf48d5 to 2b5c9c3 Compare December 10, 2024 11:33
Copy link
Collaborator

@alonh5 alonh5 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 1 files at r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @ArniStarkware)


crates/starknet_batcher/src/batcher.rs line 353 at r1 (raw file):

    }

    pub async fn add_sync_block(&mut self, sync_block: SyncBlock) -> BatcherResult<()> {

We should also abort the active height if there is one, right?


crates/starknet_batcher/src/batcher.rs line 353 at r1 (raw file):

    }

    pub async fn add_sync_block(&mut self, sync_block: SyncBlock) -> BatcherResult<()> {

Test?


crates/starknet_batcher/src/batcher.rs line 377 at r1 (raw file):

            proposal_output;
        // TODO(Arni): Move the height and the `info` level log into the function
        // `commit_proposal_and_block`.

Why not do it here?

Code quote:

        // TODO(Arni): Move the height and the `info` level log into the function
        // `commit_proposal_and_block`.

@ArniStarkware ArniStarkware force-pushed the arni/sync_block/batcher_side_communications branch 3 times, most recently from c120aea to 1f28c79 Compare December 15, 2024 09:01
@ArniStarkware ArniStarkware force-pushed the arni/sync_block/batcher_impl branch from 2b5c9c3 to bc538a5 Compare December 15, 2024 09:01
@ArniStarkware
Copy link
Contributor Author

crates/starknet_batcher/src/batcher.rs line 357 at r2 (raw file):

        let address_to_nonce = state_diff.nonces.iter().map(|(k, v)| (*k, *v)).collect();
        let tx_hashes = transaction_hashes.into_iter().collect();
        // TODO: Keep the height from start_height or get it from the input.

Is this the correct height to be synced to?
Isn't it supposed to be some other height?
The height is read from storage. Is it the intention that the given state_diff be committed to the same height?

Code quote:

        // TODO: Keep the height from start_height or get it from the input.

@ArniStarkware ArniStarkware force-pushed the arni/sync_block/batcher_side_communications branch from 1f28c79 to 631a378 Compare December 15, 2024 12:52
@ArniStarkware ArniStarkware force-pushed the arni/sync_block/batcher_impl branch from bc538a5 to aac90c3 Compare December 15, 2024 12:53
@ArniStarkware ArniStarkware changed the base branch from arni/sync_block/batcher_side_communications to arni/sync_block/clear_previous_proposals December 15, 2024 12:53
@ArniStarkware ArniStarkware force-pushed the arni/sync_block/clear_previous_proposals branch from 490a9be to e6a1c63 Compare December 15, 2024 15:15
@ArniStarkware ArniStarkware force-pushed the arni/sync_block/batcher_impl branch from aac90c3 to ef3461a Compare December 15, 2024 15:15
@ArniStarkware ArniStarkware requested a review from alonh5 December 16, 2024 08:33
Copy link
Contributor Author

@ArniStarkware ArniStarkware 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 2 files reviewed, 3 unresolved discussions (waiting on @alonh5)


crates/starknet_batcher/src/batcher.rs line 353 at r1 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

We should also abort the active height if there is one, right?

Done.


crates/starknet_batcher/src/batcher.rs line 353 at r1 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

Test?

Done.


crates/starknet_batcher/src/batcher.rs line 377 at r1 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

Why not do it here?

Because it is incorrect!
We talked on DMs. The height for decision_reached should be the current height.
The height for add_sync_block should be current height + 1.

@ArniStarkware ArniStarkware force-pushed the arni/sync_block/clear_previous_proposals branch from e6a1c63 to 7df7381 Compare December 16, 2024 08:39
@ArniStarkware ArniStarkware force-pushed the arni/sync_block/batcher_impl branch from ef3461a to e200f3e Compare December 16, 2024 08:39
@ArniStarkware ArniStarkware force-pushed the arni/sync_block/clear_previous_proposals branch 2 times, most recently from 8f88d9a to d1790d9 Compare December 16, 2024 11:27
@ArniStarkware ArniStarkware force-pushed the arni/sync_block/batcher_impl branch 2 times, most recently from bec2219 to ede2ad9 Compare December 16, 2024 12:05
@ArniStarkware ArniStarkware force-pushed the arni/sync_block/clear_previous_proposals branch from d1790d9 to 1f2e9c0 Compare December 16, 2024 12:08
@ArniStarkware ArniStarkware force-pushed the arni/sync_block/batcher_impl branch from ede2ad9 to f9e62f0 Compare December 16, 2024 12:08
Copy link
Contributor Author

@ArniStarkware ArniStarkware 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 2 files reviewed, 3 unresolved discussions (waiting on @alonh5)


crates/starknet_batcher/src/batcher.rs line 377 at r1 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

Because it is incorrect!
We talked on DMs. The height for decision_reached should be the current height.
The height for add_sync_block should be current height + 1.

  1. Reverted the changes to the height marker.
  2. Followed through with the original TODO.

Copy link
Collaborator

@alonh5 alonh5 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 2 files at r4, 1 of 1 files at r5, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @ArniStarkware)


crates/starknet_batcher/src/batcher.rs line 369 at r5 (raw file):

        let info_callback = |height: BlockNumber| {
            info!("Syncing block at height {} and notifying mempool of the block.", height);
        };

This callback is cool, but can't we just have the same message for both?
Also add #[instrument(skip(self), err)] at the top and that way we'll be able to distinct the two.

Code quote:

        let info_callback = |height: BlockNumber| {
            info!("Syncing block at height {} and notifying mempool of the block.", height);
        };

crates/starknet_batcher/src/batcher_test.rs line 499 at r5 (raw file):

            tx_hashes: test_tx_hashes(),
        }))
        .returning(|_| Ok(()));

add times(1) so we know they're called.

Code quote:

    mock_dependencies
        .storage_writer
        .expect_commit_proposal()
        .with(eq(INITIAL_HEIGHT), eq(test_state_diff()))
        .returning(|_, _| Ok(()));

    mock_dependencies
        .mempool_client
        .expect_commit_block()
        .with(eq(CommitBlockArgs {
            address_to_nonce: test_contract_nonces(),
            tx_hashes: test_tx_hashes(),
        }))
        .returning(|_| Ok(()));

crates/starknet_batcher/src/batcher_test.rs line 510 at r5 (raw file):

    let get_height_response = batcher.get_height().await.unwrap();
    assert_eq!(get_height_response.height, INITIAL_HEIGHT);

This should be the next height after syncing one block, no?
But the storage reader is mocked anyway, so there's no need for this check.

Suggestion:

INITIAL_HEIGHT.next()

@ArniStarkware ArniStarkware force-pushed the arni/sync_block/batcher_impl branch from f9e62f0 to bc3e41b Compare December 16, 2024 12:56
@ArniStarkware ArniStarkware changed the base branch from arni/sync_block/clear_previous_proposals to graphite-base/2604 December 16, 2024 12:56
@ArniStarkware ArniStarkware force-pushed the arni/sync_block/batcher_impl branch from bc3e41b to 358cf0e Compare December 16, 2024 12:56
@ArniStarkware ArniStarkware changed the base branch from graphite-base/2604 to main December 16, 2024 12:57
@ArniStarkware ArniStarkware force-pushed the arni/sync_block/batcher_impl branch from 358cf0e to dc171ca Compare December 16, 2024 12:57
@ArniStarkware ArniStarkware requested a review from alonh5 December 16, 2024 13:00
Copy link
Contributor Author

@ArniStarkware ArniStarkware 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 2 files reviewed, 3 unresolved discussions (waiting on @alonh5)


crates/starknet_batcher/src/batcher.rs line 369 at r5 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

This callback is cool, but can't we just have the same message for both?
Also add #[instrument(skip(self), err)] at the top and that way we'll be able to distinct the two.

Done. The log changed slightly. For decision_reached, the info will no longer contain the proposal_id - we count on the fact that the proposal_id appears on the call to decision_reached.


crates/starknet_batcher/src/batcher_test.rs line 499 at r5 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

add times(1) so we know they're called.

Done.


crates/starknet_batcher/src/batcher_test.rs line 510 at r5 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

This should be the next height after syncing one block, no?
But the storage reader is mocked anyway, so there's no need for this check.

Removed.

Copy link
Collaborator

@alonh5 alonh5 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 2 of 2 files at r6, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ArniStarkware)

@ArniStarkware
Copy link
Contributor Author

crates/starknet_batcher/src/batcher.rs line 369 at r5 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

Done. The log changed slightly. For decision_reached, the info will no longer contain the proposal_id - we count on the fact that the proposal_id appears on the call to decision_reached.

2024-12-16T13:04:58.220108Z  INFO decision_reached: starknet_batcher::batcher: Committing block at height 3 and notifying mempool of the block. input=DecisionReachedInput { proposal_id: ProposalId(0) }

@ArniStarkware ArniStarkware merged commit 488fcfa into main Dec 16, 2024
8 checks passed
@ArniStarkware ArniStarkware deleted the arni/sync_block/batcher_impl branch December 16, 2024 13:07
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.

3 participants