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

Feature: handle all tx traces #330

Closed
wants to merge 17 commits into from
Closed

Feature: handle all tx traces #330

wants to merge 17 commits into from

Conversation

ftheirs
Copy link
Collaborator

@ftheirs ftheirs commented Aug 29, 2024

Problem: at the moment only Invoke transactions were supported

Solution: process traces and add type conversion for reverted Invoke transaction, DeployAccount, Declare and L1Handler

Issue Number: N/A

Type

  • feature
  • bugfix
  • dev (no functional changes, no API changes)
  • fmt (formatting, renaming)
  • build
  • docs
  • testing

Description

Breaking changes?

  • yes
  • no

@ftheirs ftheirs force-pushed the ft/handle_all_tx_traces branch 3 times, most recently from c87d216 to 618d446 Compare August 29, 2024 14:47
@ftheirs ftheirs marked this pull request as ready for review August 29, 2024 14:59
@@ -24,13 +22,35 @@ pub(crate) fn get_subcalled_contracts_from_tx_traces(traces: &[TransactionTraceW
ExecuteInvocation::Success(inv) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you only need the Success variant, consider using if let instead of match.

Copy link
Collaborator

@HermanObst HermanObst left a comment

Choose a reason for hiding this comment

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

@ftheirs please modularize all the different tx with each version.
see
starknet_rs_tx_to_internal_tx

@odesenfans odesenfans changed the title Ft/handle all tx traces Feature: handle all tx traces Aug 30, 2024
sn_core_tx: &starknet::core::types::Transaction,
provider: &JsonRpcClient<HttpTransport>,
block_number: u64,
) -> Result<blockifier::transaction::transaction_execution::Transaction, Box<dyn Error>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

For another PR, but we really need to return something better than Box<dyn Error> here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI The PR in #333 includes a ProveBlockError type which I was unable to avoid when converting to a function.

};

// TODO: improve this to avoid retrieving this twice. Already done in main.rs from prove_block
let starknet_contract_class = provider.get_class(BlockId::Number(block_number), class_hash).await?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you put the ClassInfo generation in a new function?

};

let flattened_sierra = generic_sierra_cc.clone().to_starknet_core_contract_class()?;
let contract_class = generic_sierra_cc.compile()?.get_blockifier_contract_class()?.clone();
Copy link
Contributor

Choose a reason for hiding this comment

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

There's (or at least should be) a to_blockifier_contract_class method that hides the clone.


// TODO: improve this to avoid retrieving this twice. Already done in main.rs from prove_block
let starknet_contract_class = provider.get_class(BlockId::Number(block_number), class_hash).await?;
let generic_sierra_cc = match starknet_contract_class {
Copy link
Contributor

Choose a reason for hiding this comment

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

To deal with the legacy/deprecated/Cairo0 (these are synonyms) contracts, you simply need to move the compilation code + conversion to Blockifier ContractClass here and do the appropriate thing for Cairo0 in the other arm of the match. Please resolve it in this PR.

}
Transaction::L1Handler(_tx) => {
unimplemented!("starknet_rs_tx_to_blockifier() with L1Handler txn");
Transaction::L1Handler(tx) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

As @HermanObst already suggested, please split every arm of this match into separate functions.

};

// TODO: Check Fee value
let fee = Fee(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the explorer, this seems to be correct. Replace the TODO by a comment saying that fees are 0 for L1 handler txs.

@ftheirs ftheirs force-pushed the ft/handle_all_tx_traces branch 2 times, most recently from b09e460 to cb60274 Compare August 30, 2024 16:42
Copy link
Collaborator

@HermanObst HermanObst left a comment

Choose a reason for hiding this comment

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

@ftheirs good job man!
one last comment: remove all the unwrap() that you are using in favor to correctly handle the errors.

In general, we never accept unwrap() as they can make the program panic, basically bypassing Rust safety.
We only accept if there is a comment, clearly explaining why a given unwrap() will never fail. But handling the error is better practice.

Sorry that I didnt catch it before

Copy link
Collaborator

@HermanObst HermanObst left a comment

Choose a reason for hiding this comment

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

Good job! LGTM

@ftheirs ftheirs requested a review from odesenfans September 2, 2024 12:00
@ftheirs ftheirs force-pushed the ft/handle_all_tx_traces branch from d1dc4ee to cfd80a1 Compare September 2, 2024 22:22
@ftheirs ftheirs force-pushed the ft/handle_all_tx_traces branch from cfd80a1 to c9627f5 Compare September 3, 2024 12:07
This was referenced Sep 3, 2024
@ftheirs
Copy link
Collaborator Author

ftheirs commented Sep 3, 2024

Closing this since it will be split in several PRs

@ftheirs ftheirs closed this Sep 3, 2024
@ftheirs ftheirs deleted the ft/handle_all_tx_traces branch September 26, 2024 17:55
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