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(starknet_api): add contract class version to sierra contract #2277

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

AvivYossef-starkware
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link

Benchmark movements:
tree_computation_flow performance regressed!
tree_computation_flow time: [34.686 ms 35.151 ms 35.703 ms]
change: [+1.1239% +2.6890% +4.1730%] (p = 0.00 < 0.05)
Performance has regressed.
Found 15 outliers among 100 measurements (15.00%)
2 (2.00%) high mild
13 (13.00%) high severe

full_committer_flow performance regressed!
full_committer_flow time: [30.999 ms 31.042 ms 31.087 ms]
change: [+3.8548% +4.0589% +4.2750%] (p = 0.00 < 0.05)
Performance has regressed.
Found 4 outliers among 100 measurements (4.00%)
4 (4.00%) high mild

@AvivYossef-starkware AvivYossef-starkware force-pushed the aviv/refactor_sn_api_contract_class_name branch 2 times, most recently from 975b893 to 90127f0 Compare November 26, 2024 07:12
@AvivYossef-starkware AvivYossef-starkware force-pushed the aviv/refactor_sierra_contract_class branch from 1e1106a to 08e4ae7 Compare November 26, 2024 07:12
Copy link

Benchmark movements:
full_committer_flow performance regressed!
full_committer_flow time: [31.248 ms 31.311 ms 31.378 ms]
change: [+2.8388% +3.1636% +3.4451%] (p = 0.00 < 0.05)
Performance has regressed.
Found 3 outliers among 100 measurements (3.00%)
2 (2.00%) high mild
1 (1.00%) high severe

@AvivYossef-starkware AvivYossef-starkware force-pushed the aviv/refactor_sn_api_contract_class_name branch 2 times, most recently from d7f67f0 to 8b84db9 Compare November 26, 2024 07:40
@AvivYossef-starkware AvivYossef-starkware force-pushed the aviv/refactor_sierra_contract_class branch from 08e4ae7 to dba785d Compare November 26, 2024 07:58
Copy link

Benchmark movements:
full_committer_flow performance regressed!
full_committer_flow time: [30.963 ms 31.041 ms 31.158 ms]
change: [+3.5667% +3.9101% +4.3478%] (p = 0.00 < 0.05)
Performance has regressed.
Found 5 outliers among 100 measurements (5.00%)
4 (4.00%) high mild
1 (1.00%) high severe

@AvivYossef-starkware AvivYossef-starkware changed the base branch from aviv/refactor_sn_api_contract_class_name to graphite-base/2277 November 26, 2024 08:24
@AvivYossef-starkware AvivYossef-starkware force-pushed the aviv/refactor_sierra_contract_class branch from dba785d to d9a5dec Compare November 26, 2024 08:24
@AvivYossef-starkware AvivYossef-starkware changed the base branch from graphite-base/2277 to main November 26, 2024 08:24
@AvivYossef-starkware AvivYossef-starkware force-pushed the aviv/refactor_sierra_contract_class branch from d9a5dec to 851feac Compare November 26, 2024 08:24
Copy link
Collaborator

@Yoni-Starkware Yoni-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 6 files reviewed, 3 unresolved discussions (waiting on @AvivYossef-starkware)


crates/papyrus_storage/src/serialization/serializers.rs line 986 at r1 (raw file):

            )?,
            abi: String::deserialize_from(&mut decompress_from_reader(bytes)?.as_slice())?,
            contract_class_version: String::deserialize_from(bytes)?,

Seems like you need to keep the order here

Code quote:

    fn deserialize_from(bytes: &mut impl std::io::Read) -> Option<Self> {
        Some(Self {
            sierra_program: Vec::<Felt>::deserialize_from(
                &mut decompress_from_reader(bytes)?.as_slice(),
            )?,
            entry_points_by_type: HashMap::<EntryPointType, Vec<EntryPoint>>::deserialize_from(
                bytes,
            )?,
            abi: String::deserialize_from(&mut decompress_from_reader(bytes)?.as_slice())?,
            contract_class_version: String::deserialize_from(bytes)?,

crates/starknet_api/src/state.rs line 218 at r1 (raw file):

    pub entry_points_by_type: HashMap<EntryPointType, Vec<EntryPoint>>,
    pub abi: String,
    pub contract_class_version: String,

To be consistent with the compiler's struct

Suggestion:

    pub sierra_program: Vec<Felt>,
    pub contract_class_version: String,
    pub entry_points_by_type: HashMap<EntryPointType, Vec<EntryPoint>>,
    pub abi: String,

crates/papyrus_storage/src/utils_test.rs line 34 at r1 (raw file):

            ClassHash(i_felt),
            SierraContractClass {
                contract_class_version: "".to_string(),

Let it be "0.1.0"

Code quote:

"".to_string(),

Copy link
Contributor Author

@AvivYossef-starkware AvivYossef-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 6 files reviewed, 3 unresolved discussions (waiting on @Yoni-Starkware)


crates/papyrus_storage/src/serialization/serializers.rs line 986 at r1 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Seems like you need to keep the order here

the order of the fields?

Copy link

Benchmark movements:
tree_computation_flow performance regressed!
tree_computation_flow time: [34.681 ms 35.153 ms 35.707 ms]
change: [+1.4530% +2.8518% +4.6847%] (p = 0.00 < 0.05)
Performance has regressed.
Found 17 outliers among 100 measurements (17.00%)
2 (2.00%) high mild
15 (15.00%) high severe

full_committer_flow performance regressed!
full_committer_flow time: [30.886 ms 30.924 ms 30.964 ms]
change: [+3.6661% +3.8536% +4.0388%] (p = 0.00 < 0.05)
Performance has regressed.
Found 2 outliers among 100 measurements (2.00%)
1 (1.00%) high mild
1 (1.00%) high severe

Copy link
Collaborator

@Yoni-Starkware Yoni-Starkware left a comment

Choose a reason for hiding this comment

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

Are you removing the duplicated object in a separate PR?

Reviewed all commit messages.
Reviewable status: 0 of 6 files reviewed, 3 unresolved discussions (waiting on @AvivYossef-starkware)

@AvivYossef-starkware AvivYossef-starkware force-pushed the aviv/refactor_sierra_contract_class branch from 851feac to 2295fe7 Compare November 26, 2024 08:42
Copy link
Contributor Author

@AvivYossef-starkware AvivYossef-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 7 files reviewed, 3 unresolved discussions (waiting on @Yoni-Starkware)


crates/papyrus_storage/src/utils_test.rs line 34 at r1 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Let it be "0.1.0"

Done.


crates/starknet_api/src/state.rs line 218 at r1 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

To be consistent with the compiler's struct

Done.

Copy link

codecov bot commented Nov 26, 2024

Codecov Report

Attention: Patch coverage is 7.69231% with 12 lines in your changes missing coverage. Please review.

Project coverage is 61.52%. Comparing base (e3165c4) to head (15764ce).
Report is 595 commits behind head on main.

Files with missing lines Patch % Lines
crates/papyrus_protobuf/src/converters/class.rs 0.00% 9 Missing ⚠️
...s/papyrus_storage/src/serialization/serializers.rs 0.00% 0 Missing and 2 partials ⚠️
crates/starknet_client/src/reader/objects/state.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2277       +/-   ##
===========================================
+ Coverage   40.10%   61.52%   +21.41%     
===========================================
  Files          26       85       +59     
  Lines        1895    10354     +8459     
  Branches     1895    10354     +8459     
===========================================
+ Hits          760     6370     +5610     
- Misses       1100     3056     +1956     
- Partials       35      928      +893     

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

Copy link
Collaborator

@Yoni-Starkware Yoni-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: 0 of 7 files reviewed, 6 unresolved discussions (waiting on @AvivYossef-starkware)


crates/papyrus_storage/src/utils.rs line 26 at r2 (raw file):

#[derive(Serialize)]
struct DumpDeclaredClass {

Can you ask @DvirYo-starkware what is this class and why it's missing the string ABI?

Code quote:

#[derive(Serialize)]
struct DumpDeclaredClass {

crates/papyrus_storage/src/utils.rs line 31 at r2 (raw file):

    compiled_class_hash: CompiledClassHash,
    sierra_program: Vec<Felt>,
    entry_points_by_type: HashMap<EntryPointType, Vec<EntryPoint>>,

Keep the order consistent

Suggestion:

struct DumpDeclaredClass {
    class_hash: ClassHash,
    compiled_class_hash: CompiledClassHash,
    sierra_program: Vec<Felt>,
    contract_class_version: String,
    entry_points_by_type: HashMap<EntryPointType, Vec<EntryPoint>>,

crates/papyrus_storage/src/utils.rs line 82 at r2 (raw file):

                            compiled_class_hash: *compiled_class_hash,
                            sierra_program: contract_class.sierra_program.clone(),
                            entry_points_by_type: contract_class.entry_points_by_type.clone(),

Suggestion:

                        &DumpDeclaredClass {
                            class_hash: *class_hash,
                            compiled_class_hash: *compiled_class_hash,
                            sierra_program: contract_class.sierra_program.clone(),
                            contract_class_version: contract_class.contract_class_version.clone(),
                            entry_points_by_type: contract_class.entry_points_by_type.clone(),

Copy link
Collaborator

@Yoni-Starkware Yoni-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 7 files reviewed, 5 unresolved discussions (waiting on @AvivYossef-starkware)


crates/papyrus_storage/src/serialization/serializers.rs line 986 at r1 (raw file):

Previously, AvivYossef-starkware wrote…

the order of the fields?

Yes


crates/starknet_client/src/reader/objects/state.rs line 71 at r2 (raw file):

            contract_class_version: class.contract_class_version,
            sierra_program: class.sierra_program,
            entry_points_by_type: class.entry_points_by_type,

Suggestion:

        Self {
            sierra_program: class.sierra_program,
            contract_class_version: class.contract_class_version,
            entry_points_by_type: class.entry_points_by_type,

crates/papyrus_test_utils/src/lib.rs line 503 at r2 (raw file):

        pub entry_points_by_type: HashMap<EntryPointType, Vec<EntryPoint>>,
        pub abi: String,
        pub contract_class_version: String,

Suggestion:

    pub struct SierraContractClass {
        pub sierra_program: Vec<Felt>,
        pub contract_class_version: String,
        pub entry_points_by_type: HashMap<EntryPointType, Vec<EntryPoint>>,
        pub abi: String,

Copy link

Benchmark movements:
full_committer_flow performance regressed!
full_committer_flow time: [31.296 ms 31.388 ms 31.501 ms]
change: [+2.5449% +3.3163% +4.0026%] (p = 0.00 < 0.05)
Performance has regressed.
Found 4 outliers among 100 measurements (4.00%)
2 (2.00%) high mild
2 (2.00%) high severe

@AvivYossef-starkware AvivYossef-starkware force-pushed the aviv/refactor_sierra_contract_class branch from 2295fe7 to 3893a27 Compare November 26, 2024 09:08
Copy link
Contributor Author

@AvivYossef-starkware AvivYossef-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 7 files reviewed, 5 unresolved discussions (waiting on @Yoni-Starkware)


crates/papyrus_storage/src/utils.rs line 31 at r2 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Keep the order consistent

Done.


crates/papyrus_storage/src/utils.rs line 82 at r2 (raw file):

                            compiled_class_hash: *compiled_class_hash,
                            sierra_program: contract_class.sierra_program.clone(),
                            entry_points_by_type: contract_class.entry_points_by_type.clone(),

Done.


crates/papyrus_test_utils/src/lib.rs line 503 at r2 (raw file):

        pub entry_points_by_type: HashMap<EntryPointType, Vec<EntryPoint>>,
        pub abi: String,
        pub contract_class_version: String,

Done.


crates/starknet_client/src/reader/objects/state.rs line 71 at r2 (raw file):

            contract_class_version: class.contract_class_version,
            sierra_program: class.sierra_program,
            entry_points_by_type: class.entry_points_by_type,

Done.

Copy link

Benchmark movements:
full_committer_flow performance regressed!
full_committer_flow time: [31.012 ms 31.150 ms 31.332 ms]
change: [+3.9397% +4.4521% +5.0547%] (p = 0.00 < 0.05)
Performance has regressed.
Found 7 outliers among 100 measurements (7.00%)
1 (1.00%) high mild
6 (6.00%) high severe

Copy link
Collaborator

@Yoni-Starkware Yoni-Starkware left a comment

Choose a reason for hiding this comment

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

Don't forget to delete RpcContractClass :lgtm:

Reviewed 1 of 6 files at r1, 2 of 4 files at r2, 4 of 4 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @AvivYossef-starkware)

Copy link
Collaborator

@Yoni-Starkware Yoni-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 @AvivYossef-starkware)


crates/papyrus_storage/src/utils.rs line 26 at r2 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Can you ask @DvirYo-starkware what is this class and why it's missing the string ABI?

Non blocking

Copy link
Contributor

@DvirYo-starkware DvirYo-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 6 files at r1, 3 of 4 files at r2, 3 of 4 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @AvivYossef-starkware)


crates/papyrus_storage/src/utils.rs line 26 at r2 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Non blocking

The struct DumpDeclaredClass can be deleted. I will delete it in a different PR.


crates/papyrus_storage/src/serialization/serializers.rs line 972 at r3 (raw file):

    fn serialize_into(&self, res: &mut impl std::io::Write) -> Result<(), StorageSerdeError> {
        serialize_and_compress(&self.sierra_program)?.serialize_into(res)?;
        self.contract_class_version.serialize_into(res)?;

This is a breaking change to the storage. We should discuss this.
A few months ago, we decided to break the storage in version 13.3. I don't know what was agreed upon about the storage in 13.3 and 13.4, but it is fine if we break the storage in 13.4.


crates/papyrus_protobuf/src/converters/class.rs line 209 at r3 (raw file):

        let sierra_program =
            value.program.into_iter().map(Felt::try_from).collect::<Result<Vec<_>, _>>()?;

Make sure with @ShahakShama it is fine (I don't think should be a problem here)

Copy link
Contributor Author

@AvivYossef-starkware AvivYossef-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 @Yoni-Starkware)


crates/papyrus_storage/src/serialization/serializers.rs line 972 at r3 (raw file):

Previously, DvirYo-starkware wrote…

This is a breaking change to the storage. We should discuss this.
A few months ago, we decided to break the storage in version 13.3. I don't know what was agreed upon about the storage in 13.3 and 13.4, but it is fine if we break the storage in 13.4.

I think that we initialize papyrus with each new version, right? @Yoni-Starkware

Copy link
Contributor Author

@AvivYossef-starkware AvivYossef-starkware left a comment

Choose a reason for hiding this comment

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

Just two more PRS to reach it.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Yoni-Starkware)

Copy link
Collaborator

@Yoni-Starkware Yoni-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 @DvirYo-starkware)


crates/papyrus_storage/src/serialization/serializers.rs line 972 at r3 (raw file):

Previously, AvivYossef-starkware wrote…

I think that we initialize papyrus with each new version, right? @Yoni-Starkware

@AvivYossef-starkware not necessarily but we would have to do this for this version since we need all the Sierra classes. So LGTM

Copy link
Contributor

@ShahakShama ShahakShama 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 @AvivYossef-starkware and @DvirYo-starkware)


crates/papyrus_protobuf/src/converters/class.rs line 209 at r3 (raw file):

Previously, DvirYo-starkware wrote…

Make sure with @ShahakShama it is fine (I don't think should be a problem here)

Now the conversion to protobuf isn't the inverse of the conversion from protobuf. Fix the other conversion (I'll put a comment there


crates/papyrus_protobuf/src/converters/class.rs line 292 at r3 (raw file):

        });

        let contract_class_version = format!(

Remove this, and extract the contract_class_version from value instead

@AvivYossef-starkware AvivYossef-starkware force-pushed the aviv/refactor_sierra_contract_class branch from 3893a27 to 2333708 Compare November 26, 2024 13:55
Copy link
Contributor Author

@AvivYossef-starkware AvivYossef-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: 6 of 7 files reviewed, 2 unresolved discussions (waiting on @DvirYo-starkware, @ShahakShama, and @Yoni-Starkware)


crates/papyrus_protobuf/src/converters/class.rs line 292 at r3 (raw file):

Previously, ShahakShama wrote…

Remove this, and extract the contract_class_version from value instead

Thanks, consider adding a test to enforce this.

Copy link

Benchmark movements:
tree_computation_flow performance regressed!
tree_computation_flow time: [34.484 ms 34.939 ms 35.470 ms]
change: [+2.7731% +4.0558% +5.8548%] (p = 0.00 < 0.05)
Performance has regressed.
Found 12 outliers among 100 measurements (12.00%)
5 (5.00%) high mild
7 (7.00%) high severe

Copy link
Contributor

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


crates/papyrus_protobuf/src/converters/class.rs line 292 at r3 (raw file):

Previously, AvivYossef-starkware wrote…

Thanks, consider adding a test to enforce this.

There's a TODO to add that test (FYI @noamsp-starkware )

Copy link
Contributor

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

@AvivYossef-starkware AvivYossef-starkware merged commit 0131a00 into main Nov 27, 2024
20 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 29, 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