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

Implement ArbitraryOrd for relative::LockTime #2581

Merged
merged 2 commits into from Apr 2, 2024

Conversation

tcharding
Copy link
Member

TL;DR As we do for absolute::LockTime and for the same reasons; implement ArbitraryOrd for relative::LockTime.

locktimes do not have a semantic ordering if they differ (blocks, time) so we do not derive Ord however it is useful for downstream to be able to order structs that contain lock times. This is exactly what the ArbitraryOrd trait is for.

Fix: #2566

@github-actions github-actions bot added the C-bitcoin PRs modifying the bitcoin crate label Mar 13, 2024
@tcharding tcharding added 1.0 Issues and PRs required or helping to stabilize the API and removed 1.0 Issues and PRs required or helping to stabilize the API labels Mar 13, 2024
@coveralls
Copy link

coveralls commented Mar 13, 2024

Pull Request Test Coverage Report for Build 8513797817

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 9 (0.0%) changed or added relevant lines in 1 file are covered.
  • 716 unchanged lines in 20 files lost coverage.
  • Overall coverage decreased (-0.09%) to 83.136%

Changes Missing Coverage Covered Lines Changed/Added Lines %
bitcoin/src/blockdata/locktime/relative.rs 0 9 0.0%
Files with Coverage Reduction New Missed Lines %
bitcoin/src/p2p/message.rs 2 92.46%
bitcoin/src/consensus/params.rs 3 0.0%
bitcoin/src/bip32.rs 4 87.7%
bitcoin/src/blockdata/locktime/relative.rs 6 57.06%
base58/src/error.rs 7 2.56%
hashes/src/lib.rs 9 52.78%
units/src/parse.rs 13 55.1%
bitcoin/src/internal_macros.rs 15 65.74%
bitcoin/src/blockdata/witness.rs 17 88.93%
bitcoin/src/consensus/mod.rs 19 31.34%
Totals Coverage Status
Change from base Build 8427789763: -0.09%
Covered Lines: 19093
Relevant Lines: 22966

💛 - Coveralls

@tcharding tcharding added this to the 0.32.0 milestone Mar 14, 2024
apoelstra
apoelstra previously approved these changes Mar 14, 2024
Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 11867db

@tcharding
Copy link
Member Author

Rebase only, no other changes.

apoelstra
apoelstra previously approved these changes Mar 20, 2024
Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 53c5d4f

@tcharding
Copy link
Member Author

Forgot to comment yesterday, IIRC I fixed the rustdoc so its the same in both absolute and relative. Also at some stage I thought it a good idea to remove the PartialOrd impl, but then realized I was wrong. Not sure if that was ever pushed up but FTR both locktimes still implement PartialOrd (and now also implement ArbitraryOrd).

@apoelstra
Copy link
Member

The comma after "incommensurate" should be a semicolon.

@tcharding
Copy link
Member Author

You mean you want the sentence changed to this?

/// Locktimes may be height- or time-based, and these metrics are incommensurate; there
/// is no total ordering on locktimes.

Currently it is:

/// Because locktimes may be height- or time-based, and these metrics are incommensurate, there
/// is no total ordering on locktimes

(I repeatedly have to look up how to use semi-colons, I did so again last week.)

@apoelstra
Copy link
Member

Yep, exactly.

TL;DR As we do for `absolute::LockTime` and for the same reasons;
implement `ArbitraryOrd` for `relative::LockTime`.

locktimes do not have a semantic ordering if they differ (blocks, time)
so we do not derive `Ord` however it is useful for downstream to be able
to order structs that contain lock times. This is exactly what the
`ArbitraryOrd` trait is for.

Update the rustdocs in `relative` and mirror the docs changes in
`absolute`.

Fix: rust-bitcoin#2566
@tcharding
Copy link
Member Author

Done!

apoelstra
apoelstra previously approved these changes Mar 26, 2024
Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 3520f55

@tcharding tcharding added the P-high High priority label Mar 27, 2024
sanket1729
sanket1729 previously approved these changes Apr 1, 2024
Copy link
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

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

ACK 3520f55. ordered should be added to all features flags doccomment listed inlib.rs

@tcharding
Copy link
Member Author

Can do, thanks for the review!

Add "ordered" to the list of features in the `bitcoin` crate level docs.
@tcharding tcharding dismissed stale reviews from sanket1729 and apoelstra via d91cdd2 April 1, 2024 21:11
@tcharding
Copy link
Member Author

Added as a separate patch, will need re-acking now please @sanket1729

Copy link
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

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

ACK d91cdd2

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK d91cdd2

@apoelstra apoelstra merged commit 6a2fd96 into rust-bitcoin:master Apr 2, 2024
168 checks passed
@tcharding tcharding deleted the 03-13-arbitrary-ord branch April 2, 2024 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bitcoin PRs modifying the bitcoin crate P-high High priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

relative::LockTime should implement ordered::ArbitraryOrd
4 participants