Skip to content

fix(starknet_l1_provider): catch_up_height from sync client #4967

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

Conversation

giladchase
Copy link
Contributor

Most of this is boilerplate, major changes are:

  1. catch up height is now lazily initialized by the spawned sync task
    which continously asks the sync state for its height. This can be
    None if the sync is starting up.
  2. Until catch up height is ready, the rest of the startup flow is
    unchanged, with the addition that before the spawned task starts
    generating commit-blocks to sync up the provider, it'll first update
    the catch up height, which is synced with the bootstrapper.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Contributor Author

giladchase commented Mar 17, 2025

@giladchase giladchase marked this pull request as ready for review March 17, 2025 12:15
@giladchase giladchase force-pushed the gilad/03-16-fix_starknet_l1_provider_catch_up_height_from_sync_client branch from 0d11773 to 991c119 Compare March 17, 2025 12:23
@giladchase giladchase force-pushed the gilad/03-13-fix_starknet_l1_provider_init_from_logstateupdate_height branch from 6b5820d to 540b9f7 Compare March 17, 2025 12:42
@giladchase giladchase force-pushed the gilad/03-16-fix_starknet_l1_provider_catch_up_height_from_sync_client branch 2 times, most recently from b4ccc91 to bb1549e Compare March 17, 2025 13:24
@giladchase giladchase force-pushed the gilad/03-13-fix_starknet_l1_provider_init_from_logstateupdate_height branch from 540b9f7 to f141c5f Compare March 17, 2025 13:24
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 8 of 10 files at r1, 1 of 1 files at r2.
Reviewable status: 7 of 10 files reviewed, 4 unresolved discussions (waiting on @ArniStarkware)


crates/starknet_l1_provider/src/bootstrapper.rs line 50 at r2 (raw file):

    pub fn is_caught_up(&self, current_provider_height: BlockNumber) -> bool {
        self.catch_up_height()
            .is_some_and(|catch_up_height| catch_up_height <= current_provider_height)

This is the logical direction, makes it easier to read.
Also what is the current provider height defined as? is t the last retrieved block or the first unretrieved block?
Please document this and adjust here accordingly

Suggestion:

current_provider_height >= catch_up_height 

crates/starknet_l1_provider/src/bootstrapper.rs line 137 at r2 (raw file):

    let catch_up_height = *catch_up_height.get().expect("Initialized above");

    while current_height <= catch_up_height {

can you use is_caught_up()?

Code quote:

current_height <= catch_up_height

crates/starknet_l1_provider/src/l1_provider.rs line 215 at r2 (raw file):

    sync_client: SharedStateSyncClient,
    scraper_synced_startup_height: BlockNumber,
) -> L1ProviderResult<L1Provider> {

What can fail here?


crates/starknet_l1_provider/src/l1_provider.rs line 236 at r2 (raw file):

        .map(|catch_up_height_override| {
            warn!(
                "Initializing L1Provider with OVERRIDDEN catch-up height: \

Will this warn happen only upon override?

@giladchase giladchase force-pushed the gilad/03-16-fix_starknet_l1_provider_catch_up_height_from_sync_client branch from bb1549e to 9d94e7d Compare March 17, 2025 15:24
@giladchase giladchase force-pushed the gilad/03-13-fix_starknet_l1_provider_init_from_logstateupdate_height branch from f141c5f to f9117f8 Compare March 17, 2025 15:24
@giladchase giladchase force-pushed the gilad/03-16-fix_starknet_l1_provider_catch_up_height_from_sync_client branch 2 times, most recently from 3b0b768 to ed127f0 Compare March 18, 2025 07:16
@giladchase giladchase force-pushed the gilad/03-13-fix_starknet_l1_provider_init_from_logstateupdate_height branch 2 times, most recently from 91ba267 to ecf8f41 Compare March 18, 2025 11:28
@giladchase giladchase force-pushed the gilad/03-16-fix_starknet_l1_provider_catch_up_height_from_sync_client branch from ed127f0 to 267363e Compare March 18, 2025 11:28
@giladchase giladchase force-pushed the gilad/03-13-fix_starknet_l1_provider_init_from_logstateupdate_height branch from ecf8f41 to 60c6d6f Compare March 18, 2025 12:07
@giladchase giladchase force-pushed the gilad/03-16-fix_starknet_l1_provider_catch_up_height_from_sync_client branch from 267363e to a1f2ec3 Compare March 18, 2025 12:07
@ArniStarkware
Copy link
Contributor

crates/starknet_sequencer_node/src/components.rs line 264 at r4 (raw file):

                    provider_startup_height,
                )
                .unwrap(),

Why should this fail?
Can this be an expect? Every other fail in this function is very well documented.

Code quote:

unwrap()

@giladchase giladchase force-pushed the gilad/03-16-fix_starknet_l1_provider_catch_up_height_from_sync_client branch from a1f2ec3 to 4946752 Compare March 18, 2025 12:42
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 5 of 5 files at r4, 2 of 2 files at r5, all commit messages.
Reviewable status: 10 of 11 files reviewed, 5 unresolved discussions (waiting on @ArniStarkware and @giladchase)

Copy link
Contributor Author

@giladchase giladchase 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: 10 of 11 files reviewed, 5 unresolved discussions (waiting on @alonh5 and @ArniStarkware)


crates/starknet_l1_provider/src/bootstrapper.rs line 50 at r2 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

This is the logical direction, makes it easier to read.
Also what is the current provider height defined as? is t the last retrieved block or the first unretrieved block?
Please document this and adjust here accordingly

Done and Done


crates/starknet_l1_provider/src/bootstrapper.rs line 137 at r2 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

can you use is_caught_up()?

Not quite, is_caught_up also has error handling for uninitialized catch-up, which is not possible here (and using it will imply that it can be uninitialized).
Also it's a method of the bootstrapper, and this function's running as a spawned task without access to self.

It's possible to refactor by extracting the comparison itself into a free function and reusing it, but it might become a bit forced 🤔


crates/starknet_l1_provider/src/l1_provider.rs line 215 at r2 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

What can fail here?

Nothing 😱
Tnx


crates/starknet_l1_provider/src/l1_provider.rs line 236 at r2 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

Will this warn happen only upon override?

Yep, cause of the Option::map. If the override is None then it'll skip the block.


crates/starknet_sequencer_node/src/components.rs line 264 at r4 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

Why should this fail?
Can this be an expect? Every other fail in this function is very well documented.

Never fails, AlonH also noticed, i'm stupid 😬

@giladchase giladchase force-pushed the gilad/03-16-fix_starknet_l1_provider_catch_up_height_from_sync_client branch 2 times, most recently from 932e0b6 to 95027e7 Compare March 18, 2025 13:01
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 2 of 3 files at r6, 1 of 1 files at r7.
Reviewable status: 10 of 11 files reviewed, 3 unresolved discussions (waiting on @ArniStarkware)


crates/starknet_l1_provider/src/bootstrapper.rs line 137 at r2 (raw file):

Previously, giladchase wrote…

Not quite, is_caught_up also has error handling for uninitialized catch-up, which is not possible here (and using it will imply that it can be uninitialized).
Also it's a method of the bootstrapper, and this function's running as a spawned task without access to self.

It's possible to refactor by extracting the comparison itself into a free function and reusing it, but it might become a bit forced 🤔

Right (the second part). It's fine like this


crates/starknet_l1_provider/src/bootstrapper.rs line 50 at r6 (raw file):

    pub fn is_caught_up(&self, current_provider_height: BlockNumber) -> bool {
        self.catch_up_height()
            .is_some_and(|catch_up_height| current_provider_height >= catch_up_height)

In this case it must be strictly larger, no?

Suggestion:

current_provider_height > catch_up_height

crates/starknet_l1_provider/src/bootstrapper.rs line 136 at r6 (raw file):

    let catch_up_height = *catch_up_height.get().expect("Initialized above");

    while catch_up_height >= current_height {

Actually this direction was right before. It depends what the logical statement is, in this case you want to say: while I haven't reached the catch up height keep catching up. In the previous example the statement is I am caught up if my I passes the catch up height.

Suggestion:

current_height <= catch_up_height

Copy link
Contributor Author

@giladchase giladchase 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: 10 of 11 files reviewed, 3 unresolved discussions (waiting on @alonh5 and @ArniStarkware)


crates/starknet_l1_provider/src/bootstrapper.rs line 50 at r6 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

In this case it must be strictly larger, no?

Most of the time ya, but you can have cases where the catch-up height is the same as the startup height. For example, when starting out a fresh node.


crates/starknet_l1_provider/src/bootstrapper.rs line 136 at r6 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

Actually this direction was right before. It depends what the logical statement is, in this case you want to say: while I haven't reached the catch up height keep catching up. In the previous example the statement is I am caught up if my I passes the catch up height.

Done.

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


crates/starknet_l1_provider/src/bootstrapper.rs line 50 at r6 (raw file):

Previously, giladchase wrote…

Most of the time ya, but you can have cases where the catch-up height is the same as the startup height. For example, when starting out a fresh node.

How come? it should be consistent


crates/starknet_l1_provider/src/bootstrapper.rs line 136 at r6 (raw file):

Previously, giladchase wrote…

Done.

Didn't push?


crates/starknet_l1_provider/tests/startup_flows.rs line 149 at r6 (raw file):

    // Make the mocked sync client try removing from a hashmap as a response to get block.
    let mut sync_client = MockStateSyncClient::default();
    sync_client.expect_get_block().returning(|_| panic!("Should not have been called!"));

This is not needed, it fails anyways if you don't set an expectation.

Code quote:

sync_client.expect_get_block().returning(|_| panic!("Should not have been called!"));

crates/starknet_l1_provider/tests/startup_flows.rs line 150 at r6 (raw file):

    let mut sync_client = MockStateSyncClient::default();
    sync_client.expect_get_block().returning(|_| panic!("Should not have been called!"));
    let sync_height_response = Arc::new(Mutex::new(None));

Is the Arc just so you can change it during the test? In that case you can use .times().returning(). Look at the batcher tests for reference.


crates/starknet_l1_provider/tests/startup_flows.rs line 178 at r6 (raw file):

    let no_txs_committed = []; // Not testing txs in this test.
    l1_provider.commit_block(&no_txs_committed, startup_height).unwrap();
    tokio::time::sleep(config.startup_sync_sleep_retry_interval).await;

Why do you need all the sleeps?


crates/starknet_l1_provider/tests/startup_flows.rs line 189 at r6 (raw file):

    assert!(l1_provider.state.is_bootstrapping());

    *sync_height_response.lock().unwrap() = Some(BlockNumber(2));

Is this the startup height on purpose? Can it be the height you reached?

Suggestion:

start_height_plus_2

@giladchase giladchase changed the base branch from gilad/03-13-fix_starknet_l1_provider_init_from_logstateupdate_height to main March 18, 2025 14:02
@giladchase giladchase force-pushed the gilad/03-16-fix_starknet_l1_provider_catch_up_height_from_sync_client branch from 95027e7 to 26ec149 Compare March 18, 2025 14:02
Copy link

graphite-app bot commented Mar 18, 2025

Merge activity

  • Mar 18, 10:02 AM EDT: Graphite rebased this pull request after merging its parent, because this pull request is set to merge when ready.

Most of this is boilerplate, major changes are:
1. catch up height is now lazily initialized by the spawned sync task
   which continously asks the sync state for its height. This can be
   None if the sync is starting up.
2. Until catch up height is ready, the rest of the startup flow is
   unchanged, with the addition that before the spawned task starts
   generating commit-blocks to sync up the provider, it'll first update
   the catch up height, which is synced with the bootstrapper.
@giladchase giladchase force-pushed the gilad/03-16-fix_starknet_l1_provider_catch_up_height_from_sync_client branch from 26ec149 to e5c0ec3 Compare March 18, 2025 14:26
Copy link
Contributor Author

@giladchase giladchase 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: all files reviewed, 7 unresolved discussions (waiting on @alonh5 and @ArniStarkware)


crates/starknet_l1_provider/src/bootstrapper.rs line 50 at r6 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

How come? it should be consistent

Offline discussions, yr right probably, will check async.


crates/starknet_l1_provider/src/bootstrapper.rs line 136 at r6 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

Didn't push?

Done.


crates/starknet_l1_provider/tests/startup_flows.rs line 149 at r6 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

This is not needed, it fails anyways if you don't set an expectation.

Done.


crates/starknet_l1_provider/tests/startup_flows.rs line 150 at r6 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

Is the Arc just so you can change it during the test? In that case you can use .times().returning(). Look at the batcher tests for reference.

Talked offline, added a comment


crates/starknet_l1_provider/tests/startup_flows.rs line 178 at r6 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

Why do you need all the sleeps?

Just to be safe, the sync task is spawned and running in the background every interval.


crates/starknet_l1_provider/tests/startup_flows.rs line 189 at r6 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

Is this the startup height on purpose? Can it be the height you reached?

Yep on purpose, spoke offline

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 r8, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ArniStarkware)

Copy link
Contributor

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

Reviewed all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @giladchase)

@giladchase giladchase added this pull request to the merge queue Mar 18, 2025
Merged via the queue into main with commit 81ae147 Mar 18, 2025
9 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 20, 2025
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.

4 participants