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(transaction): add common getters to transaction #229

Merged

Conversation

meship-starkware
Copy link
Contributor

@meship-starkware meship-starkware commented Jul 31, 2024

This change is Reviewable

@meship-starkware meship-starkware requested a review from noaov1 July 31, 2024 11:11
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.

@tdelabro I am not sure this is what you had in mind
please LMK if you have any comments

Reviewable status: 0 of 2 files reviewed, all discussions resolved (waiting on @noaov1)

Copy link

@tdelabro tdelabro left a comment

Choose a reason for hiding this comment

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

Yup this is what I ment.
There may be other ones you could add, have you checked for every fields?

crates/blockifier/src/transaction/account_transaction.rs Outdated Show resolved Hide resolved
crates/blockifier/src/transaction/transaction_execution.rs Outdated Show resolved Hide resolved
@meship-starkware meship-starkware force-pushed the meship/blockifier/add_common_getters_to_transaction branch from 2f07d14 to 110a23f Compare August 21, 2024 08:19
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.

In the case of the blockier transaction, the only other common field they have is the tx, but everyone is of a different type
So I cannot write a getter for it. In the case of the Transaction object in the starknet API they do have more common fields but they are divided by versions and already have some common getters for some of the fields.

Reviewable status: 0 of 2 files reviewed, 2 unresolved discussions (waiting on @noaov1 and @tdelabro)


crates/blockifier/src/transaction/account_transaction.rs line 200 at r1 (raw file):

Previously, tdelabro (Timothée Delabrouille) wrote…

Don't name getters methods using the get_ prefix

https://rust-lang.github.io/api-guidelines/naming.html#getter-names-follow-rust-convention-c-getter

Done.


crates/blockifier/src/transaction/transaction_execution.rs line 101 at r1 (raw file):

Previously, tdelabro (Timothée Delabrouille) wrote…

same

Done.

@meship-starkware meship-starkware force-pushed the meship/blockifier/add_common_getters_to_transaction branch from 110a23f to abb33f7 Compare August 21, 2024 10:07
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 2 files reviewed, 2 unresolved discussions (waiting on @ArniStarkware, @noaov1, and @tdelabro)


crates/blockifier/src/transaction/account_transaction.rs line 200 at r1 (raw file):

Previously, meship-starkware (Meshi Peled) wrote…

Done.

Someone already added this getter to the account transaction, so I only needed to add it to transaction_execution.
Also, @ArniStarkware returns TransactionHash inside of &TransactionHash, so I decided to go with it
LMK if it might cause a problem.

pub fn tx_hash(&self) -> TransactionHash {

@ArniStarkware
Copy link
Contributor

crates/blockifier/src/transaction/account_transaction.rs line 200 at r1 (raw file):

Previously, meship-starkware (Meshi Peled) wrote…

Someone already added this getter to the account transaction, so I only needed to add it to transaction_execution.
Also, @ArniStarkware returns TransactionHash inside of &TransactionHash, so I decided to go with it
LMK if it might cause a problem.

pub fn tx_hash(&self) -> TransactionHash {

*instead of?

@ArniStarkware
Copy link
Contributor

-- commits line 2 at r2:

Suggestion:

- abb33f7: refactor(blockifier): add getter for tx_hash to transaction

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:

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


-- commits line 2 at r2:
Make sure the merged commit message has no typo.

Code quote:

tramsaction

@meship-starkware meship-starkware force-pushed the meship/blockifier/add_common_getters_to_transaction branch from abb33f7 to ef21a6b Compare August 21, 2024 11:28
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: all files reviewed, 2 unresolved discussions (waiting on @noaov1 and @tdelabro)


crates/blockifier/src/transaction/account_transaction.rs line 200 at r1 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

*instead of?

In the end, I changed my getter to return the object instead of a reference. So the question was for @tdelabro if it fits his need

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

@meship-starkware meship-starkware force-pushed the meship/blockifier/add_common_getters_to_transaction branch from ef21a6b to e9b4ca6 Compare August 21, 2024 11:30
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: all files reviewed, 2 unresolved discussions (waiting on @noaov1 and @tdelabro)

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.

Reviewed 1 of 2 files at r2, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @tdelabro)

Copy link

@tdelabro tdelabro left a comment

Choose a reason for hiding this comment

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

already have some common getters for some of the fields

Yeah that was what I was referring to. The issue is in the "some".
Those getters have been added erratically, when someone in the Starkware team needed them, without a concern for exhaustivity.
This PR could solve this by checking that every common field is covered by a getter

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @meship-starkware)

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

@meship-starkware meship-starkware force-pushed the meship/blockifier/add_common_getters_to_transaction branch from e9b4ca6 to bb6dd7f Compare September 3, 2024 06:30
Copy link

codecov bot commented Sep 3, 2024

Codecov Report

Attention: Patch coverage is 0% with 27 lines in your changes missing coverage. Please review.

Project coverage is 69.89%. Comparing base (b0cfe82) to head (836b981).
Report is 106 commits behind head on main.

Files with missing lines Patch % Lines
...lockifier/src/transaction/transaction_execution.rs 0.00% 15 Missing ⚠️
.../blockifier/src/transaction/account_transaction.rs 0.00% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #229      +/-   ##
==========================================
- Coverage   74.18%   69.89%   -4.30%     
==========================================
  Files         359       87     -272     
  Lines       36240    11246   -24994     
  Branches    36240    11246   -24994     
==========================================
- Hits        26886     7860   -19026     
+ Misses       7220     2998    -4222     
+ Partials     2134      388    -1746     
Flag Coverage Δ
69.89% <0.00%> (-4.30%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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 4 files reviewed, 5 unresolved discussions (waiting on @ArniStarkware, @noaov1, and @tdelabro)


crates/blockifier/src/transaction/account_transaction.rs line 145 at r4 (raw file):

        (max_fee, Option<Fee>)
    );

I'm not sure about the option here. It might be better to return an error or panic, as I did with the only V3 case.
Just to be clear, I think that all getters who do not have all options need to act the same. When we decide on a better solution, I will refactor all of them to act the same.


crates/starknet_api/src/transaction.rs line 299 at r4 (raw file):

        }
    }

I am not sure this getter is needed, but all the other fields had one, so I added this.


crates/starknet_api/src/transaction.rs line 411 at r4 (raw file):

        $(pub fn $field(&self) -> $field_type {
            match self {
                Self::V3(tx) => tx.$field.clone(),

I am not sure the panic here is a good thing. It does make the code cleaner (no need to wrap in result or option), but I think it better to let the user decide how to handle errors this way and not panic if he accidentally asks a field that does not exist for the wanted version. WDYT?

@ArniStarkware ArniStarkware requested a review from noaov1 September 3, 2024 08:01
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 4 files at r4.
Reviewable status: 1 of 4 files reviewed, 7 unresolved discussions (waiting on @meship-starkware, @noaov1, and @tdelabro)


crates/blockifier/src/transaction/account_transaction.rs line 145 at r4 (raw file):

Previously, meship-starkware (Meshi Peled) wrote…

I'm not sure about the option here. It might be better to return an error or panic, as I did with the only V3 case.
Just to be clear, I think that all getters who do not have all options need to act the same. When we decide on a better solution, I will refactor all of them to act the same.

Maybe return default class hash.


crates/blockifier/src/transaction/account_transaction.rs line 160 at r4 (raw file):

            Self::Invoke(tx) => Some(tx.tx.sender_address()),
        }
    }

Deploy account has the sender address as a member of the transaction on an external layer.

Also - make sure we don't have both getters for contract address and sender address.

Suggestion:

    pub fn sender_address(&self) -> ContractAddress {
        match self {
            Self::Declare(tx) => tx.tx.sender_address(),
            Self::DeployAccount(tx) => tx.contract_address(),
            Self::Invoke(tx) => tx.tx.sender_address(),
        }
    }

crates/starknet_api/src/executable_transaction.rs line 160 at r4 (raw file):

        (fee_data_availability_mode, DataAvailabilityMode),
        (paymaster_data, PaymasterData),
        (max_fee, Option<Fee>)

I don't like the fact that executable transaction can return max fee.

the executable transaction should be a creature of v3 transaction only (I know it is not, this is the ideal).

Code quote:

        (max_fee, Option<Fee>)

crates/starknet_api/src/transaction.rs line 299 at r4 (raw file):

Previously, meship-starkware (Meshi Peled) wrote…

I am not sure this getter is needed, but all the other fields had one, so I added this.

I sent you a DM about it.


crates/starknet_api/src/transaction.rs line 411 at r4 (raw file):

Previously, meship-starkware (Meshi Peled) wrote…

I am not sure the panic here is a good thing. It does make the code cleaner (no need to wrap in result or option), but I think it better to let the user decide how to handle errors this way and not panic if he accidentally asks a field that does not exist for the wanted version. WDYT?

Maybe you can return the default, but I don't like that either...

@meship-starkware meship-starkware force-pushed the meship/blockifier/add_common_getters_to_transaction branch from bb6dd7f to 801ab7a Compare September 3, 2024 11:28
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 4 files reviewed, 7 unresolved discussions (waiting on @ArniStarkware, @noaov1, and @tdelabro)


crates/blockifier/src/transaction/account_transaction.rs line 160 at r4 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

Deploy account has the sender address as a member of the transaction on an external layer.

Also - make sure we don't have both getters for contract address and sender address.

Done.
in this pr https://reviewable.io/reviews/starkware-libs/sequencer/699

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 4 files reviewed, 5 unresolved discussions (waiting on @ArniStarkware, @noaov1, and @tdelabro)


crates/blockifier/src/transaction/account_transaction.rs line 145 at r4 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

Maybe return default class hash.

added relevant comment in this PR https://reviewable.io/reviews/starkware-libs/sequencer/699


crates/starknet_api/src/executable_transaction.rs line 160 at r4 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

I don't like the fact that executable transaction can return max fee.

the executable transaction should be a creature of v3 transaction only (I know it is not, this is the ideal).

will do in this PR https://reviewable.io/reviews/starkware-libs/sequencer/699

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: - post expansion of the scope of this PR, and the split.

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

@meship-starkware meship-starkware force-pushed the meship/blockifier/add_common_getters_to_transaction branch from 801ab7a to 53e4b84 Compare September 3, 2024 14:28
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: 3 of 4 files reviewed, 2 unresolved discussions (waiting on @ArniStarkware, @noaov1, and @tdelabro)


crates/starknet_api/src/executable_transaction.rs line 160 at r4 (raw file):

Previously, meship-starkware (Meshi Peled) wrote…

will do in this PR https://reviewable.io/reviews/starkware-libs/sequencer/699

Done.

@meship-starkware meship-starkware force-pushed the meship/blockifier/add_common_getters_to_transaction branch from 53e4b84 to 2934fc4 Compare September 4, 2024 05:55
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 r7, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @noaov1 and @tdelabro)

@meship-starkware meship-starkware force-pushed the meship/blockifier/add_common_getters_to_transaction branch from 2934fc4 to e18369d Compare September 4, 2024 07:29
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 r8, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @noaov1 and @tdelabro)

@meship-starkware meship-starkware force-pushed the meship/blockifier/add_common_getters_to_transaction branch from e18369d to ad686ee Compare September 8, 2024 10:01
@ArniStarkware
Copy link
Contributor

crates/blockifier/src/transaction/transaction_execution.rs line 52 at r9 (raw file):

        }
    }
    pub fn from_api(

spaces.

Suggestion:

    pub fn nonce(&self) -> Nonce {
        match self {
            Self::AccountTransaction(tx) => tx.nonce(),
            Self::L1HandlerTransaction(tx) => tx.tx.nonce,
        }
    }
    
    pub fn sender_address(&self) -> ContractAddress {
        match self {
            Self::AccountTransaction(tx) => tx.sender_address(),
            Self::L1HandlerTransaction(tx) => tx.tx.contract_address,
        }
    }
    
    pub fn from_api(

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 2 files at r9, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @meship-starkware, @noaov1, and @tdelabro)

@meship-starkware meship-starkware force-pushed the meship/blockifier/add_common_getters_to_transaction branch from ad686ee to 2b62d2b Compare September 8, 2024 13: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: 3 of 4 files reviewed, 3 unresolved discussions (waiting on @ArniStarkware, @noaov1, and @tdelabro)


crates/blockifier/src/transaction/transaction_execution.rs line 52 at r9 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

spaces.

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.

Reviewed 1 of 1 files at r10, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @noaov1 and @tdelabro)

@ArniStarkware ArniStarkware self-requested a review September 9, 2024 14:53
@meship-starkware meship-starkware force-pushed the meship/blockifier/add_common_getters_to_transaction branch from 2b62d2b to daeae52 Compare September 25, 2024 12:45
@meship-starkware meship-starkware force-pushed the meship/blockifier/add_common_getters_to_transaction branch from daeae52 to 836b981 Compare September 26, 2024 05:59
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 r11, 1 of 1 files at r12, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @noaov1 and @tdelabro)

Copy link

@tdelabro tdelabro 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 r11, 1 of 1 files at r12, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @noaov1)

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.

Dismissed @tdelabro from a discussion.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @noaov1)

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.

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

@meship-starkware meship-starkware merged commit a9b9ce1 into main Sep 26, 2024
12 checks passed
@meship-starkware meship-starkware deleted the meship/blockifier/add_common_getters_to_transaction branch September 26, 2024 13:38
@github-actions github-actions bot locked and limited conversation to collaborators Oct 4, 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.

4 participants