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

feat(starknet_api): remove Ord and PartialOrd from TransactionVersion, implement explicit cmp #1638

Closed
wants to merge 1 commit into from

Conversation

dorimedini-starkware
Copy link
Collaborator

…, implement explicit cmp functions

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Collaborator Author

@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: 0 of 7 files reviewed, all discussions resolved (waiting on @noaov1)

a discussion (no related file):
Also removed many Ord, PartialOrd derives; the objects they were derived on don't seem to have a natural order. Unclear why these derives were needed...


Copy link

Artifacts upload triggered. View details here

@dorimedini-starkware dorimedini-starkware changed the title feat(starknet_api): remove Ord and PartialOrd from TransactionVersion… feat(starknet_api): remove Ord and PartialOrd from TransactionVersion, implement explicit cmp functions Oct 28, 2024
Copy link

Artifacts upload triggered. View details here

Copy link
Collaborator Author

@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: 0 of 7 files reviewed, all discussions resolved (waiting on @noaov1)


crates/starknet_api/src/transaction.rs line 862 at r1 (raw file):

    pub fn base_lt(&self, other: &Self) -> bool {
        self.without_query_bit().0 < other.without_query_bit().0

I can do self.base_le(other) && self.without_query_bit() != other.without_query_bit() but that would be 4 conversions instead of 2

Code quote:

self.without_query_bit().0 < other.without_query_bit().0

@dorimedini-starkware dorimedini-starkware force-pushed the dori/remove-order-from-tx-version branch from 33ecad3 to fdb0065 Compare October 28, 2024 20:41
@dorimedini-starkware dorimedini-starkware changed the title feat(starknet_api): remove Ord and PartialOrd from TransactionVersion, implement explicit cmp functions feat(starknet_api): remove Ord and PartialOrd from TransactionVersion, implement explicit cmp Oct 28, 2024
Copy link

Artifacts upload triggered. View details here

Copy link

Artifacts upload triggered. View details here

Copy link

codecov bot commented Oct 28, 2024

Codecov Report

Attention: Patch coverage is 96.55172% with 1 line in your changes missing coverage. Please review.

Project coverage is 73.39%. Comparing base (e3165c4) to head (a242b5c).
Report is 56 commits behind head on main.

Files with missing lines Patch % Lines
crates/starknet_api/src/transaction.rs 95.23% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1638       +/-   ##
===========================================
+ Coverage   40.10%   73.39%   +33.29%     
===========================================
  Files          26      163      +137     
  Lines        1895    21889    +19994     
  Branches     1895    21889    +19994     
===========================================
+ Hits          760    16066    +15306     
- Misses       1100     4611     +3511     
- Partials       35     1212     +1177     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it 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.

:lgtm:

Reviewed 7 of 7 files at r1, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @noaov1)

Copy link
Contributor

@giladchase giladchase left a comment

Choose a reason for hiding this comment

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

Note: this is a breaking change that might disrupt users who relied on the partialord behavior (like we did).
Can you involve product.

If this gets the OK, I still think it should be separated into two PRs, one removing unused derived and removing used derives with a replacement that explains why that order was chosen.

Reviewed 3 of 7 files at r1.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @dorimedini-starkware and @noaov1)

a discussion (no related file):

Previously, dorimedini-starkware wrote…

Also removed many Ord, PartialOrd derives; the objects they were derived on don't seem to have a natural order. Unclear why these derives were needed...

Orphan rule + legacy, if we don't implement PartialOrd/Ord then no-one can (except via newtypes), somebody probably added these all over SNAPI without thinking too much on whether or not it makes sense.
But you are right about the natural order.



crates/starknet_api/src/transaction.rs line 854 at r2 (raw file):

        let mut self_biguint = self.0.to_biguint();
        self_biguint.set_bit(QUERY_VERSION_BASE_BIT.into(), false);
        Self(self_biguint.into())

Seems to expensive for cmp, biguint is a Vec, can this done on the stack?
Also can you explain what base here means and about the query_version_base_bit?

Code quote:

        let mut self_biguint = self.0.to_biguint();
        self_biguint.set_bit(QUERY_VERSION_BASE_BIT.into(), false);
        Self(self_biguint.into())

Copy link
Contributor

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


crates/starknet_api/src/transaction.rs line 862 at r1 (raw file):

Previously, dorimedini-starkware wrote…

I can do self.base_le(other) && self.without_query_bit() != other.without_query_bit() but that would be 4 conversions instead of 2

Conversions aren't the issue, this allocates two vectors on the heap just to compare two fels

…, implement explicit cmp

Signed-off-by: Dori Medini <dori@starkware.co>
@dorimedini-starkware dorimedini-starkware force-pushed the dori/remove-order-from-tx-version branch from fdb0065 to a242b5c Compare October 29, 2024 09:25
Copy link

Artifacts upload triggered. View details here

Copy link
Collaborator Author

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

a discussion (no related file):
Closing this, and will implement a "natural" order on TransactionVersion (ZERO < ZERO_QUERY < ONE < ONE_QUERY ...)


@github-actions github-actions bot locked and limited conversation to collaborators Oct 31, 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