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
Make uint types (un)serializable #511
Conversation
And keep the latest validation status on the store cache. NOTE: This commit depends on a rust-bitcoin fork with serializable uint types. A PR was sent upstream: rust-bitcoin/rust-bitcoin#511
And keep the latest validation status on the store cache. NOTE: This commit depends on a rust-bitcoin fork with serializable uint types. A PR was sent upstream: rust-bitcoin/rust-bitcoin#511
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.
utack
We don't use |
@elichai ah-ah, I see. It was working when I tried because serde_derive is in the dev-dependencies. Will look into changing that to use one of the existing macros. |
b5f0121
to
0e9672e
Compare
0e9672e
to
4a18151
Compare
And keep the latest validation status on the store cache. NOTE: This commit depends on a rust-bitcoin fork with serializable uint types. A PR was sent upstream: rust-bitcoin/rust-bitcoin#511
And keep the latest validation status on the store cache. NOTE: This commit depends on a rust-bitcoin fork with serializable uint types. A PR was sent upstream: rust-bitcoin/rust-bitcoin#511
Can you add a unit test which parses some fixed json vectors? And covers some error/edge cases? |
4a18151
to
7c519fd
Compare
@apoelstra Added some fixed vectors and error cases. Did you have any particular edge cases to test in mind? |
64a5961
to
c122645
Compare
And keep the latest validation status on the store cache. NOTE: This commit depends on a rust-bitcoin fork with serializable uint types. A PR was sent upstream: rust-bitcoin/rust-bitcoin#511
Is there anything else needed to get this through? :) |
And keep the latest validation status on the store cache. NOTE: This commit depends on a rust-bitcoin fork with serializable uint types. A PR was sent upstream: rust-bitcoin/rust-bitcoin#511
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.
What's the motivation for using our internal representation (64bit words) for the serde implementation? This could lead to some weird mixed-endianess in binary serde implementations and doesn't look pretty as json. I think treating these bignum types as byte arrays with a hex representations in human redable serde backends would be best if there are no other compatibility requirements.
Also: travis doesn't seem happy, something failed for rust 1.29.0.
6d089b2
to
1e9705a
Compare
@sgeisler No particular reason, I like hex representation better too. I changed to it and fixed compatibility with Rust 1.29. (forced-pushed over the previous implementation, which is available for reference at I wasn't sure whether the new An alternative to adding |
Travis appears to be stuck due to some unrelated issue, it works on my fork. |
src/util/uint.rs
Outdated
S: $crate::serde::Serializer, | ||
{ | ||
use $crate::hashes::hex::ToHex; | ||
serializer.serialize_str(&self.to_be_bytes().to_hex()) |
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.
This appears to always serialize as a string, even if the output format is binary. This results in suboptimal encodings. We avoid this in other areas of the code by switching the encoding strategy based on the human readability.
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.
Agreed, implemented in d0eed01.
Testing this required introducing a new (dev only) dependency on a serde binary serializer (bincode). I wasn't sure if that's desirable or not so I kept it in a separate commit for now, will squash if it is.
And keep the latest validation status on the store cache. NOTE: This commit depends on a rust-bitcoin fork with serializable uint types. A PR was sent upstream: rust-bitcoin/rust-bitcoin#511
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.
Looks good now. I don't think a new dev-dependency is much of a problem, especially since it seems to build fine with 1.29.0.
ACK 1be22c3
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.
Sorry for being late, but I see space for further improvements over a type system here. Had a lot of issues with my own code when rust-bitcoin does not implement errors properly.
src/util/uint.rs
Outdated
); | ||
} | ||
|
||
construct_uint!(Uint256, 4); | ||
construct_uint!(Uint128, 2); | ||
|
||
/// Uint error | ||
#[derive(Debug)] |
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.
I think we can be opportunistic here, as Rust API guidelines suggest:
#[derive(Debug)] | |
#[derive(Debug, PartialEq, PartialOrd, Clone, Copy, 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.
Good point, I always forget theses derives myself 🙈 do you know if there is some way to warn about missing (standard) derives?
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.
Even if there is a way, I never heard of it :(
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.
Oh no, maybe clippy may help?
46acd77
to
0df86b4
Compare
I switched to a single-variant error type and implemented the suggested traits, apart from |
Not sure about |
That doesn't seem to be true? GitHub search returns 12 results for "impl error::Error": https://github.com/rust-bitcoin/rust-bitcoin/search?q=%22impl+error%3A%3AError%22 (and that might be missing some where it is imported differently) Please implement std::error::Error otherwise working with libraries like |
@thomaseizinger Oops, you're of course correct, not sure how my search missed that. I will implement this and the other suggested changes. |
I implemented |
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.
I still believe we need Ord
when we have Eq
and PartialOrd
. The rest looks fine for me now
@dr-orlovsky I don't think that's the case mathematically speaking (it probably still makes sense practically in this case if it's possible). Let's imagine the set of all binary strings. That's obviously a contrived example, but I don't see a strict requirement for |
On one side, if we can derive something for free, we should derive it. On the other side, I don't think it's important what we end up doing, but we should decide one thing and be consistent with that for all the Error types in the repo. This would help when we wrap |
The use for @sgeisler thanks for explanation, that is a valid case. |
I think That being said, we can try everything and see how it goes. We can continue this in #555 |
I do agree with @apoelstra in #555 (comment) that we should implement both Had plenty of pain not being able to use datatypes in |
I added |
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.
Thank you and sorry for being insistent. utACK 55657cb
I think here |
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.
tACk a1e98a6
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.
utACK a1e98a6
@sanket1729 are you still against merging without a more thorough test than CI (=currently @apoelstra's test suite)? I'm currently building my own setup (cargo-all-features and some bash, not as fancy but I'll understand it xD). So I hope we can get stuff merged again soon.
Yeah, let's merge this. |
And keep the latest validation status on the store cache. NOTE: This commit depends on a rust-bitcoin fork with serializable uint types. A PR was sent upstream: rust-bitcoin/rust-bitcoin#511
And keep the latest validation status on the store cache. NOTE: This commit depends on a rust-bitcoin fork with serializable uint types. A PR was sent upstream: rust-bitcoin/rust-bitcoin#511
No description provided.