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_state_sync): implement sync state reader get block info #2887

Conversation

noamsp-starkware
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@noamsp-starkware noamsp-starkware marked this pull request as ready for review December 22, 2024 19:47
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 r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @noamsp-starkware)


crates/starknet_state_sync/src/lib.rs line 200 at r1 (raw file):

    }

    fn get_block_header(&self, block_number: BlockNumber) -> StateSyncResult<BlockHeader> {

Change this to get_block_info and have it return the block info extracted from the header


crates/starknet_state_sync/src/lib.rs line 203 at r1 (raw file):

        let txn = self.storage_reader.begin_ro_txn()?;
        let latest_block_number = txn.get_header_marker()?.prev();
        if latest_block_number.is_none_or(|latest_block_number| latest_block_number < block_number)

No need for this check. You can just straight up call get_block_header and it will return None if latest_block_number < block_number


crates/starknet_gateway/src/sync_state_reader.rs line 42 at r1 (raw file):

            sequencer_address: block_header_without_hash.sequencer.0,
            block_timestamp: block_header_without_hash.timestamp,
            gas_prices: validated_gas_prices(

What's validated_gas_prices and parse_gas_prices? Could you point me to the code where you've seen this used?

@noamsp-starkware noamsp-starkware force-pushed the noam.s/implement_sync_state_reader_get_block_info branch from d52f5b8 to f339fbb Compare December 23, 2024 18:55
Copy link
Contributor Author

@noamsp-starkware noamsp-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: 0 of 5 files reviewed, 3 unresolved discussions (waiting on @ShahakShama)


crates/starknet_gateway/src/sync_state_reader.rs line 42 at r1 (raw file):

Previously, ShahakShama wrote…

What's validated_gas_prices and parse_gas_prices? Could you point me to the code where you've seen this used?

sequencer/crates/starknet_gateway/src/rpc_objects.rs

Code snippet:

impl TryInto<BlockInfo> for BlockHeader {
    type Error = RPCStateReaderError;
    fn try_into(self) -> Result<BlockInfo, Self::Error> {
        Ok(BlockInfo {
            block_number: self.block_number,
            sequencer_address: self.sequencer_address,
            block_timestamp: self.timestamp,
            gas_prices: validated_gas_prices(
                parse_gas_price(self.l1_gas_price.price_in_wei)?,
                parse_gas_price(self.l1_gas_price.price_in_fri)?,
                parse_gas_price(self.l1_data_gas_price.price_in_wei)?,
                parse_gas_price(self.l1_data_gas_price.price_in_fri)?,
                parse_gas_price(self.l2_gas_price.price_in_wei)?,
                parse_gas_price(self.l2_gas_price.price_in_fri)?,
            ),
            use_kzg_da: matches!(self.l1_da_mode, L1DataAvailabilityMode::Blob),
        })
    }
}

crates/starknet_state_sync/src/lib.rs line 200 at r1 (raw file):

Previously, ShahakShama wrote…

Change this to get_block_info and have it return the block info extracted from the header

Done.


crates/starknet_state_sync/src/lib.rs line 203 at r1 (raw file):

Previously, ShahakShama wrote…

No need for this check. You can just straight up call get_block_header and it will return None if latest_block_number < block_number

Done.

Copy link

Artifacts upload workflows:

Copy link
Contributor

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

Reviewed 5 of 5 files at r2, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @noamsp-starkware and @ShahakShama)


crates/starknet_gateway/src/sync_state_reader.rs line 37 at r2 (raw file):

            Some(block_info) => block_info,
            None => return Err(StateError::StateReadError("Block info not found".to_string())),
        };

Suggestion:

        maybe_block_info.ok_or_else(...)
        let block_info = match maybe_block_info {
            Some(block_info) => block_info,
            None => return Err(StateError::StateReadError("Block info not found".to_string())),
        };

crates/starknet_state_sync/src/lib.rs line 206 at r2 (raw file):

        let txn = self.storage_reader.begin_ro_txn()?;

        if let Some(block_header) = txn.get_block_header(block_number)? {

reduce nesting

Suggestion:

        let Some(block_header) = txn.get_block_header(block_number)? else { return None
        if let Some(block_header) = txn.get_block_header(block_number)? {

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 all commit messages.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @noamsp-starkware)


crates/starknet_state_sync/src/lib.rs line 203 at r2 (raw file):

    }

    fn get_block_info(&self, block_number: BlockNumber) -> StateSyncResult<Option<BlockInfo>> {

Now that Eitan added block info to get_block, we can erase this method and use get_block in SyncStateReader

@noamsp-starkware
Copy link
Contributor Author

Closing this due to big changes that require a different approach. opened the respective fixed PR at #2942

@noamsp-starkware noamsp-starkware deleted the noam.s/implement_sync_state_reader_get_block_info branch December 25, 2024 10:11
@github-actions github-actions bot locked and limited conversation to collaborators Dec 27, 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.

4 participants