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_l1_provider): add interface to query ethereum gas price #3679

Merged
merged 1 commit into from
Feb 4, 2025

Conversation

guy-starkware
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

@guy-starkware guy-starkware marked this pull request as ready for review January 26, 2025 14:46
@guy-starkware guy-starkware force-pushed the guyn/l1price/contract_functions branch from f9de65f to 4fd24cf Compare January 29, 2025 10:13
@guy-starkware guy-starkware force-pushed the guyn/l1price/contract_functions branch from 4fd24cf to 7be5ae4 Compare January 29, 2025 11:13
@guy-starkware guy-starkware changed the title feat(base_layer): add interface to query ethereum gas price feat(starknet_l1_provider): add interface to query ethereum gas price Jan 29, 2025
@guy-starkware guy-starkware force-pushed the guyn/l1price/contract_functions branch 3 times, most recently from 4670244 to 3e0c217 Compare February 2, 2025 14:14
Copy link
Contributor

@asmaastarkware asmaastarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m also curious about ur questions

Reviewed 1 of 2 files at r2, 2 of 2 files at r3, all commit messages.
Reviewable status: 3 of 4 files reviewed, 5 unresolved discussions (waiting on @giladchase, @guy-starkware, and @matan-starkware)


crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs line 196 at r3 (raw file):

            .await?;
        if let Some(block) = block {
            match (block.header.timestamp, block.header.base_fee_per_gas) {

why do we just force gas price to have some value?


crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs line 206 at r3 (raw file):

        } else {
            Ok(None)
        }

Suggestion:

        let Some(block) = block else {
            Ok(None)
        };
        match (block.header.timestamp, block.header.base_fee_per_gas) {
            (timestamp, Some(base_fee_per_gas)) => Ok(Some(PriceSample {
                timestamp,
                base_fee_per_gas,
                blob_fee: block.header.blob_fee().unwrap_or(0),
            })),
            _ => Ok(None),
        } 

crates/papyrus_base_layer/src/lib.rs line 64 at r3 (raw file):

    ) -> Result<Vec<L1Event>, Self::Error>;

    async fn get_block_timestamp(&self, block_number: u64) -> Result<Option<u64>, Self::Error>;

why not pass L1BlockNumber instead of u64? (and bellow)


crates/papyrus_base_layer/src/lib.rs line 74 at r3 (raw file):

}

/// A struct the holds together the data on the baselayer's gas prices, for a given timestamp.

Suggestion:

/// A struct that holds together the data on the baselayer's gas prices, for a given timestamp.

crates/papyrus_base_layer/src/base_layer_test.rs line 86 at r3 (raw file):

    // if !in_ci() {
    //     return;
    // }

@guy-starkware guy-starkware force-pushed the guyn/l1price/contract_functions branch from 3e0c217 to fae7015 Compare February 3, 2025 14:06
Copy link
Contributor Author

@guy-starkware guy-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 4 files reviewed, 5 unresolved discussions (waiting on @asmaastarkware, @giladchase, and @matan-starkware)


crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs line 196 at r3 (raw file):

Previously, asmaastarkware (asmaa-starkware) wrote…

why do we just force gas price to have some value?

I think that in the general case data gas can be None, but for the specific goal of PriceSample it needs to have a value, even if it is zero. The way I think about it is the PriceSample is used to estimate the cost of the L2 block, using mean over many samples. If we start having None values in there it will make our life a lot more complicated. On the other hand, I think that None really means there is no cost for blobs, in which case zero is a good value for it.


crates/papyrus_base_layer/src/lib.rs line 64 at r3 (raw file):

Previously, asmaastarkware (asmaa-starkware) wrote…

why not pass L1BlockNumber instead of u64? (and bellow)

Yes, good idea.


crates/papyrus_base_layer/src/base_layer_test.rs line 86 at r3 (raw file):

    // if !in_ci() {
    //     return;
    // }

Actually I'm going to uncomment this. It is the same for the other tests (don't know why, maybe Gilad will know).


crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs line 206 at r3 (raw file):

        } else {
            Ok(None)
        }

Done.


crates/papyrus_base_layer/src/lib.rs line 74 at r3 (raw file):

}

/// A struct the holds together the data on the baselayer's gas prices, for a given timestamp.

Done.

Copy link
Contributor

@asmaastarkware asmaastarkware 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 4 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @giladchase and @matan-starkware)


crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs line 196 at r3 (raw file):

Previously, guy-starkware wrote…

I think that in the general case data gas can be None, but for the specific goal of PriceSample it needs to have a value, even if it is zero. The way I think about it is the PriceSample is used to estimate the cost of the L2 block, using mean over many samples. If we start having None values in there it will make our life a lot more complicated. On the other hand, I think that None really means there is no cost for blobs, in which case zero is a good value for it.

do u know in which cases gas price (base_fee_per_gas) is None?

Copy link
Contributor

@matan-starkware matan-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 1 of 4 files at r4, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @giladchase and @guy-starkware)


crates/papyrus_base_layer/src/lib.rs line 79 at r4 (raw file):

        &self,
        block_number: L1BlockNumber,
    ) -> Result<Option<PriceSample>, Self::Error>;

Unless there is a use case that specifically needs these, I'd rather not add them, just to keep the interface smaller.

(If this was some public library repo then adding as much as we can would be useful, but it's just used by people who can add these fns if they need them)

Suggestion:

    async fn get_price_sample(
        &self,
        block_number: L1BlockNumber,
    ) -> Result<Option<PriceSample>, Self::Error>;

crates/papyrus_base_layer/src/lib.rs line 89 at r4 (raw file):

}

impl Display for PriceSample {

Why do we need Display? Is Debug not sufficient (your implementation looks identical to what Debug would show)

Code quote:

impl Display for PriceSample {

Copy link
Contributor Author

@guy-starkware guy-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: all files reviewed, 2 unresolved discussions (waiting on @giladchase and @matan-starkware)


crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs line 196 at r3 (raw file):

Previously, asmaastarkware (asmaa-starkware) wrote…

do u know in which cases gas price (base_fee_per_gas) is None?

I'm not sure. I am guessing that it happens when the blob demand is low (i.e., there's more room in blob than people want).


crates/papyrus_base_layer/src/lib.rs line 79 at r4 (raw file):

Previously, matan-starkware wrote…

Unless there is a use case that specifically needs these, I'd rather not add them, just to keep the interface smaller.

(If this was some public library repo then adding as much as we can would be useful, but it's just used by people who can add these fns if they need them)

Done.


crates/papyrus_base_layer/src/lib.rs line 89 at r4 (raw file):

Previously, matan-starkware wrote…

Why do we need Display? Is Debug not sufficient (your implementation looks identical to what Debug would show)

Yes, I guess you are right.

@guy-starkware guy-starkware force-pushed the guyn/l1price/contract_functions branch from fae7015 to cbaa0d6 Compare February 4, 2025 09:15
Copy link
Contributor

@matan-starkware matan-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 3 of 3 files at r5, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @giladchase and @guy-starkware)


crates/papyrus_base_layer/src/base_layer_test.rs line 100 at r5 (raw file):

        "Gas price: {}, data gas price: {:?}, timestamp: {}",
        price_sample.blob_fee, price_sample.base_fee_per_gas, price_sample.timestamp
    );

Good thing to discuss with Gilad

Remove the print statement since you have the asserts

Suggestion:

    // TODO(guyn): Figure out how these numbers are calculated, instead of just printing and testing
    // against what we got. Use this println! to get the numbers to put into the asserts.

@guy-starkware guy-starkware force-pushed the guyn/l1price/contract_functions branch from cbaa0d6 to 6d0ed1b Compare February 4, 2025 10:17
Copy link
Contributor Author

@guy-starkware guy-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: all files reviewed, 1 unresolved discussion (waiting on @giladchase and @matan-starkware)


crates/papyrus_base_layer/src/base_layer_test.rs line 100 at r5 (raw file):

Previously, matan-starkware wrote…

Good thing to discuss with Gilad

Remove the print statement since you have the asserts

Done.

@matan-starkware matan-starkware self-requested a review February 4, 2025 11:15
Copy link
Contributor

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

@guy-starkware guy-starkware added this pull request to the merge queue Feb 4, 2025
Merged via the queue into main with commit 0bb11be Feb 4, 2025
16 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Feb 7, 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