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(blockifier): compute allocation cost #2301

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

yoavGrs
Copy link
Contributor

@yoavGrs yoavGrs commented Nov 27, 2024

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

@yoavGrs yoavGrs marked this pull request as ready for review November 27, 2024 08:50
Copy link

codecov bot commented Nov 27, 2024

Codecov Report

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

Project coverage is 68.07%. Comparing base (e3165c4) to head (e281147).
Report is 666 commits behind head on main.

Files with missing lines Patch % Lines
crates/blockifier/src/fee/resources.rs 58.33% 8 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2301       +/-   ##
===========================================
+ Coverage   40.10%   68.07%   +27.96%     
===========================================
  Files          26      109       +83     
  Lines        1895    14314    +12419     
  Branches     1895    14314    +12419     
===========================================
+ Hits          760     9744     +8984     
- Misses       1100     4156     +3056     
- Partials       35      414      +379     

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

Copy link
Contributor

@nimrod-starkware nimrod-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 6 files at r1.
Reviewable status: 3 of 6 files reviewed, 2 unresolved discussions (waiting on @yoavGrs)


crates/blockifier/src/fee/resources.rs line 206 at r1 (raw file):

                 to {da_gas_cost:?}",
            )
        })

Do we want to panic in that case? Isn't it better to return something like GasVector::MAX?

Code quote:

    pub fn to_gas_vector(&self, use_kzg_da: bool, allocation_cost: &AllocationCost) -> GasVector {
        let n_allocated_keys = self.state_changes_for_fee.n_allocated_keys;
        let allocation_gas_vector = allocation_cost.get_cost(use_kzg_da);
        let total_allocation_cost =
            allocation_gas_vector.checked_mul(n_allocated_keys).unwrap_or_else(|| {
                panic!(
                    "State resources to gas vector overflowed: tried to multiply \
                     {allocation_gas_vector:?} by {n_allocated_keys:?}",
                )
            });
        let da_gas_cost =
            get_da_gas_cost(&self.state_changes_for_fee.state_changes_count, use_kzg_da);
        total_allocation_cost.checked_add(da_gas_cost).unwrap_or_else(|| {
            panic!(
                "State resources to gas vector overflowed: tried to add {total_allocation_cost:?} \
                 to {da_gas_cost:?}",
            )
        })

crates/blockifier/src/transaction/transactions_test.rs line 2308 at r1 (raw file):

        true => GasVector::from_l1_data_gas(160_u32.into()),
        false => GasVector::from_l1_gas(2203_u32.into()),
    };

If you set block_context.versioned_constants.allocation_cost = AllocationCost::ZERO, then the values are equal?

Code quote:

    let expected_gas = match use_kzg_da {
        true => GasVector {
            l1_gas: 17988_u32.into(),
            l1_data_gas: 160_u32.into(),
            l2_gas: 0_u32.into(),
        },
        false => GasVector::from_l1_gas(19682_u32.into()),
    };

    let expected_da_gas = match use_kzg_da {
        true => GasVector::from_l1_data_gas(160_u32.into()),
        false => GasVector::from_l1_gas(2203_u32.into()),
    };

@yoavGrs yoavGrs force-pushed the yoav/compression/checked_mul branch from 2198400 to b9eb760 Compare November 27, 2024 13:23
@yoavGrs yoavGrs force-pushed the yoav/compression/add_allocated_keys_to_gas_vector branch from 1ba2b81 to 2ca3609 Compare November 27, 2024 13:23
Copy link
Contributor Author

@yoavGrs yoavGrs 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: 3 of 6 files reviewed, 2 unresolved discussions (waiting on @nimrod-starkware)


crates/blockifier/src/fee/resources.rs line 206 at r1 (raw file):

Previously, nimrod-starkware wrote…

Do we want to panic in that case? Isn't it better to return something like GasVector::MAX?

Yes, I want to panic.
Like in the function to_gas_vector of StarknetResources that calls to this function.
We don't want to lose fees.


crates/blockifier/src/transaction/transactions_test.rs line 2308 at r1 (raw file):

Previously, nimrod-starkware wrote…

If you set block_context.versioned_constants.allocation_cost = AllocationCost::ZERO, then the values are equal?

Yes, with AllocationCost::ZERO the test passes without changes.

@yoavGrs yoavGrs force-pushed the yoav/compression/checked_mul branch 2 times, most recently from 6b3e7d8 to 3faf3f5 Compare November 27, 2024 13:51
@yoavGrs yoavGrs force-pushed the yoav/compression/add_allocated_keys_to_gas_vector branch from 2ca3609 to 179a4dd Compare November 27, 2024 13:52
@yoavGrs yoavGrs force-pushed the yoav/compression/add_allocated_keys_to_gas_vector branch from 179a4dd to f50f2fa Compare November 27, 2024 14:27
Copy link
Contributor

@nimrod-starkware nimrod-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: 3 of 6 files reviewed, 1 unresolved discussion (waiting on @dorimedini-starkware and @yoavGrs)


crates/blockifier/src/transaction/transactions_test.rs line 2308 at r1 (raw file):

Previously, yoavGrs wrote…

Yes, with AllocationCost::ZERO the test passes without changes.

I would prefer to set block_context.versioned_constants.allocation_cost = AllocationCost::ZERO, and keep values as they were

Copy link
Collaborator

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

Reviewed 3 of 6 files at r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @nimrod-starkware and @yoavGrs)


crates/blockifier/src/transaction/transactions_test.rs line 2308 at r1 (raw file):

Previously, nimrod-starkware wrote…

I would prefer to set block_context.versioned_constants.allocation_cost = AllocationCost::ZERO, and keep values as they were

this is wrong: the DA gas in the receipt should not change, regardless of allocation cost


crates/blockifier/src/fee/resources.rs line 207 at r1 (raw file):

            )
        })
    }

where do we compute the da_gas in the TransactionReceipt?
please make sure it is NOT state_resource.to_gas_vector... if it is, please update it (maybe add a to_da_gas_vector method in this struct?)

Suggestion:

    pub fn to_gas_vector(&self, use_kzg_da: bool, allocation_cost: &AllocationCost) -> GasVector {
        let n_allocated_keys = self.state_changes_for_fee.n_allocated_keys;
        let allocation_gas_vector = allocation_cost.get_cost(use_kzg_da);
        let total_allocation_cost =
            allocation_gas_vector.checked_mul(n_allocated_keys).unwrap_or_else(|| {
                panic!(
                    "State resources to gas vector overflowed: tried to multiply \
                     {allocation_gas_vector:?} by {n_allocated_keys:?}",
                )
            });
        let da_gas_cost = self.to_da_gas_vector(use_kzg_da);
        total_allocation_cost.checked_add(da_gas_cost).unwrap_or_else(|| {
            panic!(
                "State resources to gas vector overflowed: tried to add {total_allocation_cost:?} \
                 to {da_gas_cost:?}",
            )
        })
    }

crates/blockifier/src/transaction/transactions_test.rs line 593 at r1 (raw file):

        receipt: TransactionReceipt {
            fee: expected_actual_fee,
            da_gas,

this is wrong - the da_gas you compute includes allocation costs.
please fix the computation of the TransactionReceipt (maybe many tests will fail... but you will see which ones at least)

Code quote:

da_gas,

@yoavGrs yoavGrs force-pushed the yoav/compression/checked_mul branch from 3faf3f5 to 5f46b60 Compare December 2, 2024 09:14
@yoavGrs yoavGrs force-pushed the yoav/compression/add_allocated_keys_to_gas_vector branch from f50f2fa to e3c7be2 Compare December 2, 2024 09:14
Copy link
Contributor Author

@yoavGrs yoavGrs 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: 1 of 6 files reviewed, 3 unresolved discussions (waiting on @dorimedini-starkware and @nimrod-starkware)


crates/blockifier/src/fee/resources.rs line 207 at r1 (raw file):

Previously, dorimedini-starkware wrote…

where do we compute the da_gas in the TransactionReceipt?
please make sure it is NOT state_resource.to_gas_vector... if it is, please update it (maybe add a to_da_gas_vector method in this struct?)

Done.


crates/blockifier/src/transaction/transactions_test.rs line 593 at r1 (raw file):

Previously, dorimedini-starkware wrote…

this is wrong - the da_gas you compute includes allocation costs.
please fix the computation of the TransactionReceipt (maybe many tests will fail... but you will see which ones at least)

Done.


crates/blockifier/src/transaction/transactions_test.rs line 2308 at r1 (raw file):

Previously, dorimedini-starkware wrote…

this is wrong: the DA gas in the receipt should not change, regardless of allocation cost

Done.

@yoavGrs yoavGrs force-pushed the yoav/compression/checked_mul branch from 5f46b60 to fbc72a7 Compare December 2, 2024 12:46
@yoavGrs yoavGrs force-pushed the yoav/compression/add_allocated_keys_to_gas_vector branch from e3c7be2 to c209c11 Compare December 2, 2024 12:46
Copy link
Collaborator

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

:lgtm:

Reviewed 5 of 5 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @nimrod-starkware)

Copy link
Contributor

@nimrod-starkware nimrod-starkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @yoavGrs)

Copy link
Collaborator

@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 @yoavGrs)

@yoavGrs yoavGrs changed the base branch from yoav/compression/checked_mul to graphite-base/2301 December 3, 2024 09:15
@yoavGrs yoavGrs force-pushed the yoav/compression/add_allocated_keys_to_gas_vector branch from c209c11 to 662a062 Compare December 3, 2024 09:15
@yoavGrs yoavGrs force-pushed the graphite-base/2301 branch from fbc72a7 to 340c229 Compare December 3, 2024 09:15
@yoavGrs yoavGrs changed the base branch from graphite-base/2301 to main December 3, 2024 09:16
@yoavGrs yoavGrs force-pushed the yoav/compression/add_allocated_keys_to_gas_vector branch from 662a062 to fd0adba Compare December 3, 2024 09:16
@yoavGrs yoavGrs force-pushed the yoav/compression/add_allocated_keys_to_gas_vector branch from fd0adba to e281147 Compare December 3, 2024 09:28
Copy link
Collaborator

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

Reviewed 1 of 1 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @yoavGrs)

@yoavGrs yoavGrs merged commit ef4d972 into main Dec 3, 2024
13 checks passed
FrancoGiachetta added a commit to lambdaclass/sequencer that referenced this pull request Dec 6, 2024
* chore(starknet_batcher): delete obsolete todo (starkware-libs#2389)

* chore(blockifier): add global max_sierra_gas to versioned constants (starkware-libs#2330)

* feat(starknet_api): checked mul for gas vector (starkware-libs#2300)

* feat(consensus): proposer rotates across validators (starkware-libs#2405)

* feat(sequencing): validate streamed proposals (starkware-libs#2305)

* feat(ci): deny rust warnings in all workflows (starkware-libs#2388)

Signed-off-by: Dori Medini <[email protected]>

* feat(blockifier): compute allocation cost (starkware-libs#2301)

* chore(starknet_sequencer_infra): add dynamic logging util fn

commit-id:9ffe9fbe

* chore(starknet_sequencer_infra): add tracing test

commit-id:76d16e9a

* chore(starknet_sequencer_infra): add run_until utility fn

commit-id:194a4b6c

* chore(infra_utils): change run_until to support async functions

commit-id:92e1f8a3

* chore(starknet_integration_tests): use run_until to await for block creation

commit-id:667e001c

* chore(infra_utils): rename logger struct

commit-id:6520ae54

* chore(blockifier): explicit creation of AccountTransaction (starkware-libs#2331)

* test(starknet_integration_tests): test commit blocks by running multiple heights

* chore(starknet_batcher): set temp gas prices in propose block input (starkware-libs#2341)

* chore(starknet_batcher): set use_kzg_da flag in build block input (starkware-libs#2345)

* feat(ci): inherit the rust toolchain toml in moonrepo action (starkware-libs#2423)

Signed-off-by: Dori Medini <[email protected]>

* chore(blockifier): enforce_fee() impl by api::executable_transaction::AccountTransaction (starkware-libs#2377)

* chore(starknet_integration_tests): inherit sequencer node's stdout (starkware-libs#2427)

* chore(blockifier): invoke() declare() deploy_account() change ret val to api_tx (starkware-libs#2412)

* chore(starknet_consensus_manager): set proposer address in propose block input (starkware-libs#2346)

* feat(consensus): add observer mode

* feat(consensus): sequencer context broadcasts votes (starkware-libs#2422)

* chore(deployment): support unified deployment config (starkware-libs#2378)

* feat(starknet_api): add sierra version to class info (starkware-libs#2313)

* refactor(starknet_api): change default sierra contract class to valid one (starkware-libs#2439)

* feat(starknet_l1_provider): add uninitiailized state and make it the default (starkware-libs#2434)

This is to comply with upcoming integration with infra, which separates
instantiation with initialization. In particular, `Pending` state should
be already post-syncing with L1, whereas `Uninitialized` is unsynced and
unusable.

Co-Authored-By: Gilad Chase <[email protected]>

* feat(papyrus_storage)!: bump storage version for version 13.4 (starkware-libs#2333)

* feat(native_blockifier): allow deserialization of  python l1_data_gas (starkware-libs#2447)

* refactor(blockifier): split FC to groups base on their tags (starkware-libs#2236)

* test(consensus): remove warning on into mock propsal part (starkware-libs#2448)

* chore(blockifier): use test_utils::invoke_tx() instead of trans::test_utils::account_invoke_tx() (starkware-libs#2428)

* chore(blockifier): save sierra to Feature contracts (starkware-libs#2370)

* feat(blockifier): don't count Sierra gas in CairoSteps mode (starkware-libs#2440)

* chore(blockifier): convert Sierra gas to L1 gas if in L1 gas mode (starkware-libs#2451)

* feat(blockifier): add comprehensive state diff versioned constant (starkware-libs#2407)

* chore(starknet_consensus_manager): add chain_id to config

* refactor(papyrus_p2p_sync): add random_header utility function (starkware-libs#2381)

* chore(starknet_batcher): pass block info from consensus to batcher (starkware-libs#2238)

* test(starknet_mempool): tx added to mempool are forwarded to propagator client (starkware-libs#2288)

* fix: fix CR comments

* test(starknet_mempool): tx added to mempool are forwarded to propagator client

* feat(sequencing): cache proposals from bigger heights(starkware-libs#2325)

* fix: change to latest ubuntu version in feature combo CI (starkware-libs#2414)

* chore(blockifier): replace entry_point_gas_cost with initial_budget (starkware-libs#2247)

* test(starknet_gateway): handle todo in test_get_block_info (starkware-libs#2267)

* chore(starknet_api): revert use get_packaget_dir instead of env var

This reverts commit c45f5cc.

commit-id:a48736e7

* chore(starknet_api): rely on env::current_dir() instead of CARGO_MANIFEST_DIR

commit-id:301ed4eb

* chore(blockifier): move env var from run time to compile time

commit-id:80a7265d

* chore(starknet_sierra_compile): move env var from run time to compile time

commit-id:6e7f2a75

* chore: remove the use of zero as a validator id (starkware-libs#2411)

* refactor(papyrus_p2p_sync): add_test receives query size instead of constant (starkware-libs#2379)

* fix(blockifier): merge state diff with squash (starkware-libs#2310)

* feat(blockifier): get revert receipt only in case of revert (starkware-libs#2471)

* chore(starknet_integration_tests): create chain info once (starkware-libs#2482)

* chore(starknet_sierra_compile): split build utils

commit-id:0f504fd7

* chore(starknet_sierra_compile): set runtime-accessible out_dir env var

commit-id:539f16db

* chore(starknet_sierra_compile): avoid using OUT_DIR in run time

commit-id:cd6fba29

* refactor(starknet_api): use const in sierra version (starkware-libs#2477)

* chore: cleanups of OUT_DIR env var (starkware-libs#2484)

commit-id:18d61b1d

* chore(starknet_api): shorten executable_transaction  usage path

* fix(sequencing): remove old proposal pipes from consensus (starkware-libs#2452)

* test(starknet_integration_tests): match sequencer address with default validator id (starkware-libs#2486)

* fix(ci): move specific versioned deps to root toml (starkware-libs#2487)

* fix(ci): move specific versioned deps to root toml

Signed-off-by: Dori Medini <[email protected]>

* fix(starknet_sierra_compile): fix build.rs

Signed-off-by: Dori Medini <[email protected]>

* chore(starknet_batcher): in block builder use the consensus suplied sequncer address (starkware-libs#2409)

* chore: cleanups of CARGO_MANIFEST_DIR env var

commit-id:c96f2d88

* fix(starknet_sierra_compile): missing import in feature (starkware-libs#2495)

commit-id:abd0a286

* chore(blockifier): add keccak_builtin_gas_cost (starkware-libs#2327)

* chore(blockifier): add struct ExecutionFlags to AccTx & use instead of transaction::ExecutionFlags (starkware-libs#2429)

* chore(blockifier): add new constructor to AccountTransaction (starkware-libs#2431)

* chore(blockifier): remove only_qury from IvokeTxArgs (starkware-libs#2437)

* chore(blockifier): remove struct ExecutionFlags and replace w concurrency_mode bool (starkware-libs#2470)

* chore(blockifier): remove declare.rs deploy_account.rs invoke.rs from blockifier (starkware-libs#2478)

---------

Signed-off-by: Dori Medini <[email protected]>
Co-authored-by: YaelD <[email protected]>
Co-authored-by: aner-starkware <[email protected]>
Co-authored-by: yoavGrs <[email protected]>
Co-authored-by: matan-starkware <[email protected]>
Co-authored-by: guy-starkware <[email protected]>
Co-authored-by: dorimedini-starkware <[email protected]>
Co-authored-by: Itay Tsabary <[email protected]>
Co-authored-by: avivg-starkware <[email protected]>
Co-authored-by: Yair Bakalchuk <[email protected]>
Co-authored-by: Arnon Hod <[email protected]>
Co-authored-by: Alon Haramati <[email protected]>
Co-authored-by: Asmaa Magdoub <[email protected]>
Co-authored-by: alon-dotan-starkware <[email protected]>
Co-authored-by: AvivYossef-starkware <[email protected]>
Co-authored-by: giladchase <[email protected]>
Co-authored-by: Gilad Chase <[email protected]>
Co-authored-by: DvirYo-starkware <[email protected]>
Co-authored-by: nimrod-starkware <[email protected]>
Co-authored-by: Meshi Peled <[email protected]>
Co-authored-by: Yoni <[email protected]>
Co-authored-by: Yael Doweck <[email protected]>
Co-authored-by: ShahakShama <[email protected]>
Co-authored-by: Alon-Lukatch-Starkware <[email protected]>
Co-authored-by: Yonatan-Starkware <[email protected]>
Co-authored-by: Yair <[email protected]>
Co-authored-by: Itay-Tsabary-Starkware <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators Dec 7, 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