-
Notifications
You must be signed in to change notification settings - Fork 409
offers: parse invoice and invoice request #3800
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: main
Are you sure you want to change the base?
Conversation
👋 Thanks for assigning @jkczyz as a reviewer! |
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.
Code looks good, but I think we previously discussed this and had decided against introducing a serialization format for invoices and requests. Not sure if things changed since then though? (cc @jkczyz @TheBlueMatt)
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.
Overall LGTM, leaving a comment
I has a similar code in a bolt12 tool that I am building for ocean that allow to make verification on the offer + invoice. So would be good to have this feature somehow to allow more usable command line tools.
However, it is also possible to leave this to the caller, exposing some minimal information like AsRef
and BECH32_HRP if at the moment, rust-lightning does not want to export this kind of serializzation.
🔔 1st Reminder Hey @jkczyz! This PR has been waiting for your review. |
Add the ability to parse and display BOLT12 invoices and invoice requests. This makes it easy for users of LDK to serialize and deserialize BOLT12 invoices and invoice requests.
96fd362
to
ffed552
Compare
Pushed a change to |
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.
Code looks good, but I think we previously discussed this and had decided against introducing a serialization format for invoices and requests. Not sure if things changed since then though? (cc @jkczyz @TheBlueMatt)
Right, shouldn't the LengthReadable
and Writeable
implementations be sufficient?
} | ||
|
||
impl Bech32Encode for Bolt12Invoice { | ||
const BECH32_HRP: &'static str = "lni"; |
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.
Hmm... we shouldn't introduce a bech32 encoding that isn't in the spec. BOLT12 invoices are only transferred over the wire, so one isn't defined. They also only make sense in the context of a preceding offer
/ invoice_request
(i.e., you'll never see them in a context where a user would scan it).
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.
FWIW, could that be a spec bug? Seems CLN is supporting the lni
format, so maybe it should be added to the spec, or was that omitted on purpose?
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.
It was deliberately removed from the spec. IIRC, @TheBlueMatt pushed for having it removed. CLN uses it in some tests and its CLI, I believe.
} | ||
|
||
impl Bech32Encode for InvoiceRequest { | ||
const BECH32_HRP: &'static str = "lnr"; |
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.
Similarly here. Additionally, this clashes with Refund
, which is essentially an invoice_request
without a preceding offer
.
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 one is in the spec though, or at least it makes it seem lnr
is used for both?:
Invoice Requests are a request for an invoice; the human-readable prefix for invoice requests is
lnr
.
https://github.com/lightning/bolts/blob/master/12-offer-encoding.md#invoice-requests
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 raised the issue at one point: lightning/bolts#798 (comment)
Ultimately, if you overload it, then your parser can't just look at the human-readable part to determine which code to call. It needs to try parsing with one and, if it fails, fall back to the other.
@JssDWt Could you expand whether you really need this/for what in particular, given that parts of this seems to have been deliberately dropped from the spec? Is there a way around it? |
There's a few places where this is useful:
I understand the invoice serialization format is not part of the spec. But also I don't see a strong case against 'allowing' serialization of invoices. Invoice requests I think should just be serializable as they're part of the spec. |
Well, it's my understanding that this is exactly not the case, i.e. that BOLT12 deliberately doesn't provide such serialization formats (anymore). If you require this, it might make sense to raise this issue again at a spec level first.
Wait, but this is exactly the
Hmm, the question is what that would do for the users if there is no blessed serialization format for these. What can they even do with this string? Again, not saying we should or shouldn't do this, but if you have that requirement, it needs to be clarified on the spec level first, as adding proprietary serialization formats on the LDK side that nobody else understands will just lead to fragmentation. |
I didn't realize there was a
I understand. I probably won't take this up on the spec level myself as I find these discussions exhausting.
An LDK native parsing method would be nice. If it was actively removed from the spec by @TheBlueMatt I won't go into the discussion, but I don't get the strong opposition there tbh. |
Want to note that we are hitting the same requirement in lightningdevkit/ldk-node#542, simply because we want to provide a bindings-compatible string representation of |
They are fundamentally different types. While they share the same TLV representation, they have different semantics (i.e., which settings are considered valid) and thus cannot be used interchangeably. An
It's worth considering especially in conjunction with a proof-of-payment spec, which I believe Rusty is developing. Though also note that in addition to |
Add the ability to parse and display BOLT12 invoices and invoice requests. This makes it easy for users of LDK to serialize and deserialize BOLT12 invoices and invoice requests.