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

refactor(starknet_api,blockifier): to_discounted_gas_amount #2874

Conversation

dorimedini-starkware
Copy link
Collaborator

No description provided.

@dorimedini-starkware dorimedini-starkware self-assigned this Dec 22, 2024
@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Collaborator Author

@dorimedini-starkware dorimedini-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 2 files reviewed, all discussions resolved (waiting on @TzahiTaub)


crates/starknet_api/src/execution_resources.rs line 179 at r1 (raw file):

    l1_gas: GasAmount,
    l1_data_gas: GasAmount,
) -> GasAmount {

this change is to make explicit the fact that L2 gas is ignored here

Code quote:

pub fn to_discounted_l1_gas(
    l1_gas_price: NonzeroGasPrice,
    l1_data_gas_price: GasPrice,
    l1_gas: GasAmount,
    l1_data_gas: GasAmount,
) -> GasAmount {

@dorimedini-starkware dorimedini-starkware force-pushed the dori/convert-l2-gas-to-l1-gas-in-deprecated-bounds branch from c1695dc to 486d8d3 Compare December 24, 2024 12:21
@dorimedini-starkware dorimedini-starkware force-pushed the dori/refactor-discounted-l1-gas-computation branch from 8540cef to def2bc0 Compare December 24, 2024 12:21
@dorimedini-starkware dorimedini-starkware force-pushed the dori/convert-l2-gas-to-l1-gas-in-deprecated-bounds branch from 486d8d3 to 191993e Compare January 1, 2025 12:25
@dorimedini-starkware dorimedini-starkware force-pushed the dori/refactor-discounted-l1-gas-computation branch from def2bc0 to a2dcbb4 Compare January 1, 2025 12:26
Copy link
Contributor

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


crates/starknet_api/src/execution_resources.rs line 167 at r2 (raw file):

}

/// Compute l1_gas estimation from gas_vector using the following formula:

Why is this an "estimation"?

Suggestion:

Computes the total l1 gas amount from the different given l1 gas arguments using the following formula:

crates/starknet_api/src/execution_resources.rs line 185 at r2 (raw file):

    l1_data_gas: GasAmount,
) -> GasAmount {
    let l1_data_gas_fee = l1_data_gas.checked_mul(l1_data_gas_price).unwrap_or_else(|| {

Makes more sense to make the conversion here and have the type as it's in GasPriceVector IMO

Suggestion:

pub fn to_discounted_l1_gas(
    l1_gas_price: NonzeroGasPrice,
    l1_data_gas_price: NonzeroGasPrice,
    l1_gas: GasAmount,
    l1_data_gas: GasAmount,
) -> GasAmount {
    let l1_data_gas_fee = l1_data_gas.checked_mul(l1_data_gas_price.into()).unwrap_or_else(|| {

crates/blockifier/src/fee/fee_utils.rs line 47 at r2 (raw file):

        let discounted_l1_gas = to_discounted_l1_gas(
            gas_prices.l1_gas_price,
            gas_prices.l1_data_gas_price.into(),

Remove if you accept the suggestion below

Suggestion:

  gas_prices.l1_data_gas_price,

Copy link
Collaborator Author

@dorimedini-starkware dorimedini-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, 3 unresolved discussions (waiting on @TzahiTaub)


crates/blockifier/src/fee/fee_utils.rs line 47 at r2 (raw file):

Previously, TzahiTaub (Tzahi) wrote…

Remove if you accept the suggestion below

see below


crates/starknet_api/src/execution_resources.rs line 167 at r2 (raw file):

Previously, TzahiTaub (Tzahi) wrote…

Why is this an "estimation"?

maybe the wording is unclear: the actual value returned isn't really an amount of L1 gas, it's a "best effort" conversion, to be able to charge users signing deprecated resource bounds in proportion to actual computation resources / DA gas used.
I used the word "estimation", do you have a suggestion?
(your suggestion implies the returned value is actually L1 gas, when it really isn't..)


crates/starknet_api/src/execution_resources.rs line 185 at r2 (raw file):

Previously, TzahiTaub (Tzahi) wrote…

Makes more sense to make the conversion here and have the type as it's in GasPriceVector IMO

as an API decision: we require the L1 gas price to be nonzero, but the data gas price is allowed to be zero. Why enforce nonzero data gas price?

Copy link
Collaborator Author

@dorimedini-starkware dorimedini-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, 4 unresolved discussions (waiting on @dorimedini-starkware and @TzahiTaub)


a discussion (no related file):
py side

@dorimedini-starkware dorimedini-starkware force-pushed the dori/convert-l2-gas-to-l1-gas-in-deprecated-bounds branch from 191993e to e6d14ee Compare January 2, 2025 09:50
@dorimedini-starkware dorimedini-starkware force-pushed the dori/refactor-discounted-l1-gas-computation branch from a2dcbb4 to ab5576c Compare January 2, 2025 09:50
@TzahiTaub
Copy link
Contributor

crates/starknet_api/src/execution_resources.rs line 185 at r2 (raw file):

Previously, dorimedini-starkware wrote…

as an API decision: we require the L1 gas price to be nonzero, but the data gas price is allowed to be zero. Why enforce nonzero data gas price?

I don't know but that's the type we have here

Copy link
Collaborator Author

@dorimedini-starkware dorimedini-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, 3 unresolved discussions (waiting on @dorimedini-starkware and @TzahiTaub)


crates/starknet_api/src/execution_resources.rs line 185 at r2 (raw file):

Previously, TzahiTaub (Tzahi) wrote…

I don't know but that's the type we have here

yes, gas prices in general must be non-zero because sometimes we divide by them.
in this specific function, we divide by L1 gas price, but we only multiply by data gas price, so it can be zero

@TzahiTaub
Copy link
Contributor

crates/starknet_api/src/execution_resources.rs line 185 at r2 (raw file):

Previously, dorimedini-starkware wrote…

yes, gas prices in general must be non-zero because sometimes we divide by them.
in this specific function, we divide by L1 gas price, but we only multiply by data gas price, so it can be zero

I don't understand, it's illegal for a use to give a 0 DA price, but you want to support it in this specific helper function?

Copy link
Collaborator Author

@dorimedini-starkware dorimedini-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, 3 unresolved discussions (waiting on @dorimedini-starkware and @TzahiTaub)


crates/starknet_api/src/execution_resources.rs line 185 at r2 (raw file):

Previously, TzahiTaub (Tzahi) wrote…

I don't understand, it's illegal for a use to give a 0 DA price, but you want to support it in this specific helper function?

yes, because this function doesn't care.
GasPriceVector is used in many places, specifically in the block info, where we do not allow zero gas prices

Copy link
Contributor

@TzahiTaub TzahiTaub 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, 3 unresolved discussions (waiting on @dorimedini-starkware)


crates/starknet_api/src/execution_resources.rs line 167 at r2 (raw file):

Previously, dorimedini-starkware wrote…

maybe the wording is unclear: the actual value returned isn't really an amount of L1 gas, it's a "best effort" conversion, to be able to charge users signing deprecated resource bounds in proportion to actual computation resources / DA gas used.
I used the word "estimation", do you have a suggestion?
(your suggestion implies the returned value is actually L1 gas, when it really isn't..)

Computes the total l1 gas amount estimation from the different given l1 gas arguments using the following formula:

@dorimedini-starkware dorimedini-starkware force-pushed the dori/refactor-discounted-l1-gas-computation branch from ab5576c to d56b835 Compare January 2, 2025 12:04
Copy link
Collaborator Author

@dorimedini-starkware dorimedini-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: :shipit: complete! all files reviewed, all discussions resolved (waiting on @dorimedini-starkware)


a discussion (no related file):

Previously, dorimedini-starkware wrote…

py side

passes

@dorimedini-starkware dorimedini-starkware force-pushed the dori/convert-l2-gas-to-l1-gas-in-deprecated-bounds branch from e6d14ee to 7ce4459 Compare January 2, 2025 13:40
@dorimedini-starkware dorimedini-starkware force-pushed the dori/refactor-discounted-l1-gas-computation branch from d56b835 to 016c9ea Compare January 2, 2025 13:40
@dorimedini-starkware dorimedini-starkware changed the base branch from dori/convert-l2-gas-to-l1-gas-in-deprecated-bounds to main-v0.13.4 January 2, 2025 14:33
Signed-off-by: Dori Medini <dori@starkware.co>
@dorimedini-starkware dorimedini-starkware force-pushed the dori/refactor-discounted-l1-gas-computation branch from 016c9ea to 1f8d613 Compare January 2, 2025 14:33
Copy link
Contributor

@TzahiTaub TzahiTaub 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 r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @dorimedini-starkware)

@dorimedini-starkware dorimedini-starkware merged commit b1f93c9 into main-v0.13.4 Jan 9, 2025
14 checks passed
@dorimedini-starkware dorimedini-starkware deleted the dori/refactor-discounted-l1-gas-computation branch January 9, 2025 12:51
@github-actions github-actions bot locked and limited conversation to collaborators Jan 11, 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.

3 participants