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: create executable tx in the gateway process_tx #517

Merged

Conversation

ArniStarkware
Copy link
Contributor

@ArniStarkware ArniStarkware commented Aug 19, 2024

In this PR we create the executable_tx. This will be a member of MempoolInput.

This change is Reviewable

Copy link
Contributor Author

ArniStarkware commented Aug 19, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @ArniStarkware and the rest of your teammates on Graphite Graphite

@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/create_executable_tx branch from 528f847 to 1bd225e Compare August 19, 2024 13:28
@ArniStarkware
Copy link
Contributor Author

crates/gateway/src/gateway.rs line 139 at r1 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

error!("Failed to convert Starknet API ClassInfo to Blockifier ClassInfo: {:?}", e);

Done.

@ArniStarkware ArniStarkware marked this pull request as ready for review August 19, 2024 13:30
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/update_process_tx branch from 9a5d8bd to a5af9bc Compare August 19, 2024 14:42
@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/update_process_tx branch from a5af9bc to 65e6550 Compare August 20, 2024 11:43
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/create_executable_tx branch 2 times, most recently from eac85a8 to 9c0e1fa Compare August 20, 2024 12:34
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/update_process_tx branch from 65e6550 to 70056e5 Compare August 20, 2024 14:04
@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/update_process_tx branch 2 times, most recently from b0a4971 to 10fc2e9 Compare August 21, 2024 06:58
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/create_executable_tx branch from cf3cdac to b056be0 Compare August 21, 2024 06:58
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 3 of 3 files at r3, all commit messages.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @ArniStarkware, @ayeletstarkware, @MohammadNassar1, and @yair-starkware)


crates/gateway/src/gateway.rs line 135 at r3 (raw file):

        &tx,
        &gateway_compiler,
        &stateful_tx_validator.config.chain_info.chain_id,

Can you add a TODO to move the chain ID config out to the GW config?

Code quote:

&stateful_tx_validator.config.chain_info.chain_id,

crates/gateway/src/utils.rs line 35 at r3 (raw file):

use crate::errors::{GatewaySpecError, StatefulTransactionValidatorResult};

pub fn external_tx_to_executable_tx(

Let's move all this code to SNAPI?


crates/gateway/src/utils.rs line 35 at r3 (raw file):

use crate::errors::{GatewaySpecError, StatefulTransactionValidatorResult};

pub fn external_tx_to_executable_tx(

Here and everywhere else.

Suggestion:

rpc_tx_to_executable_tx

crates/gateway/src/utils.rs line 58 at r3 (raw file):

fn external_declare_tx_to_executable_tx(
    external_tx: &RpcDeclareTransaction,
    gateway_compiler: &GatewayCompiler,

I think this function should get the compiled class_info as an argument.
Convert functions shouldn't hide heavy stuff like compilation.

Code quote:

gateway_compiler: &GatewayCompiler,

crates/gateway/src/utils.rs line 62 at r3 (raw file):

) -> Result<ExecutableDeclareTransaction, GatewaySpecError> {
    let class_info = gateway_compiler.process_declare_tx(external_tx)?;
    let RpcDeclareTransaction::V3(tx) = external_tx;

Just to make sure: if we add another version, i.e. RpcDecalareTransaction::V4, this code won't compile right?

Code quote:

let RpcDeclareTransaction::V3(tx) = external_tx;

crates/gateway/src/utils.rs line 65 at r3 (raw file):

    let declare_tx = DeclareTransaction::V3(DeclareTransactionV3 {
        class_hash: ClassHash::default(), /* FIXME(yael 15/4/24): call the starknet-api
                                           * function once ready */

Is it ready?

Code quote:

        class_hash: ClassHash::default(), /* FIXME(yael 15/4/24): call the starknet-api
                                           * function once ready */

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.

Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @ArniStarkware, @ayeletstarkware, @MohammadNassar1, and @yair-starkware)


crates/gateway/src/gateway.rs line 135 at r3 (raw file):

Previously, dafnamatsry wrote…

Can you add a TODO to move the chain ID config out to the GW config?

Just noticed you added it in a following PR :)

@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/update_process_tx branch from 10fc2e9 to 6bc63b8 Compare August 21, 2024 09:16
@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/snapi/executable_tx/class_method_new branch from 2f03898 to 6530a9d Compare September 3, 2024 15:37
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/create_executable_tx branch 3 times, most recently from e82a9c3 to db406e5 Compare September 3, 2024 16:12
@ArniStarkware ArniStarkware force-pushed the arni/snapi/executable_tx/class_method_new branch from 6530a9d to 6a113d0 Compare September 4, 2024 10:48
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/create_executable_tx branch from db406e5 to 2c78330 Compare September 4, 2024 10:48
@ArniStarkware ArniStarkware force-pushed the arni/snapi/executable_tx/class_method_new branch from 6a113d0 to 12ec5d4 Compare September 4, 2024 12:03
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/create_executable_tx branch from 2c78330 to 2ea95c6 Compare September 4, 2024 12:03
@ArniStarkware ArniStarkware force-pushed the arni/snapi/executable_tx/class_method_new branch from 12ec5d4 to 001ac66 Compare September 5, 2024 08:46
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/create_executable_tx branch from 2ea95c6 to 8803f2b Compare September 5, 2024 08:46
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: 1 of 9 files reviewed, 8 unresolved discussions (waiting on @ayeletstarkware, @dafnamatsry, @MohammadNassar1, and @yair-starkware)


crates/gateway/src/compilation.rs line 33 at r10 (raw file):

Previously, dafnamatsry wrote…

You can do it as part of this PR.

No longer relevant.


crates/gateway/src/compilation.rs line 60 at r10 (raw file):

Previously, dafnamatsry wrote…

Why did you change the return value?

The role of the compiler is to compile and shouldn't handle any other unrelated declare tx fields.
Please move the conversion logic to compile_to_casm_and_convert_rpc_to_executable_tx.

no longer relevant.


crates/gateway/src/gateway_test.rs line 104 at r10 (raw file):

Previously, dafnamatsry wrote…

Can we calculate the hash without going through an AccountTransaction?

Maybe you can use rpc_tx.into().calculate_transaction_hash().

This function will be deleted. This is out of the scope of this PR.


crates/gateway/src/utils.rs line 44 at r10 (raw file):

Previously, dafnamatsry wrote…

No need for the map_err right?

Note that you are mapping a legitimate CompilationFailed and ompiledClassHashMismatch to UnexpectedError.
Please add a test to gateway_test to make sure we return those errors.

Done.

@ArniStarkware ArniStarkware force-pushed the arni/snapi/executable_tx/class_method_new branch from 001ac66 to fb3deb5 Compare September 5, 2024 14:33
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/create_executable_tx branch from 8803f2b to ef6ffeb Compare September 5, 2024 14:33
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 7 of 7 files at r13, all commit messages.
Reviewable status: 8 of 9 files reviewed, 5 unresolved discussions (waiting on @ArniStarkware, @ayeletstarkware, @MohammadNassar1, and @yair-starkware)


crates/gateway/src/compilation.rs line 36 at r13 (raw file):

    }

    // TODO(Arni): Squash this function into `process_declare_tx`.

Remove :)

Code quote:

    // TODO(Arni): Squash this function into `process_declare_tx`.

crates/gateway/src/compilation_test.rs line 70 at r13 (raw file):

#[rstest]
fn test_class_info_from_declare_tx_tx_success(

Suggestion:

test_process_declare_tx_success

crates/gateway/src/utils.rs line 39 at r13 (raw file):

/// executable contract class.
pub fn compile_contract_and_build_executable_tx(
    rpc_tx: RpcTransaction,

and then you won't need the clone in the gateway...

In general, I think in most cases we only want to pass references as function arguments (unless you want to enforce that an object can't be used after the function call).

Suggestion:

rpc_tx: &RpcTransaction,

crates/gateway/src/utils.rs line 85 at r13 (raw file):

fn compile_contract_and_build_executable_declare_tx(
    rpc_tx: RpcDeclareTransaction,

Suggestion:

rpc_tx: &RpcDeclareTransaction,

@ArniStarkware ArniStarkware force-pushed the arni/snapi/executable_tx/class_method_new branch from fb3deb5 to 25c4fcd Compare September 8, 2024 07:41
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/create_executable_tx branch from ef6ffeb to 865ec2d Compare September 8, 2024 07:41
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: 6 of 9 files reviewed, 5 unresolved discussions (waiting on @ayeletstarkware, @dafnamatsry, @MohammadNassar1, and @yair-starkware)


crates/gateway/src/compilation.rs line 36 at r13 (raw file):

Previously, dafnamatsry wrote…

Remove :)

Done.


crates/gateway/src/compilation_test.rs line 70 at r13 (raw file):

#[rstest]
fn test_class_info_from_declare_tx_tx_success(

Done.

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 2 of 2 files at r14, all commit messages.
Reviewable status: 8 of 9 files reviewed, all discussions resolved (waiting on @ayeletstarkware, @MohammadNassar1, and @yair-starkware)

@ArniStarkware
Copy link
Contributor Author

crates/gateway/src/utils.rs line 39 at r13 (raw file):

Previously, dafnamatsry wrote…

and then you won't need the clone in the gateway...

In general, I think in most cases we only want to pass references as function arguments (unless you want to enforce that an object can't be used after the function call).

Discussed on DMs. Ignored.
The ownership-taking is by design.

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

Copy link
Contributor Author

ArniStarkware commented Sep 8, 2024

Merge activity

@ArniStarkware ArniStarkware changed the base branch from arni/snapi/executable_tx/class_method_new to graphite-base/517 September 8, 2024 08:31
@ArniStarkware ArniStarkware changed the base branch from graphite-base/517 to main September 8, 2024 08:31
@ArniStarkware ArniStarkware force-pushed the arni/executable_tx_in_gateway/create_executable_tx branch from 865ec2d to d6c9296 Compare September 8, 2024 08:32
@ArniStarkware ArniStarkware merged commit 3f941d6 into main Sep 8, 2024
14 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 9, 2024
@ArniStarkware ArniStarkware deleted the arni/executable_tx_in_gateway/create_executable_tx 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.

2 participants