Remove VarInt and use ReadExt and WriteExt trait methods instead #2931
Remove VarInt and use ReadExt and WriteExt trait methods instead #2931apoelstra merged 2 commits intorust-bitcoin:masterfrom
VarInt and use ReadExt and WriteExt trait methods instead #2931Conversation
|
CC @stevenroose, I picked up your work man, hope you don't mind. |
|
Might close #1016 |
|
Name might be wrong, converting to draft to work it out. ref : #1016 (comment) |
bitcoin/src/blockdata/witness.rs
Outdated
There was a problem hiding this comment.
The 9fe420d2210bfcfab4d0913c9dd94f633496f95a commit message makes it sound like getting the length is impossible without returning it. That's a complete BS.
Instead the message should be something like "Returning usize is more convenient for consumers that need to add up the length of multiple encoded items."
bitcoin/src/consensus/encode.rs
Outdated
There was a problem hiding this comment.
This should be ToU64 which was added in fc03492d8d45a54da0567db8c46e6f84cb5d0148
There was a problem hiding this comment.
Ugh, sloppy work by me.
bitcoin/src/consensus/encode.rs
Outdated
There was a problem hiding this comment.
Not const, it should say varint_size_u64.
bitcoin/src/consensus/encode.rs
Outdated
There was a problem hiding this comment.
Alternative design: add varint_size method to ToU64, make this accept u64 and make it const, delete varint_size_const. Then users will be able to call .varint_size on integers. (In that case, the trait must be public and stable, not private/internals as I suggested elsewhere.) There's potential silliness that some other crate will define consensus-encoding-related method. We could have NumExt: ToU64 trait to move it away.
There was a problem hiding this comment.
You can't make trait methods const.
There was a problem hiding this comment.
I mean make this fn const by being non-generic and use methods for convenience instead.
There was a problem hiding this comment.
Flagging that I did not action this.
355a8fb to
4b142f8
Compare
|
🚨 API BREAKING CHANGE DETECTED |
4b142f8 to
acc547f
Compare
|
🚨 API BREAKING CHANGE DETECTED |
acc547f to
5d5ea04
Compare
|
Rebased, added a new final patch, and re-wrote PR description. |
|
🚨 API BREAKING CHANGE DETECTED |
|
Perhaps we should instead use |
8b387ae to
ae96162
Compare
|
🚨 API BREAKING CHANGE DETECTED To see the changes click details on "Check semver breaks / PR Semver - stable toolchain" job then expand "Run semver checker script" and scroll to the end of the section. |
1 similar comment
|
🚨 API BREAKING CHANGE DETECTED To see the changes click details on "Check semver breaks / PR Semver - stable toolchain" job then expand "Run semver checker script" and scroll to the end of the section. |
|
Needs rebase |
ae96162 to
1599db2
Compare
|
Rebased, then got lost fixing my emacs, not sure if I touched anything other than rebase but I don't think so. |
|
🚨 API BREAKING CHANGE DETECTED To see the changes click details on "Check semver breaks / PR Semver - stable toolchain" job then expand "Run semver checker script" and scroll to the end of the section. |
|
Will ACK. FWIW I'm happy with this API and would be willing to pull it out of |
apoelstra
left a comment
There was a problem hiding this comment.
ACK 1599db253574a97191ee63146ce57040845800e1 successfully ran local tests; nice, though sad that we need a separate non-generic compact_size_const method
Agreed. |
1599db2 to
b58dd27
Compare
|
Re-based, during which |
|
🚨 API BREAKING CHANGE DETECTED To see the changes click details on "Check semver breaks / PR Semver - stable toolchain" job then expand "Run semver checker script" and scroll to the end of the section. |
|
Needs #3395 |
apoelstra
left a comment
There was a problem hiding this comment.
ACK b58dd27c42d56df8a3e05ff719022e240ea0ff81 successfully ran local tests; nice, though sad that we need a separate non-generic compact_size_const method
|
lol, amusingly, your re-post of the 'sad that we ...' confused me, I was sure I'd read that before :) |
|
Yeah :) I'm not sure what the best way for me to "refresh an ACK" with a nontrivial message is. I want to repeat the message so it shows up in the commit message, but it's weird to read for people on the PR. |
|
Oh, that is ok, now I know it won't surprise me. |
We would like to add a `emit_varint` function, however doing so requires that we can get access to the length of a slice when we are encoding it so we can use `emit_slice` to implement `emit_varint`. It would be easier to do so if `emit_slice` returned the length of the slice. In preparation for adding `emit_varint` (and removing the `VarInt` type) return the encoded length of a slice from `WriteExt::emit_slice`. (Patch originally written by Steven, cherry-pick and patch description written by Tobin.) Co-developed-by: Tobin C. Harding <me@tobin.cc>
At some stage we named the compact encoding `VarInt` (which makes sense because the compact size encoding is a variable length integer encoding). However it turns out the term "varint" is used in Core for a different encoding so this may lead to confusion. While we fix this naming thing observe also that the `VarInt` type is unnecessarily complicated, all we need to be able to do is encode and decode integers in compact form as specified by Core. We can do this simply by extending our `WriteExt` and `ReadExt` traits. Add `emit_compact_size` and `read_compact_size` to emit and read compact endcodings respectively. Includes addition of `internals::compact_size::encoded_size_const`. Patch originally written by Steven, Tobin cherry-picked and did a bunch of impovements after the varint vs compact_size thing (rust-bitcoin#1016). ref: https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer Co-developed-by: Tobin C. Harding <me@tobin.cc>
b58dd27 to
18d8b0e
Compare
|
🚨 API BREAKING CHANGE DETECTED To see the changes click details on "Check semver breaks / PR Semver - stable toolchain" job then expand "Run semver checker script" and scroll to the end of the section. |
|
I rekon we can merge this, all @Kixunil's concerns from last month have been either addressed or commented on. |
This the meat and potatoes out of Steven's work in #2133 and also closes #1016