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

Default to forward for tagged hashes #2707

Merged
merged 5 commits into from May 7, 2024

Conversation

tcharding
Copy link
Member

@tcharding tcharding commented Apr 23, 2024

First three patches are preparation, improvements to the units tests in sha256t.

From the final patch:

Displaying backward is an anomaly of Bitcoin Core's early days and the
double SHA256 hash type. We should not let this unfortunate beast leak
out into other places.

Default to displaying forward when creating a new tagged hash and remove
all the explicit attributes from `bitcoin` that just clutter the code.

This is an API break and may quietly break some users downstream - eventually we should stop doing that sort of thing.

We do not test the schemars stuff in `hashes`, instead we do it in a
separate crate `extended_tests/schemars`. There is therefore no reason
to implement `schemars::JsonSchema` for the `TestHashTag`.
In the tagged hash unit tests we are testing two separate things in a
single test. To improve maintainability separate the test into two.

Refactor only, no test coverage change.
Add a unit test to verify that the forward/backward functionality of the
`sha256t_hash_newtype` works as advertised.
Displaying backward is an anomaly of Bitcoin Core's early days and the
double SHA256 hash type. We should not let this unfortunate beast leak
out into other places.

Default to displaying forward when creating a new tagged hash and remove
all the explicit attributes from `bitcoin` that just clutter the code.
@tcharding tcharding added the API break This PR requires a version bump for the next release label Apr 23, 2024
@github-actions github-actions bot added C-bitcoin PRs modifying the bitcoin crate C-hashes PRs modifying the hashes crate labels Apr 23, 2024
@coveralls
Copy link

coveralls commented Apr 23, 2024

Pull Request Test Coverage Report for Build 8978911818

Details

  • 8 of 8 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.04%) to 83.208%

Totals Coverage Status
Change from base Build 8973396166: 0.04%
Covered Lines: 19191
Relevant Lines: 23064

💛 - Coveralls

@apoelstra
Copy link
Member

Can you add some sort of migration instructions telling people they can add #[hash_newtype(backward)] to their structs if they want the old behavior?

I think this change is correct, even though it is theoretically an annoying break, because (I think) all tagged hashes are displayed forward.

@tcharding
Copy link
Member Author

Done, as a separate patch.

@github-actions github-actions bot added the doc label Apr 23, 2024
apoelstra
apoelstra previously approved these changes Apr 24, 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 f7e2b23

@tcharding tcharding added the one ack PRs that have one ACK, so one more can progress them label May 3, 2024
@tcharding
Copy link
Member Author

This one can go in now, acked for two weeks.


Note please this usage if you need to display backward:

```
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe syntax highlighting?

Suggested change
```
```rust

Copy link
Member

Choose a reason for hiding this comment

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

kek, and the 2-week timer is reset

But agreed, better to use the rust syntax highlighting.

Copy link
Member Author

Choose a reason for hiding this comment

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

Its in the changelog, who cares? Or if we do care, lets do it as a follow up. Waiting another two weeks just for this sucks balls.

Copy link
Member

Choose a reason for hiding this comment

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

Can you slip it in here?

I'll still ACK and (quickly) one-ACK merge. Agreed that a single nit about the CHANGELOG shouldn't reset the 2-week timer.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, no other changes.

Since the default display direction is now forward, use

  `#[hash_newtype(backward)]`

in the rustdocs on the macro. Also add an example usage to the changelog
in case someone downstream is relying on the old default behaviour of
displaying backwards (unlikely).
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 7685461

@apoelstra apoelstra merged commit 594eb18 into rust-bitcoin:master May 7, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API break This PR requires a version bump for the next release C-bitcoin PRs modifying the bitcoin crate C-hashes PRs modifying the hashes crate doc one ack PRs that have one ACK, so one more can progress them release notes mention
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants