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): add struct StateChangesCountForFee #2175

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

yoavGrs
Copy link
Contributor

@yoavGrs yoavGrs commented Nov 19, 2024

No description provided.

@yoavGrs yoavGrs self-assigned this Nov 19, 2024
@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link

Artifacts upload triggered. View details here

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 8 of 8 files at r1, all commit messages.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on @yoavGrs)


crates/blockifier/src/transaction/transactions_test.rs line 0 at r1 (raw file):
same as above: does it make sense to have nonzero values for n_allocations in this test?


crates/blockifier/src/state/cached_state.rs line 731 at r1 (raw file):

                n_modified_contracts: modified_contracts.len(),
            },
            n_allocated_keys: if enable_stateful_compression {

hmmm... maybe this flag is a bit confusing...
I would expect enable_stateful_compression to indicate whether or not contract 0x2 appears in the state diff,
not whether or not we charge for allocations (which is what is happening here).
should we have two separate flags for this? @Yoni-Starkware

Code quote:

n_allocated_keys: if enable_stateful_compression {

crates/blockifier/src/state/cached_state.rs line 755 at r1 (raw file):

pub struct StateChangesCountForFee {
    pub state_changes_count: StateChangesCount,
    pub n_allocated_keys: usize,

just to be clear: this field will be computed, regardless of the enable_stateful_compression flag, correct?

Code quote:

 pub n_allocated_keys: usize,

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

        sender_address: Option<ContractAddress>,
        fee_token_address: ContractAddress,
        enable_stateful_compression: bool,

consider this rename, everywhere (see below - maybe a separate flag for stateful compression?)

Suggestion:

charge_for_allocations: bool,

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

        // TODO(Nimrod, 29/3/2024): delete `get_da_gas_cost` and move it's logic here.
        // TODO(Yoav): Add the cost of allocating keys.
        get_da_gas_cost(&self.state_changes_for_fee.state_changes_count, use_kzg_da)

did we decide the allocation should be part of DA gas?
we show DA gas separately in the receipt, we want to charge for allocation but not necessarily make it show up as part of the DA gas vector
@Yoni-Starkware WDYT?

Code quote:

        // TODO(Yoav): Add the cost of allocating keys.
        get_da_gas_cost(&self.state_changes_for_fee.state_changes_count, use_kzg_da)

crates/blockifier/src/fee/receipt_test.rs line 0 at r1 (raw file):
any coverage benefit from making some of these values non-zero?
if so, please make some non-zero
(if tests fail: why?)


crates/blockifier/src/transaction/account_transactions_test.rs line 1385 at r1 (raw file):

            block_context.versioned_constants.enable_stateful_compression,
        )
        .state_changes_count;

why take this field, and not compare the entire object?

X3 (same Q twice below)

Code quote:

.state_changes_count

crates/blockifier/src/state/cached_state_test.rs line 351 at r1 (raw file):

            n_modified_contracts: 2,
        },
        n_allocated_keys: 0,

can you update create_state_changes_for_test to create some allocations and use some nonzero X here?

Suggestion:

n_allocated_keys: if enable_stateful_compression { X } else { 0 },

@yoavGrs yoavGrs force-pushed the yoav/compression/refactor_diff_of_cached_state branch from 539d545 to 4832a87 Compare November 19, 2024 15:43
@yoavGrs yoavGrs force-pushed the yoav/compression/state_changes_count_for_fee branch from 46a6da2 to 868b6b6 Compare November 19, 2024 15:43
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: 5 of 8 files reviewed, 9 unresolved discussions (waiting on @dorimedini-starkware)


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

Previously, dorimedini-starkware wrote…

any coverage benefit from making some of these values non-zero?
if so, please make some non-zero
(if tests fail: why?)

Done, where it makes sense.
Some tests will fail when we include the allocations in the gas computation.


crates/blockifier/src/state/cached_state.rs line 755 at r1 (raw file):

Previously, dorimedini-starkware wrote…

just to be clear: this field will be computed, regardless of the enable_stateful_compression flag, correct?

No.
Under a ForFee struct, this field will be 0 if not enable_stateful_compression.


crates/blockifier/src/state/cached_state_test.rs line 351 at r1 (raw file):

Previously, dorimedini-starkware wrote…

can you update create_state_changes_for_test to create some allocations and use some nonzero X here?

It will create allocations when we implement the allocation logic. Look at this test here:
https://reviewable.io/reviews/starkware-libs/sequencer/2150


crates/blockifier/src/transaction/account_transactions_test.rs line 1385 at r1 (raw file):

Previously, dorimedini-starkware wrote…

why take this field, and not compare the entire object?

X3 (same Q twice below)

Changing it.
I'll set the correct number of allocations when we implement the allocation logic (2150).


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

Previously, dorimedini-starkware wrote…

same as above: does it make sense to have nonzero values for n_allocations in this test?

No allocations in invoke return_result / declare tx.
This is the expected value.


crates/blockifier/src/state/cached_state.rs line 732 at r1 (raw file):

            },
            n_allocated_keys: if enable_stateful_compression {
                self.allocated_keys.count()

Sorry, moving this to the next PR.

Code quote:

self.allocated_keys.count()

Copy link

Artifacts upload triggered. View details here

Copy link

codecov bot commented Nov 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.70%. Comparing base (e3165c4) to head (99c2be9).
Report is 588 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2175       +/-   ##
===========================================
+ Coverage   40.10%   68.70%   +28.60%     
===========================================
  Files          26      108       +82     
  Lines        1895    13936    +12041     
  Branches     1895    13936    +12041     
===========================================
+ Hits          760     9575     +8815     
- Misses       1100     3950     +2850     
- Partials       35      411      +376     

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

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


crates/blockifier/src/state/cached_state.rs line 755 at r1 (raw file):

Previously, yoavGrs wrote…

No.
Under a ForFee struct, this field will be 0 if not enable_stateful_compression.

ah, right.
but the StateChanges will count this? just not the ForFee flavor?

@yoavGrs yoavGrs force-pushed the yoav/compression/refactor_diff_of_cached_state branch from 4832a87 to f799e59 Compare November 20, 2024 06:34
@yoavGrs yoavGrs force-pushed the yoav/compression/state_changes_count_for_fee branch from 868b6b6 to d7d90ca Compare November 20, 2024 06:34
Copy link

Artifacts upload triggered. View details here

Copy link
Collaborator

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


crates/blockifier/src/state/cached_state.rs line 731 at r1 (raw file):

Previously, dorimedini-starkware wrote…

hmmm... maybe this flag is a bit confusing...
I would expect enable_stateful_compression to indicate whether or not contract 0x2 appears in the state diff,
not whether or not we charge for allocations (which is what is happening here).
should we have two separate flags for this? @Yoni-Starkware

We should count the allocated keys here regardless of this flag - only charge according to it.
And yes, more readable to have two flags.

Copy link
Collaborator

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


crates/blockifier/src/state/cached_state.rs line 731 at r1 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

We should count the allocated keys here regardless of this flag - only charge according to it.
And yes, more readable to have two flags.

Even better - let the second config be the cost of an allocated key, and set it to 0 for old VCs. That way we save a flag.

Copy link
Collaborator

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


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

Previously, dorimedini-starkware wrote…

did we decide the allocation should be part of DA gas?
we show DA gas separately in the receipt, we want to charge for allocation but not necessarily make it show up as part of the DA gas vector
@Yoni-Starkware WDYT?

Hmmm yes but I don't want to split this part into another struct. And soon we will have L2 cost for state changes, so I think putting this under StateResources makes sense.

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 7 of 7 files at r3, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @yoavGrs)


crates/blockifier/src/fee/gas_usage_test.rs line 82 at r3 (raw file):

        },
        19,
>>>>>>> 868b6b68c (feat(blockifier): add struct StateChangesCountForFee)

oops

Code quote:

>>>>>>> 868b6b68c (feat(blockifier): add struct StateChangesCountForFee)

@yoavGrs yoavGrs changed the base branch from yoav/compression/refactor_diff_of_cached_state to graphite-base/2175 November 20, 2024 14:57
Copy link

Artifacts upload triggered. View details here

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: all files reviewed, 3 unresolved discussions (waiting on @yoavGrs)


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

Previously, Yoni-Starkware (Yoni) wrote…

Hmmm yes but I don't want to split this part into another struct. And soon we will have L2 cost for state changes, so I think putting this under StateResources makes sense.

unblocking here, but I'm saying that get_da_gas_cost should ignore allocations even in future PRs.
this function should return get_da_gas_cost(...).checked_add(get_allocations_gas_cost(...)).expect(...), so we can still use get_da_gas_cost to represent the cost of data availability (and not starknet state allocation costs)

@yoavGrs yoavGrs force-pushed the yoav/compression/state_changes_count_for_fee branch from d7d90ca to 3cf36e7 Compare November 25, 2024 13:58
@yoavGrs yoavGrs changed the base branch from graphite-base/2175 to main November 25, 2024 13:58
@yoavGrs yoavGrs force-pushed the yoav/compression/state_changes_count_for_fee branch from 3cf36e7 to bb121ba Compare November 25, 2024 15:07
@yoavGrs yoavGrs changed the base branch from main to yoav/compression/allocation_cost_constant November 25, 2024 15:07
Copy link
Collaborator

@Yoni-Starkware Yoni-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: 1 of 9 files reviewed, 4 unresolved discussions (waiting on @dorimedini-starkware and @yoavGrs)


crates/blockifier/src/state/cached_state.rs line 731 at r5 (raw file):

            },
            // TODO: Set number of allocated keys.
            n_allocated_keys: { 0 },

What's the plan?

Code quote:

            // TODO: Set number of allocated keys.
            n_allocated_keys: { 0 },

@yoavGrs yoavGrs force-pushed the yoav/compression/state_changes_count_for_fee branch from bb121ba to d3b22a0 Compare November 25, 2024 16:02
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 9 files reviewed, 4 unresolved discussions (waiting on @dorimedini-starkware)


crates/blockifier/src/fee/gas_usage_test.rs line 82 at r3 (raw file):

Previously, dorimedini-starkware wrote…

oops

:(


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

Previously, dorimedini-starkware wrote…

consider this rename, everywhere (see below - maybe a separate flag for stateful compression?)

removed.


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

Previously, dorimedini-starkware wrote…

unblocking here, but I'm saying that get_da_gas_cost should ignore allocations even in future PRs.
this function should return get_da_gas_cost(...).checked_add(get_allocations_gas_cost(...)).expect(...), so we can still use get_da_gas_cost to represent the cost of data availability (and not starknet state allocation costs)

👍


crates/blockifier/src/state/cached_state.rs line 731 at r1 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Even better - let the second config be the cost of an allocated key, and set it to 0 for old VCs. That way we save a flag.

https://reviewable.io/reviews/starkware-libs/sequencer/2200


crates/blockifier/src/state/cached_state.rs line 755 at r1 (raw file):

Previously, dorimedini-starkware wrote…

ah, right.
but the StateChanges will count this? just not the ForFee flavor?

Sorry, even in theForFee struct, the real amount will appear.

@yoavGrs yoavGrs force-pushed the yoav/compression/state_changes_count_for_fee branch from d3b22a0 to 391bf4b Compare November 26, 2024 09:10
@yoavGrs yoavGrs changed the base branch from yoav/compression/allocation_cost_constant to yoav/compression/allocated_keys_structure November 26, 2024 09:10
@yoavGrs yoavGrs force-pushed the yoav/compression/state_changes_count_for_fee branch from 391bf4b to 2838afb Compare November 26, 2024 09:16
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 9 files reviewed, 4 unresolved discussions (waiting on @dorimedini-starkware and @Yoni-Starkware)


crates/blockifier/src/state/cached_state.rs line 731 at r5 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

What's the plan?

I changed the order of the branches, and removed the TODO.

@yoavGrs yoavGrs force-pushed the yoav/compression/state_changes_count_for_fee branch from 2838afb to 2c19800 Compare November 26, 2024 09:17
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 1 of 4 files at r4, 1 of 6 files at r5, 4 of 5 files at r6, 2 of 2 files at r7, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Yoni-Starkware)


crates/blockifier/src/fee/resources.rs line 17 at r7 (raw file):

};
#[cfg(any(test, feature = "testing"))]
use crate::state::cached_state::StateChangesCount;

delete (see below)
non-blocking, it's a question of style

Code quote:

#[cfg(any(test, feature = "testing"))]
use crate::state::cached_state::StateChangesCount;

crates/blockifier/src/fee/resources.rs line 183 at r7 (raw file):

    ) -> Self {
        Self {
            state_changes_for_fee: StateChangesCountForFee {

I suggest this, looks better than gating the use (see above)

Suggestion:

state_changes_for_fee: crate::state::cached_state::StateChangesCountForFee

Copy link
Collaborator

@Yoni-Starkware Yoni-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, 1 of 6 files at r5, 1 of 5 files at r6, 1 of 2 files at r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @yoavGrs)

@yoavGrs yoavGrs force-pushed the yoav/compression/state_changes_count_for_fee branch from 2c19800 to 9a147b1 Compare November 26, 2024 10:18
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 r8, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @yoavGrs)

Copy link
Contributor Author

yoavGrs commented Nov 26, 2024

Merge activity

  • Nov 26, 5:53 AM EST: A user started a stack merge that includes this pull request via Graphite.
  • Nov 26, 6:15 AM EST: Graphite rebased this pull request as part of a merge.
  • Nov 26, 6:34 AM EST: A user merged this pull request with Graphite.

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/allocated_keys_structure to graphite-base/2175 November 26, 2024 10:54
@yoavGrs yoavGrs changed the base branch from graphite-base/2175 to main November 26, 2024 11:13
@yoavGrs yoavGrs force-pushed the yoav/compression/state_changes_count_for_fee branch from 9a147b1 to 99c2be9 Compare November 26, 2024 11:14
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 r9, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @yoavGrs)

@yoavGrs yoavGrs merged commit 2db8897 into main Nov 26, 2024
13 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 29, 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