consensus_encoding: add u64 support to compact size#5784
Conversation
82364b5 to
ccbfdaf
Compare
|
Are we writing the 'decoding a compact size should fail if value over 32MB' bug back in by providing the |
I rekon we should do this. The module layout in this crate is simply a code organisation thing so we are free to do it how we like. Top level private file |
Cool, think I can tack on the move to |
|
Do it, its easy to review if its a separate patch because of git zebra config. At the front of the PR or the back, its the same for me to review. |
|
Needs rebase. |
|
Per |
Bortlesboat
left a comment
There was a problem hiding this comment.
ACK ccbfdaf. Encoding/decoding is symmetric across all prefix boundaries, non-minimal rejection is correct at each tier, and the round-trip tests are thorough.
66d4143 to
7c28f91
Compare
| pub type bitcoin_primitives::Wtxid::Err = hex_conservative::error::DecodeFixedLengthBytesError | ||
| pub type bitcoin_primitives::block::Block::Decoder = bitcoin_primitives::block::BlockDecoder | ||
| pub type bitcoin_primitives::block::Block::Encoder<'e> where Self: 'e = bitcoin_consensus_encoding::encode::encoders::Encoder2<bitcoin_primitives::block::HeaderEncoder<'e>, bitcoin_consensus_encoding::encode::encoders::Encoder2<bitcoin_consensus_encoding::encode::encoders::CompactSizeEncoder, bitcoin_consensus_encoding::encode::encoders::SliceEncoder<'e, bitcoin_primitives::transaction::Transaction>>> | ||
| pub type bitcoin_primitives::block::Block::Encoder<'e> where Self: 'e = bitcoin_consensus_encoding::encode::encoders::Encoder2<bitcoin_primitives::block::HeaderEncoder<'e>, bitcoin_consensus_encoding::encode::encoders::Encoder2<bitcoin_consensus_encoding::compact_size::CompactSizeEncoder, bitcoin_consensus_encoding::encode::encoders::SliceEncoder<'e, bitcoin_primitives::transaction::Transaction>>> |
There was a problem hiding this comment.
Hm, need to dig in to why these APIs changed.
EDIT: maybe just a limitation of the docs-as-type-checker system?
e1322cf to
cc51369
Compare
|
cc51369: moved compact size stuff into its own module and beef'd up the docs. For some reason this move triggered a mutant, not sure how yet, but tossed in a test to cover it. There is also a confusing diff in the |
cc51369 to
093025b
Compare
|
Ah, the mutant timeouts are on master already, going to deal with those separately in #5806 and then rebase. |
093025b to
1596b2c
Compare
1596b2c to
3be0feb
Compare
|
Needs rebase. |
3be0feb to
5535272
Compare
5535272 to
fe83d4f
Compare
|
fe83d4f: rebased and toned down some of the yelling in the docs |
|
@tcharding this is a nontrivial API change to consensus-encoding so we need your ACK |
|
|
||
| /// The maximum length of a compact size encoding. | ||
| const SIZE: usize = 9; | ||
| pub use crate::compact_size::CompactSizeEncoder; |
There was a problem hiding this comment.
I don't think we should do this. And if we do want to do it we should mirror it for decoders.
There was a problem hiding this comment.
Was the concern here about the encoder constructors? Or did I just make the commits confusing?
There was a problem hiding this comment.
Oh it was adding 'pub use' in encoders but the decoder is not re-exported in decoders. But I don't think we should do either, just the crate root is enough IMO.
There was a problem hiding this comment.
ooo, and I missed this while reviewing this morning. Thanks for flagging it.
There was a problem hiding this comment.
Ah I see now, yea, I did this really round-about. Will fix.
|
Didn't finish review sorry mate, will come back tomorrow. |
|
Sorry for taking so long. |
fe83d4f to
2c9b904
Compare
|
2c9b904: simplified the compact_size re-export from the root. |
| pub const bitcoin_hashes::HashEngine::LEN: usize | ||
| pub const bitcoin_hashes::IsByteArray::LEN: usize | ||
| pub const bitcoin_hashes::hash160::Hash::DISPLAY_BACKWARD: bool | ||
| pub const bitcoin_hashes::hash160::Hash::LEN: usize |
There was a problem hiding this comment.
Huh, dunno why all these hashes changes showed up now.
There was a problem hiding this comment.
Ah, the version of cargo-public-api is only set int he CI rust.yml workflow, it isn't shared for local dev. Need to run on cargo +nightly install --locked cargo-public-api --version 0.50.1 for now. The new cargo-rbmt tools command will handle this in the future.
There was a problem hiding this comment.
Yep that bit me before, sorry I didn't notice during review.
Public API is unchanged; lib.rs re-exports all the same types.
2c9b904 to
85a6da3
Compare
|
85a6da3: regenerated api files with |
Manually revert 91a6e64 (`git revert` didn't work.) This was a backport of rust-bitcoin#5697 which added range checking to the `VarInt` type. On master we did this then realized there are legitimate use cases for the full range of a `u64`. We then added `u64` support to compact size (rust-bitcoin#5784). Note that we cannot break the API so the new stuff introduced in `0.32.9` has to stay in there. Comment the code as such. NB: 'compact size' is the new name for varint. This backport then broke downstream users.
Manually revert 91a6e64 Note that we cannot break the API so the new stuff introduced in `0.32.9` has to stay in there. Comment the code as such. This was a backport of rust-bitcoin#5697 which added range checking to the `VarInt` type. On master we did this then realized there are legitimate use cases for the full range of a `u64`. We then added `u64` support to compact size (rust-bitcoin#5784). NB: 'compact size' is the new name for varint. This backport then broke downstream users.
Manually revert 91a6e64 Note that we cannot break the API so the new stuff introduced in `0.32.9` has to stay in there. Comment the code as such. This was a backport of rust-bitcoin#5697 which added range checking to the `VarInt` type. On master we did this then realized there are legitimate use cases for the full range of a `u64`. We then added `u64` support to compact size (rust-bitcoin#5784). NB: 'compact size' is the new name for varint. This backport then broke downstream users.
Manually revert 91a6e64 Note that we cannot break the API so the new stuff introduced in `0.32.9` has to stay in there. Comment the code as such. This was a backport of rust-bitcoin#5697 which added range checking to the `VarInt` type. On master we did this then realized there are legitimate use cases for the full range of a `u64`. We then added `u64` support to compact size (rust-bitcoin#5784). NB: 'compact size' is the new name for varint. This backport then broke downstream users.
Manually revert 91a6e64 Note that we cannot break the API so the new stuff introduced in `0.32.9` has to stay in there. Comment the code as such. This was a backport of #5697 which added range checking to the `VarInt` type. On master we did this then realized there are legitimate use cases for the full range of a `u64`. We then added `u64` support to compact size (#5784). NB: 'compact size' is the new name for varint. This backport then broke downstream users.
3bcd7c9 Manually revert VarInt range check (Tobin C. Harding) Pull request description: Manually revert 91a6e64 Note that we cannot break the API so the new stuff introduced in `0.32.9` has to stay in there. Comment the code as such. This was a backport of #5697 which added range checking to the `VarInt` type. On master we did this then realized there are legitimate use cases for the full range of a `u64`. We then added `u64` support to compact size (#5784). NB: 'compact size' is the new name for varint. This backport then broke downstream users. Close: #6138 ACKs for top commit: apoelstra: ACK 3bcd7c9; successfully ran local tests Tree-SHA512: d01078f4f8fae59c439fd404a643abfb353bcec1757ebfbcabde487ff8620d927387f91d0e749a7bbd36163f2386290d301f17c0cff9e628e37585329daf116b
Add u64 support to the Compact Size codec since there are non prefix length use cases (#5762). Kind of related to #5752.
I believe this is the simplest way to add support, but the asymmetry kind of annoys me. On the encoding side, only a new constructor is necessary. But on the decoding side a new type is required since there is a 1:1 with the associated output. I don't think symmetry is a strong enough reason to put a type on the encoding side though.
I didn't put much though into the names, focusing on minimal change. But maybe it would be worth it to name each encoder/decoder after its use case instead of impl? So the existing one would be called something like
LengthPrefixDecoderand so on.The first commit moves the existing compact size stuff into its own
::compact_sizemodule, to kind of corner this weirdness. This creates kind of a funky dependency graph with::decodeand::decode::decoders(and the equivalent encoders side), but none of that is exposed from the crate since it is a private module.