-
Notifications
You must be signed in to change notification settings - Fork 922
Enum[erate] PSBT version #1218
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
base: master
Are you sure you want to change the base?
Enum[erate] PSBT version #1218
Conversation
apoelstra
left a comment
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.
ACK f98bfd3bb74b8f090cf3b093e40f9abd19c5e49c
tcharding
left a comment
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.
Nice one man, a few tips and suggestions.
src/util/psbt/mod.rs
Outdated
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.
For other reviewers: this is too many derives but they have to be here because of psbt::error::Error.
Kixunil
left a comment
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 should at least rename standard. The other issues would be also good to address but not required. The rest looks good.
bitcoin/src/psbt/mod.rs
Outdated
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 should say "invalid version". (The whole thing looks weird but I'm not in the mood to figure out a better way.)
bitcoin/src/psbt/error.rs
Outdated
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 realized this will produce silly-looking messages like unrecognized PSBT version: Unknown future PSBT version 42 but I don't see a clear way how to make them better. A not-very-clear way is to use fmt::Display::fmt(e, f) (with a comment that this is intentionally flattened) and then impl source like this:
Error::FutureVersion(ref e) => e.source(),Effectively flattening the variant. Any ideas?
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 Error::FutureVersion(ref e) => e.fmt(f) will produce Unknown future PSBT version 42. How's that? Error handling the right way is a big rust blind spot for me to improve.
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.
Exactly. We just pretend e is not a sub-error. But has to be combined with e.source(). I worry though that it'll be confusing since the enum is public.
b8734cb to
2f2c944
Compare
Kixunil
left a comment
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.
Unpublishing version looks wrong. The rest looks OK, jut some nits.
bitcoin/src/psbt/mod.rs
Outdated
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'm not sure if we should keep Ord and PartialOrd. We can probably keep the others.
tcharding
left a comment
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 don't know exactly what stage PSBT version 2 is at but wanted to flag that there is a code comment
// We only understand version 0 PSBTs. According to BIP-174 we
// should throw an error if we see anything other than version 0.
if version != Some(0) {
return Err(encode::Error::ParseFailed("PSBT versions greater than 0 are not supported"))
}But with this PR we accept v0 or v2
version: match version {
Some(v) => Version::from_raw(v).map_err(Error::from)?,
None => Version::PsbtV0,
},|
@tcharding nice catch! It appears to me that we should not have |
|
Agree it makes sense to provide Version::V2 only when the interface is available. This was a good place for me to start since Orlovsky did most of the heavy lifting on the original PR. Separating the PRs makes it easier to address decisions about individual pieces before it comes together.
I believe the hardest part will be the refactoring around errors #837 and the move away consensus::{Encodable, Decodable}. After that, the v2 data structure is mostly new map fields and a function to serialize v2 to v0 |
|
I can't remember what state this one was up to @DanGould, now that the error stuff is ready to merge did you want to get this into the next release? |
|
I think this change only makes sense in the context of a usable psbt2. If there is time to review psbt2 changes before the next (30.0) release I would love to draft it and get it over the line now. If not, we can get it into the following pre-release. |
|
PSBT is a huge change, I don't think it can make it in. |
tcharding
left a comment
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.
Thanks @DanGould, an open question about the Ord stuff but also I'm concerned that if this merges the code reads like we support V2 already, I'd be happier if everywhere we use the version that an occurence of v2 gives an explicit "not yet implemented" or "wip, not fully implemented" error.
| match version { | ||
| v if v == Version::PsbtV0 as u32 => Ok(Version::PsbtV0), | ||
| v if v == Version::PsbtV2 as u32 => Ok(Version::PsbtV2), | ||
| future => Err(FutureVersionError(future)) | ||
| } |
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 don't have deep PSBT knowledge but this reads as if someone attempting to parse 0 for version will get a future version error but v1 will never exist, right?
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.
0 will get PsbtV0
1 will get Future version which I agree is weird. Maybe just VersionError is more appropriate
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.
Never say never ;).
But I agree, I think we should have a specific error variant for v1 actually which tells the user that they probably meant v0.
|
|
||
| // Serializing version only for non-default value; otherwise test vectors fail | ||
| if self.version > 0 { | ||
| if self.version > Version::PsbtV0 { |
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'm not sure exactly why but my gut tells me we should match on the variants explicitly and remove PartialOrd/Ord. For the "keep the highest version" (in combine) we could use to_raw then compare the values.
|
I'm thinking merging PSBT2 in pieces this small makes less sense than getting a viable implementation done first, even if that's a larger review. |
|
I'm fine to review a massive "psbt v2" PR. |
|
I figured it would be added as part of #1924 and then this pr would be closed. Am I mistaken? What kind of attention does this require to facilitate psbt2 |
|
AFAICT just the error thing fixing up. |
|
I guess this PR is deprecated in favor of #1924? |
|
@stevenroose the most active development for psbtv2 is happening in a new psbt crate |
Reinstates #769
This converts PSBT version into an enum. This rejects PSBTs which are unknown, i.e. not v0 or v2 as per BIP 174 spec.
This is a first of many PRs to discuss PSBTv2 design decisions one-by-one