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): derive serde for transaction_execution_info #379

Merged
merged 1 commit into from
Aug 29, 2024

Conversation

aner-starkware
Copy link
Contributor

@aner-starkware aner-starkware commented Aug 11, 2024

This change is Reviewable

Copy link
Collaborator

@dorimedini-starkware dorimedini-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 5 of 5 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @aner-starkware, @meship-starkware, and @noaov1)

a discussion (no related file):
why?
what's the use case?


@aner-starkware
Copy link
Contributor Author

Previously, dorimedini-starkware wrote…

why?
what's the use case?

🤷, it's the assignment from github issues...

Copy link
Collaborator

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

a discussion (no related file):

Previously, aner-starkware wrote…

🤷, it's the assignment from github issues...

ah
ok then, please gate it behind a feature, so we verify we don't use this internally


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

a discussion (no related file):
In all open issues PRs, Ariel asked us to add @tdelabro


@aner-starkware
Copy link
Contributor Author

Previously, dorimedini-starkware wrote…

ah
ok then, please gate it behind a feature, so we verify we don't use this internally

What does that mean?

@aner-starkware
Copy link
Contributor Author

Previously, meship-starkware (Meshi Peled) wrote…

In all open issues PRs, Ariel asked us to add @tdelabro

Thanks.

Copy link
Collaborator

@dorimedini-starkware dorimedini-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 @aner-starkware, @noaov1, and @tdelabro)

a discussion (no related file):

Previously, aner-starkware wrote…

What does that mean?

  1. add a feature (call it, say, transaction_serde in the features section of the blockifier's cargo.toml
  2. use cfg_attr to conditionally derive (De)Serialize if the feature is active (see cfg_attr examples in the repo)

@tdelabro
Copy link

@aner-starkware you can take a look to widely used crate like: https://github.com/rust-num/num-bigint/blob/master/Cargo.toml

The Cargo.toml has a serde feature, and the serde crate is flaged as an optional dependency. Read carefully this section in order to understand how to specify those things correctly: https://doc.rust-lang.org/cargo/reference/features.html#optional-dependencies

Then instead of having #[derive(Serialize, Deserialize)] in your code you have instead

#[derive(Copy, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serizalize, serde::Deserialize)]
pub struct MyStruct {}

@TzahiTaub TzahiTaub force-pushed the aner/derive_serde_transaction_execution_info branch from 12a029c to 67b490b Compare August 21, 2024 17:53
Copy link
Contributor

@TzahiTaub TzahiTaub left a comment

Choose a reason for hiding this comment

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

Reviewed 5 of 5 files at r1.
Reviewable status: 0 of 7 files reviewed, 3 unresolved discussions (waiting on @aner-starkware, @dorimedini-starkware, @noaov1, and @tdelabro)


crates/blockifier/Cargo.toml line 15 at r2 (raw file):

concurrency = []
jemalloc = ["dep:tikv-jemallocator"]
transaction_serde = []

AFAIU, no need for explicit dependencies as serde is a non-optional dependency already.

@TzahiTaub TzahiTaub force-pushed the aner/derive_serde_transaction_execution_info branch from 67b490b to 5c2652a Compare August 21, 2024 18:01
Copy link
Collaborator

@dorimedini-starkware dorimedini-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 7 files at r2, 6 of 6 files at r3, all commit messages.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on @aner-starkware, @noaov1, and @tdelabro)


crates/blockifier/src/execution/call_info.rs line 32 at r3 (raw file):

#[cfg_attr(test, derive(Clone))]
#[cfg_attr(feature = "transaction_serde", derive(Deserialize))]
#[derive(Debug, Default, Eq, PartialEq, Serialize)]

this is cleaner IMO; WDYT?
this way you only need to name the feature once

Suggestion:

use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use serde::Serialize;
use starknet_api::core::{ClassHash, ContractAddress, EthAddress, PatriciaKey};
use starknet_api::state::StorageKey;
use starknet_api::transaction::{EventContent, L2ToL1Payload};
use starknet_api::{felt, patricia_key};
use starknet_types_core::felt::Felt;

use crate::execution::entry_point::CallEntryPoint;
use crate::fee::gas_usage::get_message_segment_length;
use crate::state::cached_state::StorageEntry;

#[cfg_attr(feature = "transaction_serde", derive(serde::Deserialize))]
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)]
pub struct Retdata(pub Vec<Felt>);

#[macro_export]
macro_rules! retdata {
    ( $( $x:expr ),* ) => {
        Retdata(vec![$($x),*])
    };
}

#[cfg_attr(test, derive(Clone))]
#[cfg_attr(feature = "transaction_serde", derive(Deserialize))]
#[derive(Debug, Default, Eq, PartialEq, Serialize)]

crates/blockifier/src/execution/entry_point.rs line 8 at r3 (raw file):

use num_traits::{Inv, Zero};
#[cfg(feature = "transaction_serde")]
use serde::Deserialize;

see above

Code quote:

#[cfg(feature = "transaction_serde")]
use serde::Deserialize;

crates/blockifier/src/fee/actual_cost.rs line 3 at r3 (raw file):

use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
#[cfg(feature = "transaction_serde")]
use serde::{Deserialize, Serialize};

see above

Code quote:

#[cfg(feature = "transaction_serde")]
use serde::{Deserialize, Serialize};

crates/blockifier/src/state/cached_state.rs line 7 at r3 (raw file):

use indexmap::IndexMap;
#[cfg(feature = "transaction_serde")]
use serde::{Deserialize, Serialize};

see above

Code quote:

#[cfg(feature = "transaction_serde")]
use serde::{Deserialize, Serialize};

crates/blockifier/src/transaction/objects.rs line 7 at r3 (raw file):

use num_traits::Pow;
#[cfg(feature = "transaction_serde")]
use serde::Deserialize;

see above

Code quote:

#[cfg(feature = "transaction_serde")]
use serde::Deserialize;

@TzahiTaub TzahiTaub force-pushed the aner/derive_serde_transaction_execution_info branch from 5c2652a to 54b4df3 Compare August 22, 2024 07:54
Copy link
Contributor

@TzahiTaub TzahiTaub 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 7 files reviewed, 8 unresolved discussions (waiting on @aner-starkware, @dorimedini-starkware, @noaov1, and @tdelabro)


crates/blockifier/src/execution/call_info.rs line 32 at r3 (raw file):

Previously, dorimedini-starkware wrote…

this is cleaner IMO; WDYT?
this way you only need to name the feature once

Agree

Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware 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 5 of 5 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @noaov1)

Copy link

codecov bot commented Aug 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.59%. Comparing base (d80da28) to head (194066d).
Report is 201 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #379      +/-   ##
==========================================
+ Coverage   76.51%   76.59%   +0.07%     
==========================================
  Files         329      348      +19     
  Lines       34931    36771    +1840     
  Branches    34931    36771    +1840     
==========================================
+ Hits        26729    28165    +1436     
- Misses       5909     6283     +374     
- Partials     2293     2323      +30     

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

Copy link
Collaborator

@dorimedini-starkware dorimedini-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 @noaov1)

@TzahiTaub TzahiTaub force-pushed the aner/derive_serde_transaction_execution_info branch from 54b4df3 to 194066d Compare August 22, 2024 11:26
Copy link
Contributor

@TzahiTaub TzahiTaub 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 r5.
Reviewable status: all files reviewed (commit messages unreviewed), all discussions resolved (waiting on @noaov1)

Copy link
Contributor

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

Copy link
Collaborator

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

@TzahiTaub TzahiTaub merged commit 6f89ece into main Aug 29, 2024
16 checks passed
@TzahiTaub TzahiTaub deleted the aner/derive_serde_transaction_execution_info branch August 29, 2024 07:28
@github-actions github-actions bot locked and limited conversation to collaborators Aug 30, 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.

5 participants