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

Improve hashes trait method usage #2714

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tcharding
Copy link
Member

Done as part of the ongoing work to improve the hashes API.

  • Patch 1: Use concrete type when calling all_zeros instead of the trait method.
  • Patch 2: Clean up p2p unit test imports (preparation for next patch)
  • Patch 3: Use as _ when importing Hash and HashEngine

This whole PR is refactor only, no logic changes.

Currently we use the `Hash` trait in a bunch of places to call
`all_zeros`. We are attempting to improve the `hashes` API and this
usage is both unnecessary and also hindering that effort.

Use the concrete type (e.g. `BlockHash`) instead of calling through the
trait method.

Refactor only, no logic changes.
@github-actions github-actions bot added C-bitcoin PRs modifying the bitcoin crate test labels Apr 24, 2024
@coveralls
Copy link

coveralls commented Apr 25, 2024

Pull Request Test Coverage Report for Build 8855222593

Details

  • 26 of 28 (92.86%) changed or added relevant lines in 8 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.002%) to 83.129%

Changes Missing Coverage Covered Lines Changed/Added Lines %
bitcoin/src/consensus/encode.rs 3 4 75.0%
bitcoin/src/internal_macros.rs 2 3 66.67%
Totals Coverage Status
Change from base Build 8849264030: -0.002%
Covered Lines: 19192
Relevant Lines: 23087

💛 - Coveralls

@@ -308,7 +308,7 @@ mod test {

use hex::{test_hex_unwrap as hex, FromHex};

use super::{AddrV2, AddrV2Message, Address};
use super::*;
Copy link
Member

Choose a reason for hiding this comment

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

In 9c47158:

There are still more explicit imports you need to drop if you add super::*.

Copy link
Member Author

Choose a reason for hiding this comment

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

Bother, thanks - I'll re-look.

Copy link
Member

Choose a reason for hiding this comment

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

You might need to compile with nightly, and possibly nightly from a week ago, because I believe they just reverted a bunch of the "redundant import" lints due to mass protests.

Clean up the test imports in the `p2p` module:

- Use `use super::*` as is conventional.
- Use `sha256d::Hash` as is conventional.

Refactor, no logic changes.
@tcharding tcharding force-pushed the 04-25-stop-using-hashes-by-name branch from a3a7389 to 621ff28 Compare April 26, 2024 23:00
@tcharding
Copy link
Member Author

tcharding commented Apr 26, 2024

Force push is the PR done properly this time:

  • Fix all the p2p test imports (using nightly as suggested).
  • Fix all the Hash and HashEngine imports, seems my grep was broken the other day.

Bringing traits into scope risks naming conflicts for no real reason
because we can import traits using `as _`.

Also, in `hashes` we always use `as _` so `bitcoin` and `hashes` are
currently non-uniform.

Use as-underscore when importing the `Hash` and `HashEngine` traits.

Refactor, no logic changes.
@tcharding tcharding force-pushed the 04-25-stop-using-hashes-by-name branch from 621ff28 to 9e924cf Compare April 26, 2024 23:03
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 test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants