0.32.x: Add consensus_encoding to types present in units 1.0#6184
Conversation
debebc4 to
d5337ac
Compare
|
I opened #6188 to update the dependence to 0.5.0 on 0.32.x |
|
Problem with |
|
MSRV bump tagged and published in #6126 |
d5337ac to
6493f3a
Compare
|
Now internals is gone and the MSRV bumped this is ready for review. |
|
|
||
| if !remaining.is_empty() { | ||
| return Err(DecodeAllError::TrailingBytes); | ||
| } |
There was a problem hiding this comment.
Isnt' this going to error on every call? I thought bytes was essentially an endless slice of data.
There was a problem hiding this comment.
Apparently not, I don't know why not though?
There was a problem hiding this comment.
Oooh, maybe compare_amount never gets anywhere because both decode_all and deserialize error.
There was a problem hiding this comment.
This was added because the first try failed fuzzing on cases with trailing bytes. As AI said (minus the half a page of nonsense) "the new path could accept a valid prefix with extra bytes while legacy rejects it". Fuzzing with extra bytes then causes false mismatches.
This is a behaviour difference, but I assume we want it because it matches master. And it is not a difference in the encoding itself.
I added a comment to try and explain why the check is there.
There was a problem hiding this comment.
I thought
byteswas essentially an endless slice of data.
Rust has no "endless slice" type so bytes is definitely not this.
Please cite which commit you're reviewing. Github does not show enough context to locate comments. For example, here you are complaining about a bytes object which does not even appear in the "context" that Github provides.
There was a problem hiding this comment.
I changed the fuzzing to trim the slices since the old encoding logic failed on trailing bytes but the new just ignores them.
There was a problem hiding this comment.
I learned a bit more. What I learned is: libfuzzer calls do_test repeatedly with different length slices starting with short ones then getting bigger.
I'm still unsure once the fuzzer finds a code path (ie a type decodes) if subsequent calls to do_test will change the slice length again or if the fuzzer gets 'stuck' using this length slice. Which leads back to the question is it the same to run the fuzzer for 1000 seconds compared to running it 10 times for 100 seconds?
|
A few comments:
|
7995ac4 to
6fe22fe
Compare
It was relatively straightforward, I am hoping there are other types like this.
I removed the changes to locktime.
It is only Amount that has consensus_encoding in 1.0.0 and here.
Master has it both at the repo root and in units. I assumed it was duplicated in units because it needed to be in the crate for publishing.
Can easily change it if needed. I just matched it to master.
Makes sense to do it now so I did it.
Updated. |
There is only one copy, in the crate root. The other copies are symlinks.
I don't know how to interpret @tcharding's "don't do locktimes, do locktimes" comment, but we need to implement the traits for |
Sorry if I wasn't clear. This PR is (or was when I reviewed it) adding encoding to the types used by
That is my point. There are other types in |
|
Ok thanks, I'll address those comments next week. Going to draft it for now. |
|
Full disclosure, I was braindead yesterday, I had it in mind that all the types from |
|
BOOM! Thanks for your patience and for sticking with this Jamil. |
|
Can you prioritise this one please @apoelstra |
|
FYI we may wind up yanking this, reducing the MSRV, and re-releasing. But I don't see any reason to hold up this PR on that. Will definitely prioritize this. |
Bump all of the dependencies of the crates on other crates in the workspace to .100 which have an MSRV of 1.74 now that they are published.
Add the dependency and reexport to units and bitcoin. Add path section to bitcoin manifest since it uses local changes to units. Add the decoder newtype macro for consensus encoding and sym links in units and bitcoin. Update api and lock files.
Copy the code from master directly. Then remove ``.map_err(AmountDecoderError::out_of_range)` from `Amount::from_sat(a)`` since it is infallible. Remove AmountDecoderErrorInner and refactor now it is not needed. Update api files.
Copy the code from master directly. Then update the import of `internals` to `internal_macros` now that `internals` is not used. Gate the whole error module on `encoding` instead of every individual part to keep it out of the api when `encoding` is not enabled. Update api files.
Copy the code from master directly. Then update the import of `internals` to `internal_macros` now that `internals` is not used. Gate the whole error module on `encoding` instead of every individual part to keep it out of the api when `encoding` is not enabled. Update api files.
d16f97e to
bfe8656
Compare
|
Rebased and removed merge conflict in lock files. Also removed all the error modules and inlined the errors. |
Copy the code from master directly. Then update the import of `internals` to `internal_macros` now that `internals` is not used. Gate the whole error module on `encoding` instead of every individual part to keep it out of the api when `encoding` is not enabled. And update a doc link to LockTime. Update api files.
Add a fuzz target that compares the legacy to the new consensus encoding implementations for units 1.0 types. The slices created by the fuzzer are trimmed to the correct length to increase coverage instead of erroring on most slices that are too long. Update lockfiles. Assisted-by: Claude Sonnet 4.6 (So it says, with the amount of edits I had to make I'm not sure it was an "assistance")
bfe8656 to
2e1f9a0
Compare
|
My local CI system is complaining about the include link. Lemme investigate. |
|
I think I've got it. Should be resolved and an ACK posted tonight. |
|
I think we should revert all the patches that went in with the MSRV bump first. |
|
This one is bigger, already has review, and doesn't have any version bumps or anything in it. So I merged it now, and we can rebase #6354. |
|
Bother, you made #6354 way harder now. I don't know exactly how to revert and keep each commit building and still keep the encoding stuff. |
|
EDIT: Perhaps skip reading this and just see #6359 I had hoped to do this:
|
As a first step in implementing
consensus_encodingin0.32.xadd impl for types that are inunits1.0and in0.32.x.consensus_encodingdependency tounitsandbitcoin(some units 1.0 types are still in bitcoin in v0.32).consensus_encodingtoAmount,Sequence,CompactTargetandabsolute::LockTime.base58ckdependence inbitcointo0.1.100. Required to remove the dependence of0.1.0oninternals.