Skip to content

Conversation

@DanGould
Copy link
Contributor

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

apoelstra
apoelstra previously approved these changes Aug 29, 2022
Copy link
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 f98bfd3bb74b8f090cf3b093e40f9abd19c5e49c

@tcharding tcharding changed the title Enum[erate] PSBT vesion Enum[erate] PSBT version Aug 30, 2022
Copy link
Member

@tcharding tcharding left a 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.

Copy link
Member

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.

Copy link
Collaborator

@Kixunil Kixunil left a 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.

Copy link
Collaborator

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

Copy link
Collaborator

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?

Copy link
Contributor Author

@DanGould DanGould Nov 29, 2022

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.

Copy link
Collaborator

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.

@DanGould DanGould force-pushed the psbt-ver branch 2 times, most recently from b8734cb to 2f2c944 Compare December 1, 2022 02:41
Copy link
Collaborator

@Kixunil Kixunil left a 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.

Copy link
Collaborator

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.

Copy link
Member

@tcharding tcharding left a 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,
                    },

@Kixunil
Copy link
Collaborator

Kixunil commented Dec 1, 2022

@tcharding nice catch!

It appears to me that we should not have PsbtV2 until we trully support version 2. And I suspect there will be forward-compatibility issues among other things. Super-large and difficult project for sure.

@DanGould
Copy link
Contributor Author

DanGould commented Dec 4, 2022

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 don't know exactly what stage PSBT version 2 is at

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

@tcharding
Copy link
Member

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?

@DanGould
Copy link
Contributor Author

DanGould commented Feb 3, 2023

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.

@Kixunil
Copy link
Collaborator

Kixunil commented Feb 3, 2023

PSBT is a huge change, I don't think it can make it in.

Copy link
Member

@tcharding tcharding left a 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.

Comment on lines +72 to +76
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))
}
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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 {
Copy link
Member

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.

@DanGould
Copy link
Contributor Author

DanGould commented Apr 9, 2023

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.

@tcharding
Copy link
Member

I'm fine to review a massive "psbt v2" PR.

@tcharding
Copy link
Member

tcharding commented Aug 25, 2023

Hi @DanGould whats your workload like at the moment, have you time to get to this? Seems it is needed for #1924, would be good to get it in, I can pick it up and shepherd it through if you like?

@DanGould
Copy link
Contributor Author

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

@tcharding
Copy link
Member

AFAICT just the error thing fixing up.

@stevenroose
Copy link
Collaborator

I guess this PR is deprecated in favor of #1924?

@DanGould
Copy link
Contributor Author

DanGould commented Dec 30, 2023

@stevenroose the most active development for psbtv2 is happening in a new psbt crate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants