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: refactor the stateful tx validator to get executable tx as input #519

Merged

Conversation

ArniStarkware
Copy link
Contributor

@ArniStarkware ArniStarkware commented Aug 19, 2024

In this PR we change the inputs for the run_validate method of the stateful validator. This also streamlines process+tx.

This change is Reviewable

Copy link
Contributor Author

ArniStarkware commented Aug 19, 2024

@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/remove_optional_class_info branch from fe7f892 to 74144ec Compare August 19, 2024 13:28
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/stateful_validator_interface branch 2 times, most recently from 8fd60c6 to 867299e Compare August 19, 2024 14:14
@ArniStarkware ArniStarkware changed the base branch from arni/executable_tx_in_gateway/remove_optional_class_info to arni/executable_tx_in_gateway/create_executable_tx August 19, 2024 14:14
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/create_executable_tx branch from 1bd225e to ef4229f Compare August 19, 2024 14:42
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/stateful_validator_interface branch from 867299e to c081dd8 Compare August 19, 2024 14:42
@ArniStarkware ArniStarkware marked this pull request as ready for review August 19, 2024 14:47
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/create_executable_tx branch from ef4229f to eac85a8 Compare August 20, 2024 11:43
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/stateful_validator_interface branch from c081dd8 to 7dcaf90 Compare August 20, 2024 11:43
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/create_executable_tx branch from eac85a8 to 9c0e1fa Compare August 20, 2024 12:34
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/stateful_validator_interface branch from 7dcaf90 to 35f5961 Compare August 20, 2024 12:34
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/create_executable_tx branch from 9c0e1fa to cf3cdac Compare August 20, 2024 14:04
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/stateful_validator_interface branch from 35f5961 to 4b460e4 Compare August 20, 2024 14:04
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/create_executable_tx branch from cf3cdac to b056be0 Compare August 21, 2024 06:58
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/stateful_validator_interface branch from 4b460e4 to cc0e749 Compare August 21, 2024 06:59
Copy link
Collaborator

@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 2 of 5 files at r1, 3 of 3 files at r2, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @ArniStarkware, @ayeletstarkware, @MohammadNassar1, and @yair-starkware)


crates/gateway/src/stateful_transaction_validator.rs line 77 at r2 (raw file):

        mut validator: V,
    ) -> StatefulTransactionValidatorResult<ValidateInfo> {
        let account_tx = AccountTransaction::try_from(executable_tx.clone()).map_err(|error| {

Why the clone here? Can't AccountTransaction::try_from get a reference?

Code quote:

executable_tx.clone()

crates/gateway/src/stateful_transaction_validator.rs line 78 at r2 (raw file):

    ) -> StatefulTransactionValidatorResult<ValidateInfo> {
        let account_tx = AccountTransaction::try_from(executable_tx.clone()).map_err(|error| {
            error!("Failed to executable transaction into account transaction: {}", error);

Suggestion:

Failed to convert executable transaction into account transaction: {}

crates/gateway/src/stateful_transaction_validator_test.rs line 81 at r2 (raw file):

#[case::invalid_tx(invoke_tx(CairoVersion::Cairo1), Err(STATEFUL_VALIDATOR_FEE_ERROR))]
fn test_stateful_tx_validator(
    #[case] external_tx: RpcTransaction,

I think the test should start with an executable tx, and not do any conversion, and especially not compile anything.

Code quote:

#[case] external_tx: RpcTransaction,

@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/create_executable_tx branch from b056be0 to c993729 Compare August 21, 2024 09:16
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/stateful_validator_interface branch from cc0e749 to 98da56f Compare August 21, 2024 09:16
@ArniStarkware
Copy link
Contributor Author

crates/gateway/src/stateful_transaction_validator.rs line 78 at r2 (raw file):

    ) -> StatefulTransactionValidatorResult<ValidateInfo> {
        let account_tx = AccountTransaction::try_from(executable_tx.clone()).map_err(|error| {
            error!("Failed to executable transaction into account transaction: {}", error);

Done.

Copy link
Contributor Author

@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: 4 of 10 files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware, @dafnamatsry, @MohammadNassar1, and @yair-starkware)


crates/gateway/src/gateway_test.rs line 161 at r8 (raw file):

Previously, dafnamatsry wrote…

Can you explain?

No. I would rather delete this function :)

This was a test util that should be deprecated.
Let us update the test.

Copy link
Contributor Author

@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: 4 of 10 files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware, @dafnamatsry, @MohammadNassar1, and @yair-starkware)


crates/gateway/src/stateful_transaction_validator_test.rs line 67 at r9 (raw file):

    executable_invoke_tx(CairoVersion::Cairo1),
    Ok(ValidateInfo{
        tx_hash: TransactionHash::default(),

This is not the subject of this test.
This value is deleted in #521.

Code quote:

        tx_hash: TransactionHash::default(),

@ArniStarkware
Copy link
Contributor Author

crates/gateway/src/gateway_test.rs line 161 at r8 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

No. I would rather delete this function :)

This was a test util that should be deprecated.
Let us update the test.

The original thread was about a test util called rpc_tx_to_account_tx that first appeared in r4 of this review session.
A new design of the code makes this code obsolete.

@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/stateful_validator_interface branch 2 times, most recently from 176981b to b4e640f Compare September 15, 2024 07:42
Copy link
Contributor

@yair-starkware yair-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 6 files at r7, 3 of 8 files at r8, 5 of 5 files at r11, all commit messages.
Reviewable status: 9 of 10 files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware, @dafnamatsry, and @MohammadNassar1)

Copy link
Contributor Author

@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: 9 of 10 files reviewed, 2 unresolved discussions (waiting on @ayeletstarkware, @dafnamatsry, and @MohammadNassar1)

a discussion (no related file):
In this PR we change the


Copy link
Contributor Author

@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: 9 of 10 files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware, @dafnamatsry, and @MohammadNassar1)

a discussion (no related file):
The original goal of this PR was to refactor the stateful tx validator so that it receives an executable transaction as input.
Another goal achieved is that the proper executable transaction is now used as the mempool input. This change occurred to address issues with the gateway_test: test_add_tx. In the meantime we also cleaned some test utils for this test and for the stateful validator test.


Copy link
Collaborator

@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 4 of 5 files at r12, 5 of 5 files at r13, all commit messages.
Reviewable status: 9 of 10 files reviewed, all discussions resolved (waiting on @ayeletstarkware and @MohammadNassar1)

@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/stateful_validator_interface branch from 811ebb9 to f159d01 Compare September 18, 2024 06:56
@ArniStarkware
Copy link
Contributor Author

crates/gateway/src/gateway_test.rs line 86 at r13 (raw file):

    let response_bytes = &to_bytes(response).await;

    assert_eq!(status_code, StatusCode::OK, "{response_bytes:?}");

The base changed before this PR in #837

Code quote:

    let response = add_tx(State(app_state), rpc_tx.into()).await.into_response();

    let status_code = response.status();
    let response_bytes = &to_bytes(response).await;

    assert_eq!(status_code, StatusCode::OK, "{response_bytes:?}");

@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/stateful_validator_interface branch 3 times, most recently from 728fd16 to c4e9a61 Compare September 18, 2024 07:54
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/stateful_validator_interface branch from c4e9a61 to ae9880e Compare September 18, 2024 12:28
Copy link
Collaborator

@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 1 of 7 files at r14, 1 of 6 files at r16, 5 of 5 files at r17, all commit messages.
Reviewable status: 9 of 10 files reviewed, all discussions resolved (waiting on @ayeletstarkware and @MohammadNassar1)

Copy link
Collaborator

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

Reviewable status: 9 of 10 files reviewed, all discussions resolved (waiting on @ayeletstarkware and @MohammadNassar1)

Copy link
Contributor Author

@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 8 files at r8.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ayeletstarkware and @MohammadNassar1)

@ArniStarkware ArniStarkware merged commit c7f9b7a into main Sep 19, 2024
14 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 20, 2024
@ArniStarkware ArniStarkware deleted the arni/executable_tx_in_gateway/stateful_validator_interface branch September 22, 2024 11:35
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