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(transaction): implement rpc transaction #236

Merged

Conversation

MohammadNassar1
Copy link
Contributor

@MohammadNassar1 MohammadNassar1 commented Apr 24, 2024

This change is Reviewable

@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/transaction/implement_rpc_transaction branch from a22c544 to a327a51 Compare May 1, 2024 10:47
Copy link
Contributor

@ayeletstarkware ayeletstarkware 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 4 files at r1, 4 of 4 files at r2, all commit messages.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @giladchase and @MohammadNassar1)


src/rpc_transaction.rs line 37 at r2 (raw file):

/// [`Starknet specs`]: https://github.com/starkware-libs/starknet-specs/blob/master/api/starknet_api_openrpc.json
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields)]

Is this necessary? it's not in ExternalTransaction


src/rpc_transaction.rs line 50 at r2 (raw file):

///
/// [`Starknet specs`]: https://github.com/starkware-libs/starknet-specs/blob/master/api/starknet_api_openrpc.json
#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]

Where do you use Hash, Ord and PartialOrd? (also for the other tx type)


src/rpc_transaction.rs line 72 at r2 (raw file):

/// A declare transaction of a Cairo-v1 contract class that can be added to Starknet through the
/// RPC.
#[derive(Debug, Deserialize, Serialize, Clone, Eq, PartialEq)]

alphabetize


src/rpc_transaction.rs line 92 at r2 (raw file):

/// A deploy account transaction that can be added to Starknet through the RPC.
#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct RPCDeployAccountTransactionV3 {

in ExternalTransaction there's #[serde(deny_unknown_fields)]. why not here?
same for RPCInvokeTransactionV3


src/rpc_transaction.rs line 123 at r2 (raw file):

#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct ContractClass {
    pub sierra_program: Vec<StarkFelt>,

The code below is from ExternalTransaction. Why did you change it? Because of the spec? I see that this field used to be a String, and now it's a vector of StarkFelts.

Code snippet:

#[serde(rename = "sierra_program")]
 pub compressed_sierra_program: String,

src/rpc_transaction.rs line 130 at r2 (raw file):

#[derive(Debug, Clone, Default, Eq, PartialEq, Deserialize, Serialize)]
pub struct EntryPointByType {

Why did you decide to change entry_points_by_type, that was HashMap<EntryPointType, Vec<EntryPoint>> (EntryPointType as an enum) to a struct?

giladchase
giladchase previously approved these changes May 5, 2024
Copy link
Contributor

@giladchase giladchase 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 4 files at r2, all commit messages.
Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @ayeletstarkware and @MohammadNassar1)


src/rpc_transaction.rs line 35 at r2 (raw file):

/// either a contract class or a class hash).
///
/// [`Starknet specs`]: https://github.com/starkware-libs/starknet-specs/blob/master/api/starknet_api_openrpc.json

🤩

Code quote:

/// [`Starknet specs`]: https://github.com/starkware-libs/starknet-specs/blob/master/api/starknet_api_openrpc.json

src/rpc_transaction.rs line 130 at r2 (raw file):

Previously, ayeletstarkware (Ayelet Zilber) wrote…

Why did you decide to change entry_points_by_type, that was HashMap<EntryPointType, Vec<EntryPoint>> (EntryPointType as an enum) to a struct?

In general, if you have a hash with fixed fields it should be a struct, it is better:

a) you get a compile-time check that all keys you want exist for free
b) easier to access the values, rather than having to do a get(thing).unwrap() or something like that
c) faster access, more optimized

probably other that I forgot.
But basically hashmaps are largly for dynamic content, not fixed.


src/rpc_transaction_test.rs line 1 at r2 (raw file):

use std::sync::Arc;

no logic changes right? just move/rename?

@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/transaction/implement_rpc_transaction branch 2 times, most recently from e16363b to 0cac003 Compare May 26, 2024 13:54
Copy link
Contributor Author

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


src/rpc_transaction.rs line 35 at r2 (raw file):

Previously, giladchase wrote…

🤩

:)


src/rpc_transaction.rs line 37 at r2 (raw file):

Previously, ayeletstarkware (Ayelet Zilber) wrote…

Is this necessary? it's not in ExternalTransaction

Moved to ExternalTransaction


src/rpc_transaction.rs line 50 at r2 (raw file):

Previously, ayeletstarkware (Ayelet Zilber) wrote…

Where do you use Hash, Ord and PartialOrd? (also for the other tx type)

Note that this struct should be shared among other crates.
So, I prefer to keep additional traits that can be useful for others.


src/rpc_transaction.rs line 72 at r2 (raw file):

Previously, ayeletstarkware (Ayelet Zilber) wrote…

alphabetize

Done.


src/rpc_transaction.rs line 92 at r2 (raw file):

Previously, ayeletstarkware (Ayelet Zilber) wrote…

in ExternalTransaction there's #[serde(deny_unknown_fields)]. why not here?
same for RPCInvokeTransactionV3

Good point.
I think it should be added for ExternalTransaction struct.
As the deserialization is done over ExernalTransaction struct.


src/rpc_transaction.rs line 123 at r2 (raw file):

Previously, ayeletstarkware (Ayelet Zilber) wrote…

The code below is from ExternalTransaction. Why did you change it? Because of the spec? I see that this field used to be a String, and now it's a vector of StarkFelts.

Correct, changed to be aligned with the spec.


src/rpc_transaction_test.rs line 1 at r2 (raw file):

Previously, giladchase wrote…

no logic changes right? just move/rename?

correct

Copy link
Contributor Author

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

a discussion (no related file):
In this PR, I changed the struct fields to be aligned with the spec.
Next PR, rename to RPCTransaction.


Copy link
Contributor

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

Copy link
Contributor

@ayeletstarkware ayeletstarkware 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 5 files at r3.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @ArniStarkware and @MohammadNassar1)


src/external_transaction.rs line 28 at r3 (raw file):

    DeployAccount(ExternalDeployAccountTransaction),
    /// An invoke transaction.
    #[serde(rename = "INVOKE_FUNCTION")]

why did you remove it?

Code quote:

_FUNCTION

src/external_transaction_test.rs line 21 at r3 (raw file):

fn create_resource_bounds() -> ResourceBoundsMapping {
    let mut map = BTreeMap::new();
    map.insert(Resource::L1Gas, ResourceBounds { max_amount: 100, max_price_per_unit: 12 });

What are these values? I see you use default values now.


src/executable_transaction.rs line 4 at r1 (raw file):

use crate::state::ContractClass;
use crate::transaction::TransactionHash;

why?

@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/transaction/implement_rpc_transaction branch from 0cac003 to 5458bda Compare May 28, 2024 07:16
Copy link
Contributor Author

@MohammadNassar1 MohammadNassar1 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 6 files reviewed, 4 unresolved discussions (waiting on @ArniStarkware, @ayeletstarkware, and @giladchase)


src/external_transaction.rs line 28 at r3 (raw file):

Previously, ayeletstarkware (Ayelet Zilber) wrote…

why did you remove it?

See here


src/external_transaction_test.rs line 21 at r3 (raw file):

Previously, ayeletstarkware (Ayelet Zilber) wrote…

What are these values? I see you use default values now.

I've added a new function that generates non-default values.


src/executable_transaction.rs line 4 at r1 (raw file):

Previously, ayeletstarkware (Ayelet Zilber) wrote…

why?

This file wasn't changed.
It's not related to the external tx.

Copy link
Contributor

@ayeletstarkware ayeletstarkware 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 r4, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ArniStarkware and @MohammadNassar1)


src/external_transaction_test.rs line 21 at r3 (raw file):

Previously, MohammadNassar1 (mohammad-starkware) wrote…

I've added a new function that generates non-default values.

Add a comment explaining that these are non-default values because they're random and seem to mean something.

@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/transaction/implement_rpc_transaction branch from 5458bda to 8317046 Compare May 28, 2024 10:20
Copy link
Contributor Author

@MohammadNassar1 MohammadNassar1 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 6 files reviewed, 2 unresolved discussions (waiting on @ArniStarkware and @ayeletstarkware)


src/external_transaction_test.rs line 21 at r3 (raw file):

Previously, ayeletstarkware (Ayelet Zilber) wrote…

Add a comment explaining that these are non-default values because they're random and seem to mean something.

Done.

Copy link
Contributor

@ayeletstarkware ayeletstarkware 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 r5, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ArniStarkware)

Copy link
Contributor

@ayeletstarkware ayeletstarkware 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: all files reviewed, 1 unresolved discussion (waiting on @ArniStarkware)

@ArniStarkware
Copy link
Contributor

src/external_transaction.rs line 122 at r5 (raw file):

#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct ContractClass {
    pub sierra_program: Vec<StarkFelt>,

Can we be aligned with the class ContractClass used in the compilers repo?

Suggestion:

    pub sierra_program: Vec<BigUintAsHex>,

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: :shipit: complete! all files reviewed, all discussions resolved (waiting on @MohammadNassar1)


src/external_transaction.rs line 122 at r5 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

Can we be aligned with the class ContractClass used in the compilers repo?

Discussed F2F. This is complicated.

@MohammadNassar1 MohammadNassar1 changed the base branch from main to main-mempool May 29, 2024 08:33
@MohammadNassar1 MohammadNassar1 force-pushed the mohammad/transaction/implement_rpc_transaction branch from 8317046 to 37a169f Compare May 29, 2024 08:35
@ArniStarkware
Copy link
Contributor

src/external_transaction.rs line 122 at r5 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

Discussed F2F. This is complicated.

Wait - we talked F2f about how this member needs to be consistent with the RPC.
(look for the line: The list of Sierra instructions of which the program consists in here
But we just changed this value (to fit this better, I admit). Who is in charge of the RPC? Are we sure they are using the same values for external transactions? Can the external transaction use a different ContractClass struct than the one Papyrus is using?

Copy link
Contributor Author

@MohammadNassar1 MohammadNassar1 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 6 files reviewed, 1 unresolved discussion (waiting on @ArniStarkware, @ayeletstarkware, and @giladchase)


src/external_transaction.rs line 122 at r5 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

Wait - we talked F2f about how this member needs to be consistent with the RPC.
(look for the line: The list of Sierra instructions of which the program consists in here
But we just changed this value (to fit this better, I admit). Who is in charge of the RPC? Are we sure they are using the same values for external transactions? Can the external transaction use a different ContractClass struct than the one Papyrus is using?

Why do you think we use a different value?
What do you mean by external transaction? the one that is different than RPC.

I think Ariel is in charged of this spec.

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.

:lgtm:

Reviewable status: 5 of 6 files reviewed, all discussions resolved (waiting on @ayeletstarkware and @giladchase)


src/external_transaction.rs line 122 at r5 (raw file):

Previously, MohammadNassar1 (mohammad-starkware) wrote…

Why do you think we use a different value?
What do you mean by external transaction? the one that is different than RPC.

I think Ariel is in charged of this spec.

NVM.

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 2 files at r6, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ayeletstarkware and @giladchase)

@MohammadNassar1 MohammadNassar1 merged commit 8e7cf72 into main-mempool May 29, 2024
1 check passed
@MohammadNassar1 MohammadNassar1 deleted the mohammad/transaction/implement_rpc_transaction branch May 29, 2024 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants