-
Notifications
You must be signed in to change notification settings - Fork 10
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
Hash refactor #660
Conversation
firewood/src/hashednode.rs
Outdated
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]>>( |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was unused. Removed.
firewood/src/hashednode.rs
Outdated
/// 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![]; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
impl HashedNodeStore
because we don't actually use any of theHashedNodeStore
's fields.HashPreimage
. This generalizes the existing logic, which only knows how to hash a&Node
. I think this will be useful in implementing proofs.hasher
in instances where it's actually not necessarily a hasher (it could be a vec we're writing the node preimage into)