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

Implement Hash for schnorrsig::Signature #335

Merged
merged 1 commit into from
Nov 5, 2021

Conversation

elsirion
Copy link
Contributor

@elsirion elsirion commented Oct 19, 2021

I pondered putting the impl into the array type macro together with (Partial)Eq, but that would have meant removing other implementations and potentially implementing it for types where it is not wanted. The drawback of the separate impl is that it is more disconnected from the (Partial)Eq impl and could theoretically diverge (although unlikely in case of such a simple type) which would break the trait's contract.

Comment on lines 23 to 28
impl std::hash::Hash for Signature {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.0.hash(state)
}
}

Copy link
Member

Choose a reason for hiding this comment

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

Why not derive it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I recently learned that it is considered harmful to derive Hash/PartialEq and hand-implement the other and clippy complains about that (not sure if it would here, the PartialEq impl is behind a macro). The other question would be: why not derive most of the stuff currently in impl_array_newtype!?

Copy link
Member

Choose a reason for hiding this comment

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

Great question :)

Copy link
Member

Choose a reason for hiding this comment

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

Because the stuff in impl_array_newtype needs to apply to array sizes for which derive does not work.

Why impl Hash here but not in impl_array_newtype?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why impl Hash here but not in impl_array_newtype?

There already were some custom impls, updated the PR to remove them and instead implement Hash in the macro.

@elsirion elsirion force-pushed the 2021-10-hash-schnorr-sig branch from 37b9d77 to bac7890 Compare November 4, 2021 14:49
@apoelstra
Copy link
Member

cargo build --no-default-features --features='lowmemory recovery' fails for me.

* implements `Hash` as part of the newtype macro
* removes type-specific implementations
@elsirion elsirion force-pushed the 2021-10-hash-schnorr-sig branch from bac7890 to 75b49ef Compare November 4, 2021 21:17
@elsirion
Copy link
Contributor Author

elsirion commented Nov 4, 2021

Right, didn't think of nostd 😅

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 75b49ef

@apoelstra apoelstra merged commit 96d2242 into rust-bitcoin:master Nov 5, 2021
@thomaseizinger
Copy link
Contributor

Note: This was actually a breaking change because the macro is publicly exported. We are using it in https://github.com/ElementsProject/rust-secp256k1-zkp where it broken the build because we are adding those Hash implementations manually.

Not a big deal as it is easily fixed but something worth considering for the future. Should we export this macro? Should we not use it in https://github.com/ElementsProject/rust-secp256k1-zkp for types where we could derive things? It feels a bit like a "god"-macro to me that gets slapped on most newtypes without considering, what we actually need. Perhaps we should modularise this a bit more.

@apoelstra
Copy link
Member

Lol, oops. I think we shouldn't export it.

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.

4 participants