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

chore(blockifier): impl traits Executable & TxInfoCreator for api_executabe_txs #1279

Conversation

avivg-starkware
Copy link
Contributor

@avivg-starkware avivg-starkware commented Oct 9, 2024

This change is Reviewable

@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/make_execution_tx_compatible_w_blockifier_tx branch from e6bc976 to f21ad3e Compare October 9, 2024 13:02
@avivg-starkware avivg-starkware changed the title add(blockifier): impl traits Executable & TxInfoCreator for api_executabe_txs chore(blockifier): impl traits Executable & TxInfoCreator for api_executabe_txs Oct 9, 2024
Copy link

codecov bot commented Oct 9, 2024

Codecov Report

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

Project coverage is 75.57%. Comparing base (e3165c4) to head (758f49b).
Report is 286 commits behind head on main.

Files with missing lines Patch % Lines
crates/blockifier/src/transaction/transactions.rs 0.00% 182 Missing ⚠️
crates/starknet_api/src/executable_transaction.rs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1279       +/-   ##
===========================================
+ Coverage   40.10%   75.57%   +35.47%     
===========================================
  Files          26      102       +76     
  Lines        1895    13872    +11977     
  Branches     1895    13872    +11977     
===========================================
+ Hits          760    10484     +9724     
- Misses       1100     2932     +1832     
- Partials       35      456      +421     

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

Copy link
Contributor

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

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


crates/blockifier/src/transaction/transactions.rs line 668 at r1 (raw file):

                    // In the past, we allowed redeclaration of Cairo 0 contracts since there was
                    // no class commitment (so no need to check if the class is already declared).
                    state.set_contract_class(class_hash, contract_class(self)?)?;

Is this semi-column intentional? Also, it seems like all the functions are returning None upon success, so in which case are we returning CallInfo? Is it for future use?


crates/blockifier/src/transaction/transactions.rs line 709 at r1 (raw file):

                    max_fee: tx.max_fee,
                })
            }

Do they need to be in different cases because of the compiled class hash? It seems to me like it should work.

Suggestion:

            starknet_api::transaction::DeclareTransaction::V0(tx)
            | starknet_api::transaction::DeclareTransaction::V1(tx) | 
            starknet_api::transaction::DeclareTransaction::V2(tx)  => {
                TransactionInfo::Deprecated(DeprecatedTransactionInfo {
                    common_fields,
                    max_fee: tx.max_fee,
                })
            }

Copy link
Contributor

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


crates/blockifier/src/transaction/transactions.rs line 668 at r1 (raw file):

Previously, meship-starkware (Meshi Peled) wrote…

Is this semi-column intentional? Also, it seems like all the functions are returning None upon success, so in which case are we returning CallInfo? Is it for future use?

Never mind, I saw that it is part of this function API. Only the semicolon part is relevant

Copy link
Contributor

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

Reviewed 1 of 2 files at r1.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @avivg-starkware and @noaov1)

Copy link
Contributor

@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 @avivg-starkware and @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 2 files at r1, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @avivg-starkware)


crates/blockifier/src/transaction/transactions.rs line 10 at r1 (raw file):

    DeployAccountTransaction as StarknetApiDeployAccountTx,
    InvokeTransaction as StarknetApiInvokeTx,
};

Suggestion:

use starknet_api::executable_transaction::{
    DeclareTransaction as ExecutableDeclareTransaction,
    DeployAccountTransaction as ExecutableDeployAccountTx,
    InvokeTransaction as ExecutableInvokeTx,
};

crates/blockifier/src/transaction/transactions.rs line 693 at r1 (raw file):

            nonce: self.nonce(),
            sender_address: self.sender_address(),
            only_query: false, //QUESTION(AvivG): should get only_query from some source?

That is an interesting question. We can set it here to false and than override it by the account transaction that called this method.

Code quote:

            only_query: false, //QUESTION(AvivG): should get only_query from some source?

@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/make_execution_tx_compatible_w_blockifier_tx branch from f21ad3e to 3ad4d2a Compare October 20, 2024 10:57
Copy link
Contributor Author

@avivg-starkware avivg-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, 4 unresolved discussions (waiting on @meship-starkware and @noaov1)


crates/blockifier/src/transaction/transactions.rs line 10 at r1 (raw file):

    DeployAccountTransaction as StarknetApiDeployAccountTx,
    InvokeTransaction as StarknetApiInvokeTx,
};

for consistency I've changed all to end with 'Tx' instead of 'Transaction'. Is there a reason you think 'ExecutableDeclareTransaction' should be different? or to have them all end with 'Transaction'?


crates/blockifier/src/transaction/transactions.rs line 693 at r1 (raw file):

Previously, noaov1 (Noa Oved) wrote…

That is an interesting question. We can set it here to false and than override it by the account transaction that called this method.

OK thank you. I left a temporary comment for myself to be removed before merging.


crates/blockifier/src/transaction/transactions.rs line 709 at r1 (raw file):

Previously, meship-starkware (Meshi Peled) wrote…

Do they need to be in different cases because of the compiled class hash? It seems to me like it should work.

'tx' in the first two is of type 'DeclareTransactionV0V1' and in the latter it is 'DeclareTransactionV2', because it is used to extract max_fee, it must be separated

@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/make_execution_tx_compatible_w_blockifier_tx branch from 3ad4d2a to b35e972 Compare October 28, 2024 13:54
@avivg-starkware avivg-starkware changed the base branch from main to noa/use_raw_contract_class_in_class_info October 28, 2024 13:55
Copy link

Artifacts upload triggered. View details here

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.

:lgtm:

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


crates/blockifier/src/transaction/transactions.rs line 10 at r1 (raw file):

Previously, avivg-starkware wrote…

for consistency I've changed all to end with 'Tx' instead of 'Transaction'. Is there a reason you think 'ExecutableDeclareTransaction' should be different? or to have them all end with 'Transaction'?

No, I accidentally wrote it differently.

Copy link
Contributor

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

Reviewed 1 of 2 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @avivg-starkware)

@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/make_execution_tx_compatible_w_blockifier_tx branch from b35e972 to 6ab33b3 Compare November 4, 2024 11:53
@avivg-starkware avivg-starkware changed the base branch from noa/use_raw_contract_class_in_class_info to main November 4, 2024 15:23
Copy link

github-actions bot commented Nov 4, 2024

Artifacts upload triggered. View details here

@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/make_execution_tx_compatible_w_blockifier_tx branch from 6ab33b3 to f3a7c10 Compare November 4, 2024 17:39
Copy link

github-actions bot commented Nov 4, 2024

Artifacts upload triggered. View details here

Copy link

github-actions bot commented Nov 4, 2024

Benchmark movements:
full_committer_flow performance improved 😺
full_committer_flow time: [29.642 ms 29.689 ms 29.740 ms]
change: [-2.2144% -1.9735% -1.7229%] (p = 0.00 < 0.05)
Performance has improved.
Found 2 outliers among 100 measurements (2.00%)
2 (2.00%) high mild

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, 5 unresolved discussions (waiting on @avivg-starkware, @meship-starkware, and @noaov1)


crates/blockifier/src/transaction/transactions.rs line 715 at r5 (raw file):

    ) -> TransactionExecutionResult<Option<CallInfo>> {
        let class_hash = self.class_hash();
        let ctor_context = ConstructorContext {

Avoid abbreviations.

Suggestion:

let constructor_context = ConstructorContext {

crates/blockifier/src/transaction/transactions.rs line 852 at r5 (raw file):

    class_hash: ClassHash,
    compiled_class_hash: Option<CompiledClassHash>,
) -> TransactionExecutionResult<()> {

Document.

Suggestion:

/// Tries declaring a contract class i.e. setting the contract class at the state at the given class hash.
fn try_declare<S: State>(
    tx: &ExecutableDeclareTx,
    state: &mut S,
    class_hash: ClassHash,
    compiled_class_hash: Option<CompiledClassHash>,
) -> TransactionExecutionResult<()> {

crates/blockifier/src/transaction/transactions.rs line 852 at r5 (raw file):

    class_hash: ClassHash,
    compiled_class_hash: Option<CompiledClassHash>,
) -> TransactionExecutionResult<()> {

see that for the Declare struct in this file - try_declare is a method. There is code duplication here. Add a todo to delete it there (Or, can you please link the PR where the code duplication is resolved?)

Also, please do the same for other code duplications around this PR.

Code quote:

fn try_declare<S: State>(
    tx: &ExecutableDeclareTx,
    state: &mut S,
    class_hash: ClassHash,
    compiled_class_hash: Option<CompiledClassHash>,
) -> TransactionExecutionResult<()> {

crates/blockifier/src/transaction/transactions.rs line 872 at r5 (raw file):

fn contract_class(tx: &ExecutableDeclareTx) -> ContractClass {
    tx.class_info.contract_class.clone()
}

Can't this be a getter method of ExecutableDeclareTx? (i.e. update the code in Starknet API).

Code quote:

fn contract_class(tx: &ExecutableDeclareTx) -> ContractClass {
    tx.class_info.contract_class.clone()
}

crates/starknet_api/src/executable_transaction.rs line 232 at r5 (raw file):

        (signature, TransactionSignature),
        (version, TransactionVersion)
    );

TL;DR" move to top of impl block.

Align the order of calls with other impl blocks.

For DeployAccountTransaction and InvokeTransaction it is:

  1. implement_inner_tx_getter_calls,
  2. pub fn tx(&self) (no need to add this function if it is never used).
  3. create
  4. from_rpc_tx (Irrelevant for declare - long story).

Code quote:

    implement_inner_tx_getter_calls!(
        (class_hash, ClassHash),
        (nonce, Nonce),
        (sender_address, ContractAddress),
        (signature, TransactionSignature),
        (version, TransactionVersion)
    );

@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/make_execution_tx_compatible_w_blockifier_tx branch from f3a7c10 to dacda4c Compare November 5, 2024 14:46
Copy link
Contributor Author

@avivg-starkware avivg-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, @meship-starkware, and @noaov1)


crates/blockifier/src/transaction/transactions.rs line 715 at r5 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

Avoid abbreviations.

Done.


crates/blockifier/src/transaction/transactions.rs line 852 at r5 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

Document.

Done.


crates/blockifier/src/transaction/transactions.rs line 852 at r5 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

see that for the Declare struct in this file - try_declare is a method. There is code duplication here. Add a todo to delete it there (Or, can you please link the PR where the code duplication is resolved?)

Also, please do the same for other code duplications around this PR.

Yes, it is removed together with "DeclareTransaction" entire implementation in the following PR:
#1831


crates/blockifier/src/transaction/transactions.rs line 872 at r5 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

Can't this be a getter method of ExecutableDeclareTx? (i.e. update the code in Starknet API).

It can. See change


crates/starknet_api/src/executable_transaction.rs line 232 at r5 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

TL;DR" move to top of impl block.

Align the order of calls with other impl blocks.

For DeployAccountTransaction and InvokeTransaction it is:

  1. implement_inner_tx_getter_calls,
  2. pub fn tx(&self) (no need to add this function if it is never used).
  3. create
  4. from_rpc_tx (Irrelevant for declare - long story).

Done.

Copy link

github-actions bot commented Nov 5, 2024

Artifacts upload triggered. View details here

@ArniStarkware
Copy link
Contributor

crates/blockifier/src/transaction/transactions.rs line 858 at r6 (raw file):

        Err(StateError::UndeclaredClassHash(_)) => {
            // Class is undeclared; declare it.
            state.set_contract_class(class_hash, tx.contract_class().try_into()?)?;

Note to self. This is where the magic happens!
Nice.

Code quote:

contract_class().try_into()

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

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, 1 unresolved discussion (waiting on @avivg-starkware, @meship-starkware, and @noaov1)


crates/blockifier/src/transaction/transactions.rs line 848 at r6 (raw file):

/// Tries declaring a contract class i.e. setting the contract class at the state at the given class
/// hash.

ChatGPT suggests:

Suggestion:

/// Attempts to declare a contract class by setting the contract class in the state with the specified class hash.

@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/make_execution_tx_compatible_w_blockifier_tx branch from dacda4c to 71daa83 Compare November 5, 2024 16:28
Copy link
Contributor Author

@avivg-starkware avivg-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, 1 unresolved discussion (waiting on @ArniStarkware, @meship-starkware, and @noaov1)


crates/blockifier/src/transaction/transactions.rs line 848 at r6 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

ChatGPT suggests:

Done.

Copy link

github-actions bot commented Nov 5, 2024

Artifacts upload triggered. View details here

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: 2 of 3 files reviewed, all discussions resolved (waiting on @meship-starkware and @noaov1)

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

Copy link
Contributor

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

Reviewed 1 of 2 files at r5, 1 of 2 files at r6, 1 of 1 files at r7, all commit messages.
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 1 of 2 files at r5, 1 of 2 files at r6, 1 of 1 files at r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @avivg-starkware)

Copy link
Contributor

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

@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/make_execution_tx_compatible_w_blockifier_tx branch from 71daa83 to 758f49b Compare November 10, 2024 10:26
Copy link

Artifacts upload triggered. View details here

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

Copy link
Contributor

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

Reviewed 2 of 2 files at r8, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @avivg-starkware)

@avivg-starkware avivg-starkware merged commit 6f73317 into main Nov 11, 2024
15 checks passed
@avivg-starkware avivg-starkware deleted the avivg/blockifier/make_execution_tx_compatible_w_blockifier_tx branch November 11, 2024 11:20
@github-actions github-actions bot locked and limited conversation to collaborators Nov 13, 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