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
SerializedPublicKey
#1095
Comments
From the other thread:
The more we discussed In the context of I think it might be best to go over what bitcoin:PublicKey does/doesn't do and what SerializedPublicKey should/shouldn't do. Just because it's not really a debate I'll start off with listing what bitcoin::PublicKey does/doesn't do.
If we can agree on this, I would be interested in everyone's thoughts on what a potential SerializedPublicKey should/shouldn't do/be. It seems like the main point of change is But what kinds of methods / properties should it have and why would that be useful? (psuedo-code examples of a short use case might help visualize) |
Bear in mind that we could obviously implement Validating/deserializing a public key, to contrast, is around 7 microseconds, so 30x slower. I think your summary is good @junderw. The benefit of I think Core's behavior is dumb but the performance benefit is undeniable. |
@junderw nice list of properties!
For me it's just avoiding allocation in serialization.
I never intended to use it for anything else but if people will find it useful I'm open to hash methods and perhaps even constructing it with light validation (would need discussion later). I propose to only implement minimal API for now, until people actually need more:
Agreed and interestingly there's a case where something like this is actually preferred: in Lightning it's much better to process graph without key (node ID) validation. But the keys there are always compressed, so this is out-of-scope here. |
Ah, I understand, I missed the fact that serialization in our current API requires allocation, and that Not to add another point of argument, but I wonder whether |
Isn't to_bytes the only allocation? |
@junderw yes...and it is the only way to get a serialized public key. |
@apoelstra AFAIR rust-secp doesn't provide any serialization with dynamic length but an argument could be made that it could be handy for some people. @junderw yes. |
@Kixunil we do actually, we have a |
Sorry, I meant serialization of a key. |
There was discussion in #1084 about what should this type do. My intention was (and still is) for it to be just a bunch of bytes just like
Box<[u8]>
without heap allocation - a replacement forVec<u8>
returned fromto_bytes()
. The original idea was solely to improve serialization performance by avoiding allocations and perhaps allow no-alloc in the future.There were some ideas that it could do something more. Methods for hashing seem reasonable to me but there are even more exotic ideas that I don't find appealing.
Example implementation of my idea
The text was updated successfully, but these errors were encountered: