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

Hash refactor #660

Merged
merged 14 commits into from
Jun 24, 2024
Merged

Hash refactor #660

merged 14 commits into from
Jun 24, 2024

Conversation

danlaine
Copy link

  • Move hashing logic out of the impl HashedNodeStore because we don't actually use any of the HashedNodeStore's fields.
  • Add type HashPreimage. This generalizes the existing logic, which only knows how to hash a &Node. I think this will be useful in implementing proofs.
  • Renames hasher in instances where it's actually not necessarily a hasher (it could be a vec we're writing the node preimage into)

@danlaine danlaine self-assigned this May 23, 2024
@danlaine danlaine marked this pull request as ready for review May 24, 2024 16:59
hasher.update([value_exists]);
return;
/// Returns the SHA-256 hash of the `preimage`.
pub(crate) fn _hash<K: Iterator<Item = u8> + Clone, V: AsRef<[u8]>>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this _hash instead of hash?

Copy link
Author

Choose a reason for hiding this comment

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

It was unused. Removed.

/// Returns the serialized representation of `node` used as the pre-image
/// when hashing the node. The node is at the given `path_prefix`.
pub fn hash_preimage(node: &Node, path_prefix: &Path) -> Box<[u8]> {
let mut buf = vec![];
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Maybe vec::with_capacity(node.value.len()) or something to avoid reallocating the buffer every time.

Copy link
Author

Choose a reason for hiding this comment

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

Changed to pre-allocate capacity

@danlaine danlaine merged commit 2c7cd28 into remove-shale Jun 24, 2024
4 checks passed
@danlaine danlaine deleted the remove-shale-hash-refactor branch June 24, 2024 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants