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

refactor: move skip validation check to py_validator #2013

Merged
merged 1 commit into from
Jul 3, 2024

Conversation

Yael-Starkware
Copy link
Contributor

@Yael-Starkware Yael-Starkware commented Jun 30, 2024

This change is Reviewable

@codecov-commenter
Copy link

codecov-commenter commented Jun 30, 2024

Codecov Report

Attention: Patch coverage is 7.50000% with 37 lines in your changes missing coverage. Please review.

Project coverage is 79.89%. Comparing base (73c3821) to head (295492c).
Report is 39 commits behind head on main.

Files Patch % Lines
crates/native_blockifier/src/py_validator.rs 0.00% 26 Missing ⚠️
...es/blockifier/src/blockifier/stateful_validator.rs 21.42% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2013      +/-   ##
==========================================
- Coverage   80.17%   79.89%   -0.28%     
==========================================
  Files          69       69              
  Lines        9739     9739              
  Branches     9739     9739              
==========================================
- Hits         7808     7781      -27     
- Misses       1471     1501      +30     
+ Partials      460      457       -3     

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

Copy link
Contributor Author

@Yael-Starkware Yael-Starkware left a comment

Choose a reason for hiding this comment

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

python PR for CI testing:
https://github.com/starkware-industries/starkware/pull/35347

Reviewable status: 0 of 3 files reviewed, all discussions resolved

Copy link
Contributor Author

@Yael-Starkware Yael-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


-- commits line 2 at r1:
blocking until python tests run and pass

@ArniStarkware
Copy link
Contributor

-- commits line 2 at r1:

Previously, Yael-Starkware (YaelD) wrote…

blocking until python tests run and pass

link?

Copy link
Contributor

@ArniStarkware ArniStarkware 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 3 files at r1.
Reviewable status: 2 of 3 files reviewed, 2 unresolved discussions (waiting on @dafnamatsry, @Yael-Starkware, and @Yoni-Starkware)


crates/blockifier/src/blockifier/stateful_validator_test.rs line 0 at r1 (raw file):
A test that checks the skip_validate functionality is missing (And many more tests TBH).


crates/native_blockifier/src/py_validator.rs line 79 at r1 (raw file):

                    deploy_account_tx_hash,
                )?;
        }

Suggestion:

        let skip_validate = if let AccountTransaction::Invoke(tx) = &account_tx {
                self.stateful_validator.skip_validate_due_to_unprocessed_deploy_account(
                    tx.tx.sender_address(),
                    tx.tx.nonce(),
                    deploy_account_tx_hash,
                )?
        } else {false}

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: 2 of 3 files reviewed, 3 unresolved discussions (waiting on @dafnamatsry and @Yael-Starkware)


crates/native_blockifier/src/py_validator.rs line 76 at r1 (raw file):

                self.stateful_validator.skip_validate_due_to_unprocessed_deploy_account(
                    tx.tx.sender_address(),
                    tx.tx.nonce(),

Can you avoid using the raw python tx?

Suggestion:

                    &account_tx.create_tx_info(),

@Yael-Starkware Yael-Starkware force-pushed the yael/refactor_stateful_validations branch from b79bff8 to 6715494 Compare July 1, 2024 09:21
Copy link
Contributor Author

@Yael-Starkware Yael-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 3 files reviewed, 2 unresolved discussions (waiting on @ArniStarkware and @dafnamatsry)


-- commits line 2 at r1:

Previously, ArniStarkware (Arnon Hod) wrote…

link?

was state at the top :
https://reviewable.io/reviews/starkware-industries/starkware/35347


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

Previously, ArniStarkware (Arnon Hod) wrote…

A test that checks the skip_validate functionality is missing (And many more tests TBH).

added a test, done


crates/native_blockifier/src/py_validator.rs line 76 at r1 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Can you avoid using the raw python tx?

done


crates/native_blockifier/src/py_validator.rs line 79 at r1 (raw file):

                    deploy_account_tx_hash,
                )?;
        }

done.

Copy link
Contributor

@dafnamatsry dafnamatsry 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 3 files reviewed, 5 unresolved discussions (waiting on @ArniStarkware, @Yael-Starkware, and @Yoni-Starkware)


crates/blockifier/src/blockifier/stateful_validator.rs line 117 at r2 (raw file):

    // `__validate__` method for subsequent transactions for a better user experience.
    // (they will otherwise fail solely because the deploy account hasn't been processed yet).
    pub fn skip_validate_due_to_unprocessed_deploy_account(

I would move this logic as well to py_validator.

Code quote:

pub fn skip_validate_due_to_unprocessed_deploy_account(

crates/blockifier/src/blockifier/stateful_validator.rs line 120 at r2 (raw file):

        &mut self,
        sender_address: ContractAddress,
        tx_nonce: Nonce,

Consider passing AccountTrnasaction, and check that this is Invoke here

Code quote:

        sender_address: ContractAddress,
        tx_nonce: Nonce,

crates/native_blockifier/src/py_validator.rs line 71 at r2 (raw file):

        let deploy_account_tx_hash = deploy_account_tx_hash.map(|hash| TransactionHash(hash.0));
        // We check if the transaction should be skipped due to the deploy account not being
        // processed.

Suggestion:

        let deploy_account_tx_hash = deploy_account_tx_hash.map(|hash| TransactionHash(hash.0));
        
        // We check if the transaction should be skipped due to the deploy account not being
        // processed.

@Yael-Starkware Yael-Starkware force-pushed the yael/refactor_stateful_validations branch from 6715494 to 6430958 Compare July 1, 2024 11:33
Copy link
Contributor Author

@Yael-Starkware Yael-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, 5 unresolved discussions (waiting on @ArniStarkware, @dafnamatsry, and @Yoni-Starkware)


crates/blockifier/src/blockifier/stateful_validator.rs line 117 at r2 (raw file):

Previously, dafnamatsry wrote…

I would move this logic as well to py_validator.

I tried but this function is touching private fields of stateful_validator so I can't use it outside of the crate. I think it also makes sense logically to keep it there because it exposes the implementation details of the stateful validator.


crates/blockifier/src/blockifier/stateful_validator.rs line 120 at r2 (raw file):

Previously, dafnamatsry wrote…

Consider passing AccountTrnasaction, and check that this is Invoke here

done


crates/native_blockifier/src/py_validator.rs line 71 at r2 (raw file):

        let deploy_account_tx_hash = deploy_account_tx_hash.map(|hash| TransactionHash(hash.0));
        // We check if the transaction should be skipped due to the deploy account not being
        // processed.

Done.

Copy link
Contributor

@ArniStarkware ArniStarkware 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, 7 unresolved discussions (waiting on @dafnamatsry, @Yael-Starkware, and @Yoni-Starkware)


-- commits line 2 at r1:

Previously, Yael-Starkware (YaelD) wrote…

was state at the top :
https://reviewable.io/reviews/starkware-industries/starkware/35347

tnx.


crates/blockifier/src/blockifier/stateful_validator_test.rs line 91 at r3 (raw file):

        scenario: INVALID,
        ..transaction_args
    });

Suggestion:

    // Create a transaction that does not pass validations.
    let tx = create_account_tx_for_validate_test_nonce_0(FaultyAccountTxCreatorArgs {
        scenario: INVALID,
        tx_type: TransactionType::InvokeFunction,
        tx_version: TransactionVersion::THREE,
        sender_address: faulty_account.get_instance_address(0),
        class_hash: faulty_account.get_class_hash(),
        max_fee: Fee(BALANCE),
        ..Default::default()
    });

crates/blockifier/src/blockifier/stateful_validator_test.rs line 95 at r3 (raw file):

    let mut stateful_validator = StatefulValidator::create(state, block_context, nonce!(0_u32));
    // The transaction validations should be skipped and the function should return Ok.
    let result = stateful_validator.perform_validations(tx, true);

Suggestion:

    // The transaction validations should be skipped and the function should return Ok.
    let skip_validate = true;
    let result = stateful_validator.perform_validations(tx, skip_validate);

crates/blockifier/src/blockifier/stateful_validator_test.rs line 96 at r3 (raw file):

    // The transaction validations should be skipped and the function should return Ok.
    let result = stateful_validator.perform_validations(tx, true);
    assert!(result.is_ok());

Better error representation.
(If the test fails, it will print out why it failed).

Suggestion:

assert_matches!(result, Ok());

@Yael-Starkware Yael-Starkware force-pushed the yael/refactor_stateful_validations branch from 3142af1 to f8692a1 Compare July 1, 2024 12:08
Copy link
Contributor Author

@Yael-Starkware Yael-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, 6 unresolved discussions (waiting on @ArniStarkware, @dafnamatsry, and @Yoni-Starkware)


crates/blockifier/src/blockifier/stateful_validator_test.rs line 91 at r3 (raw file):

        scenario: INVALID,
        ..transaction_args
    });

Done.


crates/blockifier/src/blockifier/stateful_validator_test.rs line 95 at r3 (raw file):

    let mut stateful_validator = StatefulValidator::create(state, block_context, nonce!(0_u32));
    // The transaction validations should be skipped and the function should return Ok.
    let result = stateful_validator.perform_validations(tx, true);

Done.


crates/blockifier/src/blockifier/stateful_validator_test.rs line 96 at r3 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

Better error representation.
(If the test fails, it will print out why it failed).

Done.

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: 0 of 3 files reviewed, 6 unresolved discussions (waiting on @ArniStarkware and @dafnamatsry)


crates/blockifier/src/blockifier/stateful_validator.rs line 117 at r2 (raw file):

Previously, Yael-Starkware (YaelD) wrote…

I tried but this function is touching private fields of stateful_validator so I can't use it outside of the crate. I think it also makes sense logically to keep it there because it exposes the implementation details of the stateful validator.

You can move max_nonce_for_validation_skip (also not related to the rust class) and expose justget_nonce

Copy link
Contributor

@ArniStarkware ArniStarkware 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 r4.
Reviewable status: 1 of 3 files reviewed, 3 unresolved discussions (waiting on @dafnamatsry)

ArniStarkware
ArniStarkware previously approved these changes Jul 1, 2024
Copy link
Contributor

@ArniStarkware ArniStarkware 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: 1 of 3 files reviewed, 3 unresolved discussions (waiting on @dafnamatsry)

Copy link
Contributor

@dafnamatsry dafnamatsry 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: 1 of 3 files reviewed, 3 unresolved discussions (waiting on @ArniStarkware, @Yael-Starkware, and @Yoni-Starkware)


crates/blockifier/src/blockifier/stateful_validator.rs line 117 at r2 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

You can move max_nonce_for_validation_skip (also not related to the rust class) and expose justget_nonce

+1 to Yoni's suggestion.


crates/blockifier/src/blockifier/stateful_validator.rs line 122 at r4 (raw file):

        account_tx: &AccountTransaction,
        sender_address: ContractAddress,
        tx_nonce: Nonce,

Can these be extracted from account_tx?

Code quote:

        sender_address: ContractAddress,
        tx_nonce: Nonce,

Copy link
Contributor Author

@Yael-Starkware Yael-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 @ArniStarkware, @dafnamatsry, and @Yoni-Starkware)


crates/blockifier/src/blockifier/stateful_validator.rs line 117 at r2 (raw file):

Previously, dafnamatsry wrote…

+1 to Yoni's suggestion.

indeed looks better now.
Done.


crates/blockifier/src/blockifier/stateful_validator.rs line 122 at r4 (raw file):

Previously, dafnamatsry wrote…

Can these be extracted from account_tx?

Done.

Copy link
Contributor

@dafnamatsry dafnamatsry 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, 2 unresolved discussions (waiting on @Yael-Starkware)


crates/blockifier/src/blockifier/stateful_validator.rs line 151 at r5 (raw file):

            .expect(BLOCK_STATE_ACCESS_ERR)
            .get_nonce_at(account_address)?;
        Ok(nonce)

A bit cleaner. non-blocking...

Suggestion:

        self
            .tx_executor
            .block_state
            .as_ref()
            .expect(BLOCK_STATE_ACCESS_ERR)
            .get_nonce_at(account_address);

crates/blockifier/src/blockifier/stateful_validator_test.rs line 95 at r3 (raw file):

Previously, Yael-Starkware (YaelD) wrote…

Done.

Not critical at all, but IMO the original was better. VSCode does the job of showing the names of the arguments for us.


crates/native_blockifier/src/py_validator.rs line 90 at r5 (raw file):

// (they will otherwise fail solely because the deploy account hasn't been processed yet).
pub fn skip_validate_due_to_unprocessed_deploy_account(
    py_validator: &mut PyValidator,

You can define it as a method of PyValidator, and pass self instead.

Code quote:

py_validator: &mut PyValidator,

Copy link
Contributor Author

@Yael-Starkware Yael-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 @dafnamatsry)


crates/blockifier/src/blockifier/stateful_validator.rs line 151 at r5 (raw file):

Previously, dafnamatsry wrote…

A bit cleaner. non-blocking...

it doesn't work because the error type is different between the value returned from get_nonce_at and get_nonce. Wrapping it with Ok does the job.
Done.


crates/blockifier/src/blockifier/stateful_validator_test.rs line 95 at r3 (raw file):

Previously, dafnamatsry wrote…

Not critical at all, but IMO the original was better. VSCode does the job of showing the names of the arguments for us.

Done.


crates/native_blockifier/src/py_validator.rs line 90 at r5 (raw file):

Previously, dafnamatsry wrote…

You can define it as a method of PyValidator, and pass self instead.

originally that was what I did and it didn't compile because of the #[pyclass] requirement.

But here since you insisted I found a suitable solution, put in in a different impl clause.

@Yael-Starkware Yael-Starkware force-pushed the yael/refactor_stateful_validations branch from 952ce7f to 295492c Compare July 2, 2024 12:43
Copy link
Contributor

@dafnamatsry dafnamatsry 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 3 of 3 files at r6, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Yael-Starkware)


crates/native_blockifier/src/py_validator.rs line 90 at r5 (raw file):

Previously, Yael-Starkware (YaelD) wrote…

originally that was what I did and it didn't compile because of the #[pyclass] requirement.

But here since you insisted I found a suitable solution, put in in a different impl clause.

Nice!

dafnamatsry
dafnamatsry previously approved these changes Jul 3, 2024
Copy link
Contributor

@dafnamatsry dafnamatsry 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 @Yael-Starkware)

Copy link
Contributor

@dafnamatsry dafnamatsry 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 r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @Yael-Starkware)

@Yael-Starkware Yael-Starkware merged commit bad24f2 into main Jul 3, 2024
10 checks passed
@Yael-Starkware Yael-Starkware deleted the yael/refactor_stateful_validations branch July 3, 2024 08:25
Yael-Starkware added a commit that referenced this pull request Jul 3, 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.

5 participants