Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

fix(concurrency): add the sequencer key when checking if the tx is #1980

Merged

Conversation

meship-starkware
Copy link
Contributor

@meship-starkware meship-starkware commented Jun 13, 2024

too big in concurrency mode


This change is Reviewable

@codecov-commenter
Copy link

codecov-commenter commented Jun 13, 2024

Codecov Report

Attention: Patch coverage is 89.28571% with 3 lines in your changes missing coverage. Please review.

Project coverage is 78.85%. Comparing base (6e06e79) to head (2bdfae7).
Report is 6 commits behind head on main.

Files Patch % Lines
.../blockifier/src/transaction/account_transaction.rs 50.00% 0 Missing and 2 partials ⚠️
...lockifier/src/transaction/transaction_execution.rs 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1980      +/-   ##
==========================================
+ Coverage   78.42%   78.85%   +0.42%     
==========================================
  Files          62       62              
  Lines        8913     9031     +118     
  Branches     8913     9031     +118     
==========================================
+ Hits         6990     7121     +131     
+ Misses       1476     1460      -16     
- Partials      447      450       +3     

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

Copy link
Contributor Author

@meship-starkware meship-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 3 files reviewed, 1 unresolved discussion (waiting on @avi-starkware and @noaov1)


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

pub struct StateChangesKeys {
    nonce_keys: HashSet<ContractAddress>,
    class_hash_keys: HashSet<ContractAddress>,

Im not sure changing this filed to pub(crate) is the right solution to add the sequencer balance key to the storage keys.

@meship-starkware meship-starkware removed the request for review from avi-starkware June 13, 2024 11:11
@meship-starkware meship-starkware changed the title fix(concurrency): add the sequencer key when checking if the tx is fix(concurrency): add the sequencer key when checking if the tx is Jun 13, 2024
@meship-starkware meship-starkware force-pushed the meship/fix_conncurent_mode_transaction_to_big branch from c26ebfb to 8a62cbc Compare June 13, 2024 13:27
Copy link
Contributor Author

@meship-starkware meship-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 3 files reviewed, 2 unresolved discussions (waiting on @avi-starkware, @noaov1, and @Yoni-Starkware)


crates/blockifier/src/concurrency/worker_logic.rs line 225 at r1 (raw file):

        let mut execution_output = lock_mutex_in_array(&self.execution_outputs, tx_index);
        let writes = &execution_output.as_ref().expect(EXECUTION_OUTPUTS_UNWRAP_ERROR).writes;
        let reads = &execution_output.as_ref().expect(EXECUTION_OUTPUTS_UNWRAP_ERROR).reads;

It might be better to fix the sequencer balance before checking if it has a place in the bouncer. We just need to ensure that if the transaction fails because it has no space, we won't need to revert this change.

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: 0 of 3 files reviewed, 3 unresolved discussions (waiting on @avi-starkware, @meship-starkware, and @noaov1)


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

Previously, meship-starkware (Meshi Peled) wrote…

Im not sure changing this filed to pub(crate) is the right solution to add the sequencer balance key to the storage keys.

Instead, create a StateChangesKeys object and use extend


crates/blockifier/src/transaction/transaction_execution.rs line 192 at r2 (raw file):

                .storage_keys
                .insert((tx_context.fee_token_address(), sequencer_balance_low));
        }

Share code with the worker logic.

Code quote:

        if block_context.concurrency_mode
            && block_context.block_info.sequencer_address != tx_context.tx_info.sender_address()
        {
            // Add the deleted sequencer balance key to the storage keys.
            let sequencer_balance_low =
                get_fee_token_var_address(block_context.block_info.sequencer_address);
            tx_state_changes_keys
                .storage_keys
                .insert((tx_context.fee_token_address(), sequencer_balance_low));
        }

@meship-starkware meship-starkware force-pushed the meship/fix_conncurent_mode_transaction_to_big branch from 8a62cbc to e22013f Compare June 16, 2024 08:03
Copy link
Contributor Author

@meship-starkware meship-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 3 files reviewed, 3 unresolved discussions (waiting on @avi-starkware, @noaov1, and @Yoni-Starkware)


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

Previously, Yoni-Starkware (Yoni) wrote…

Instead, create a StateChangesKeys object and use extend

I tried using Extend by creating a new StateChangesKeys and using StateChangesKeys::default(), but it told me that I couldn't use the default because the fields are private.

Copy link
Contributor Author

@meship-starkware meship-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 3 files reviewed, 3 unresolved discussions (waiting on @avi-starkware, @noaov1, and @Yoni-Starkware)


crates/blockifier/src/transaction/transaction_execution.rs line 192 at r2 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Share code with the worker logic.

Done.

@meship-starkware meship-starkware force-pushed the meship/fix_conncurent_mode_transaction_to_big branch from e22013f to 6f1fc43 Compare June 16, 2024 10:34
@avi-starkware
Copy link
Collaborator

crates/blockifier/src/state/cached_state.rs line 623 at r3 (raw file):

    pub fn update_sequencer_key_in_storage(&mut self, tx_context: &TransactionContext) {
        let seqencer_address = tx_context.block_context.block_info.sequencer_address;
        let seqencer_is_sender = seqencer_address == tx_context.tx_info.sender_address();

Suggestion:

        let sequencer_address = tx_context.block_context.block_info.sequencer_address;
        let sequencer_is_sender = sequencer_address == tx_context.tx_info.sender_address();

Copy link
Collaborator

@avi-starkware avi-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 r3, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @meship-starkware, @noaov1, and @Yoni-Starkware)

@meship-starkware meship-starkware force-pushed the meship/fix_conncurent_mode_transaction_to_big branch from 6f1fc43 to 6416548 Compare June 16, 2024 10:59
Copy link
Contributor Author

@meship-starkware meship-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: 2 of 3 files reviewed, 4 unresolved discussions (waiting on @avi-starkware, @noaov1, and @Yoni-Starkware)


crates/blockifier/src/state/cached_state.rs line 623 at r3 (raw file):

    pub fn update_sequencer_key_in_storage(&mut self, tx_context: &TransactionContext) {
        let seqencer_address = tx_context.block_context.block_info.sequencer_address;
        let seqencer_is_sender = seqencer_address == tx_context.tx_info.sender_address();

Done.

avi-starkware
avi-starkware previously approved these changes Jun 16, 2024
Copy link
Collaborator

@avi-starkware avi-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 1 files at r4, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @noaov1 and @Yoni-Starkware)

@meship-starkware meship-starkware changed the title fix(concurrency): add the sequencer key when checking if the tx is fix(concurrency): add the sequencer key when checking if the tx i Jun 16, 2024
@meship-starkware meship-starkware changed the title fix(concurrency): add the sequencer key when checking if the tx i fix(concurrency): add the sequencer key when checking if the tx is Jun 16, 2024
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 all commit messages.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @meship-starkware and @noaov1)


crates/blockifier/src/state/cached_state.rs line 621 at r4 (raw file):

    }

    pub fn update_sequencer_key_in_storage(&mut self, tx_context: &TransactionContext) {

Pass the fee, and add the key only if the fee is greater than zero

Code quote:

 pub fn update_sequencer_key_in_storage(&mut self, tx_context: &TransactionContext) 

crates/blockifier/src/state/cached_state.rs line 623 at r4 (raw file):

    pub fn update_sequencer_key_in_storage(&mut self, tx_context: &TransactionContext) {
        let sequencer_address = tx_context.block_context.block_info.sequencer_address;
        let sequencer_is_sender = sequencer_address == tx_context.tx_info.sender_address();

Move this check to be a function of tx_context, and use it here and in other places if there are

Code quote:

sequencer_address == tx_context.tx_info.sender_address()

crates/blockifier/src/state/cached_state.rs line 625 at r4 (raw file):

        let sequencer_is_sender = sequencer_address == tx_context.tx_info.sender_address();
        // Checks if we run in concurrency mode.
        if tx_context.block_context.concurrency_mode && !sequencer_is_sender {

Comments are written in ציווי. Anyway, the comment does not help here.

Suggestion:

        if tx_context.block_context.concurrency_mode && !sequencer_is_sender {

crates/blockifier/src/transaction/transaction_execution.rs line 180 at r4 (raw file):

        let tx_execution_summary = tx_execution_info.summarize();
        let mut tx_state_changes_keys = state.get_actual_state_changes()?.into_keys();
        tx_state_changes_keys.update_sequencer_key_in_storage(&tx_context);

Suggestion:

        // types, since now running Transaction::execute_raw is not identical to
        // AccountTransaction::execute_raw.
        let tx_execution_info = match self {
            Self::AccountTransaction(account_tx) => {
                account_tx.execute_raw(state, block_context, charge_fee, validate)?
            }
            Self::L1HandlerTransaction(tx) => {
                tx.execute_raw(state, block_context, charge_fee, validate)?
            }
        };

        // Check if the transaction is too large to fit any block.
        // TODO(Yoni, 1/8/2024): consider caching these two.
        let tx_execution_summary = tx_execution_info.summarize();
        let mut tx_state_changes_keys = state.get_actual_state_changes()?.into_keys();
        tx_state_changes_keys.update_sequencer_key_in_storage(&block_context.to_tx_context(self));

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: all files reviewed, 6 unresolved discussions (waiting on @meship-starkware and @noaov1)


crates/blockifier/src/state/cached_state.rs line 621 at r4 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Pass the fee, and add the key only if the fee is greater than zero

Or the execution result, whatever is more convenient

Yoni-Starkware
Yoni-Starkware previously approved these changes Jun 17, 2024
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.

:lgtm:

Reviewed 5 of 5 files at r5, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @meship-starkware and @noaov1)


crates/blockifier/src/context.rs line 21 at r5 (raw file):

        self.block_context.chain_info.fee_token_address(&self.tx_info.fee_type())
    }
    pub fn sequencer_is_the_sender(&self) -> bool {

Suggestion:

is_sequencer_the_sender

@meship-starkware meship-starkware force-pushed the meship/fix_conncurent_mode_transaction_to_big branch from f5f75cf to 8f0bc0b Compare June 17, 2024 11:27
Copy link
Contributor Author

@meship-starkware meship-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 5 files reviewed, all discussions resolved (waiting on @noaov1 and @Yoni-Starkware)


crates/blockifier/src/state/cached_state.rs line 621 at r4 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Or the execution result, whatever is more convenient

Done.


crates/blockifier/src/state/cached_state.rs line 623 at r4 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Move this check to be a function of tx_context, and use it here and in other places if there are

Done.


crates/blockifier/src/state/cached_state.rs line 625 at r4 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Comments are written in ציווי. Anyway, the comment does not help here.

Done.


crates/blockifier/src/transaction/transaction_execution.rs line 180 at r4 (raw file):

        let tx_execution_summary = tx_execution_info.summarize();
        let mut tx_state_changes_keys = state.get_actual_state_changes()?.into_keys();
        tx_state_changes_keys.update_sequencer_key_in_storage(&tx_context);

Done.

Yoni-Starkware
Yoni-Starkware previously approved these changes Jun 17, 2024
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.

:lgtm:

Reviewed 4 of 4 files at r6, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @noaov1)

noaov1
noaov1 previously approved these changes Jun 17, 2024
Copy link
Collaborator

@noaov1 noaov1 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 @meship-starkware)


crates/blockifier/src/concurrency/worker_logic.rs line 252 at r6 (raw file):

            // Update the sequencer balance (in state + call info).
            if tx_context.tx_info.sender_address()
                == self.block_context.block_info.sequencer_address

Suggestion:

            if tx_context.is_sequencer_the_sender()

Copy link
Collaborator

@noaov1 noaov1 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 @meship-starkware)


crates/blockifier/src/concurrency/worker_logic.rs line 252 at r6 (raw file):

            // Update the sequencer balance (in state + call info).
            if tx_context.tx_info.sender_address()
                == self.block_context.block_info.sequencer_address

Do we want to add fee == 0 here as well?

@meship-starkware meship-starkware force-pushed the meship/fix_conncurent_mode_transaction_to_big branch from 8f0bc0b to 758f364 Compare June 17, 2024 14:08
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: 4 of 5 files reviewed, all discussions resolved (waiting on @meship-starkware)


crates/blockifier/src/concurrency/worker_logic.rs line 252 at r6 (raw file):

Previously, noaov1 (Noa Oved) wrote…

Do we want to add fee == 0 here as well?

Better not to. You assume that fee==0 -> no fee transfer

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: 4 of 5 files reviewed, all discussions resolved (waiting on @meship-starkware)


crates/blockifier/src/concurrency/worker_logic.rs line 252 at r6 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Better not to. You assume that fee==0 -> no fee transfer

Which is true now but we gain nothing from this extra assumption here

@meship-starkware meship-starkware force-pushed the meship/fix_conncurent_mode_transaction_to_big branch from 758f364 to 2bdfae7 Compare June 17, 2024 14:25
Copy link
Collaborator

@noaov1 noaov1 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: 4 of 5 files reviewed, all discussions resolved (waiting on @Yoni-Starkware)


crates/blockifier/src/concurrency/worker_logic.rs line 252 at r6 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Which is true now but we gain nothing from this extra assumption here

We will add the sequencer balance keys to the call info storage read values

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.

:lgtm:

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

@meship-starkware meship-starkware merged commit 4a674cc into main Jun 17, 2024
9 checks passed
@meship-starkware meship-starkware deleted the meship/fix_conncurent_mode_transaction_to_big branch June 17, 2024 15:27
gswirski pushed a commit to reilabs/blockifier that referenced this pull request Jun 26, 2024
# Description

<!--
A description of what this PR is solving.
-->

## Related issue

<!--
Please link related issues: Fixes #<issue_number>
More info: https://docs.github.com/en/free-pro-team@latest/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword
-->

## Tests

<!--
Please refer to the CONTRIBUTING.md file to know more about the testing process. Ensure you've tested at least the package you're modifying if running all the tests consumes too much memory on your system.
-->

- [ ] Yes
- [x] No, because they aren't needed
- [ ] No, because I need help

## Added to documentation?

<!--
If the changes are small, code comments are enough, otherwise, the documentation is needed. It
may be a README.md file added to your module/package, a DojoBook PR or both.
-->

- [ ] README.md
- [ ] [Dojo Book](https://github.com/dojoengine/book)
- [x] No documentation needed

## Checklist

- [x] I've formatted my code (`scripts/prettier.sh`, `scripts/rust_fmt.sh`, `scripts/cairo_fmt.sh`)
- [ ] I've linted my code (`scripts/clippy.sh`, `scripts/docs.sh`)
- [x] I've commented my code
- [ ] I've requested a review after addressing the comments
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.

5 participants