Skip to content

Remove Witness::from_parts__unstable#5139

Merged
apoelstra merged 2 commits intorust-bitcoin:masterfrom
tcharding:push-tpqnlvtkvnor
Dec 13, 2025
Merged

Remove Witness::from_parts__unstable#5139
apoelstra merged 2 commits intorust-bitcoin:masterfrom
tcharding:push-tpqnlvtkvnor

Conversation

@tcharding
Copy link
Copy Markdown
Member

@tcharding tcharding commented Oct 15, 2025

This is nice enough now. Use the new consensus_encoding crate to decode a Witness (in bitcoin). Then remove the from_parts__unstable function.

Close #4062

@github-actions github-actions bot added C-bitcoin PRs modifying the bitcoin crate C-primitives labels Oct 15, 2025
@apoelstra
Copy link
Copy Markdown
Member

I wouldn't call this a "hack", but it does stuff in the wrong order.

What we should do instead is add a dep to bitcoin-io on consensus_encoding. Then in bitcoin-io we can provide a ReadError and decode_from_read method analogous to the existing ones in consensus_encoding for std Read.

Then most of your "ugly hack" would be replaced with a call to bitcoin_io::decode_from_read. The remaining ugliness is about converting the bitcoin_io::ReadError into the old bitcoin::consensus::Error. Well, that error is #[non_exhaustive] so we can add variants (and actually we're totally breaking the API so in principle we can do whatever we want, but everything I've said thus-far is backportable to 0.32.x so let's try to keep it that way as long as possible).

So let's add a variant to bitcoin::consensus::Error which holds a primitives::WitnessDecoderError. This is pretty ugly, adding a type-specific error variant to an error type which is supposed to be a general-purpose error type. But another way to look at it is that it's a less-ugly expression of the inherent ugliness of from_parts__unstable.

@tcharding
Copy link
Copy Markdown
Member Author

tcharding commented Oct 15, 2025

So let's add a variant to bitcoin::consensus::Error which holds a primitives::WitnessDecoderError.

I did try that this morning but ran into trouble, I stopped at the IterReader IIRC.

EDIT: Oh I remember now, deserialize_partial doesn't work, there is no way to get a ParseError.

@apoelstra
Copy link
Copy Markdown
Member

apoelstra commented Oct 15, 2025

You should add the variant to ParseError, not consensus::Error. (Or you can keep using ParseError::ParseFailed as you do now, but that loses a lot of information).

In this current PR you add a variant to Error but AFAICT you never actually use it.

@tcharding
Copy link
Copy Markdown
Member Author

Oh I didn't think of that, it will mean the io::Error is in two places but anyways, I'll have a go.

@apoelstra
Copy link
Copy Markdown
Member

Lint failure is real (clippy)

@apoelstra
Copy link
Copy Markdown
Member

Looks like this still inlines "decode from bitcoin::io::BufRead" logic which should be in io.

@tcharding
Copy link
Copy Markdown
Member Author

Thanks, I'll come back.

@tcharding tcharding marked this pull request as draft October 26, 2025 00:42
@tcharding
Copy link
Copy Markdown
Member Author

tcharding commented Oct 27, 2025

Looks like this still inlines "decode from bitcoin::io::BufRead" logic which should be in io.

I'm not sure what you mean? This is a copy of encoding::decode_from_read but with a WitnessDecoder instead of generic decoder (T) and using the ParseError instead of ReadError::Decode.

@apoelstra
Copy link
Copy Markdown
Member

It should be a single call to io::decode_from_read, not a copy of the inside of encoding::decode_from_read.

@github-actions github-actions bot added the C-io PRs modifying the io crate label Oct 28, 2025
@tcharding tcharding force-pushed the push-tpqnlvtkvnor branch 2 times, most recently from 85f78e0 to 3c42ec3 Compare November 20, 2025 23:59
@github-actions
Copy link
Copy Markdown

🚨 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.

@github-actions github-actions bot added the API break This PR requires a version bump for the next release label Nov 21, 2025
@github-actions
Copy link
Copy Markdown

🚨 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.

@tcharding
Copy link
Copy Markdown
Member Author

tcharding commented Nov 21, 2025

The API break is expected and comes from #5249.

Use the new `consensus_encoding` crate (by way of the `io` crate
decoding function) to implement `consensus_decode` for `Witness`.

This is ugly a bit ugly because we remove equality derives from
`ParseError` so that we can jam the witness decoding error into it.
Cleanly it should not go there but in order to keep
`encode::deserialize_partial` working we have to be able to return
a `ParseError` and we have to be able to include the witness decoding
error if there was one.

Each subsequent time we try to do this in other decoding impls we will
add a new error variant each time also. This encoding code is on its
way out and will hopefully be deprecated soon so I believe this is ok.
@github-actions github-actions bot removed the C-io PRs modifying the io crate label Dec 13, 2025
@tcharding tcharding marked this pull request as ready for review December 13, 2025 01:24
This was added solely so that we could call it in the consensus
decoding function in `bitcoin`. That call site no longer exists,
remove the function.
Copy link
Copy Markdown
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 9b261de; successfully ran local tests; I think we should do this before the beta release

@apoelstra apoelstra merged commit 4f31509 into rust-bitcoin:master Dec 13, 2025
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API break This PR requires a version bump for the next release C-bitcoin PRs modifying the bitcoin crate C-primitives

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Figure out how to get rid of Witness::from_parts__unstable

2 participants