8000 Rename `hash` module to `merkle_root` by tcharding · Pull Request #1334 · rust-bitcoin/rust-bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Rename hash module to merkle_root #1334

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

Merged
merged 3 commits into from
Nov 4, 2022

Conversation

tcharding
Copy link
Member
@tcharding tcharding commented Oct 20, 2022

Done as part of flattening util.

The util::hash module only provides two functions, both to calculate the merkle root of a list of hashes.

  1. Rename util::hash -> crate::merkle_root
  2. Change function names to calculate[_inline] so usage becomes merkle_root::calculate

Done as two separate patches so we can bikeshed the names, can squash if needed.

@tcharding tcharding force-pushed the 01-21-move-hash-module branch from 17d4fea to bc845d0 Compare October 20, 2022 23:48
@apoelstra
Copy link
Member

concept ACK. If #418 gets in before this one, those new functions should also live in the new merkle_root module.

apoelstra
apoelstra previously approved these changes Oct 21, 2022
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 bc845d08dc4917a1a2d5b54901507d7bbb506651

@tcharding
Copy link
Member Author

concept ACK. If #418 gets in before this one, those new functions should also live in the new merkle_root module.

#418 was merged two years ago ;) Did you mean #1321?

@apoelstra
Copy link
Member

Oops, yes. I blame github's # autocomplete :).

@Kixunil
Copy link
Collaborator
Kixunil commented Oct 25, 2022

How about module being named merkle_tree and functions being calculate_root?

@tcharding
Copy link
Member Author

I like it!

@tcharding
Copy link
Member Author

Renamed as suggested.

@apoelstra
Copy link
Member

CI failure is actually in master, sorry

@tcharding
Copy link
Member Author

No sweat, I'll fix it :)

@apoelstra
Copy link
Member

Sure -- though I have a fix that I'll push as soon as my local tests pass. (If you beat me to it, fine, I'll just test and ACK yours -- it's only a couple lines :))

@tcharding
Copy link
Member Author

#1346 whichever goes first :)

@tcharding tcharding force-pushed the 01-21-move-hash-module branch from e410555 to a7e74fc Compare October 28, 2022 00:00
@tcharding
Copy link
Member Author

Rebased on master, no other changes.

apoelstra
apoelstra previously approved these changes Oct 28, 2022
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 a7e74fc7355aab932fc68c4896593c982e5a320b

Kixunil
Kixunil previously approved these changes Oct 28, 2022
Copy link
Collaborator
@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK a7e74fc7355aab932fc68c4896593c982e5a320b

///
/// # Returns
/// - `None` if `hashes` is empty. The merkle root of an empty tree of hashes is undefined.
/// - `Some(hash)` if `hashes` contains one element. A single hash is by definition the merkle root.
/// - `Some(merkle_root)` if length of `hashes` is greater than one.
pub fn bitcoin_merkle_root_inline<T>(hashes: &mut [T]) -> Option<T>
pub fn calculate_root_inline<T>(hashes: &mut [T]) -> Option<T>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now that I see this I realize it'd be nice to explicitly state that the hashes are overwritten in the process. And perhaps state that the state we leave it in is undefined and must not be relied on.

8000 Copy link
Member

Choose a reason for hiding this comment

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

Agreed. Though FWIW taking a mutable slice implies that we'll overwrite stuff.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added some extra docs as an additional patch.

@@ -97,6 +96,34 @@ pub use crate::bip32;
#[deprecated(since = "0.30.0", note = "Please use crate::bip158")]
pub use crate::bip158;

/// The `hash` module was renamed to `../merkle_tree`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Although GH says "renamed" and we think of it as renaming, a more sensible representation is "removed and the merkle tree functions were moved to merkle_tree"

Copy link
Member Author

Choose a reason for hiding this comment

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

Noted, all thees "deprecated" messages should go away in a version or two so unless I re-spin for some other reason I'll leave this as is.

Copy link
Member Author
@tcharding tcharding Oct 28, 2022

Choose a reason for hiding this comment

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

Changed to: /// Functions from the hash module were renamed and moved to ../merkle_tree.

merkle_tree::calculate_root(hashes)
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Very good choice here finding them could be hard otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

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

Cheers!

The `util::hash` module provides two functions for computing a merkle
root from a list/iterator of hashes.

Rename the module to `merkle_root` and move it to the crate root,
deprecate the original functions.

Done as part of flattening the `util` module.
Recently we renamed the `hash` module to `merkle_root`, this makes the
public functions provided stutter if used with one layer of path as is
Rust convention:

 `merkle_root::bitcoin_merkle_root`

We can improve on this by renaming the functions to 'calculate', then we
get

- `merkle_root::calculate()`
- `merkle_root::calculate_inline()`
The function call `calculate_root_inline` calculates the merkle root
using the input array as a scratch buffer, i.e., we trash the data
during recursive calls to `merkle_root_r`.

Add explicit documentation to the function so its super clear not to use
the hashes again after calling this function.
@tcharding tcharding dismissed stale reviews from Kixunil and apoelstra via 29df410 October 28, 2022 20:52
@tcharding tcharding force-pushed the 01-21-move-hash-module branch from a7e74fc to 29df410 Compare October 28, 2022 20:52
@tcharding
Copy link
Member Author

Changes in force push:

  • rebased fixing trivial merge conflict
  • added additional patch with improved rustdocs

Copy link
Collaborator
@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK 29df410

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 29df410

@apoelstra apoelstra merged commit b271699 into rust-bitcoin:master Nov 4, 2022
@tcharding tcharding deleted the 01-21-move-hash-module branch November 7, 2022 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0