-
Notifications
You must be signed in to change notification settings - Fork 436
invoice: Use PaymentHash in raw invoice types #4363
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?
invoice: Use PaymentHash in raw invoice types #4363
Conversation
|
👋 I see @valentinewallace was un-assigned. |
da905d6 to
f967d8a
Compare
lightning/src/ln/channelmanager.rs
Outdated
| let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); | ||
| let payment_hash = invoice.payment_hash(); | ||
| let payment_hash = | ||
| PaymentHash(Sha256::from_byte_array(invoice.payment_hash().0).to_byte_array()); |
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.
Huh? Same below.
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.
Ah, good catch. That was a redundant round-trip left over from when I was refactoring the types. Simplified it to just use invoice.payment_hash() directly
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4363 +/- ##
=======================================
Coverage 86.09% 86.09%
=======================================
Files 156 156
Lines 102804 102853 +49
Branches 102804 102853 +49
=======================================
+ Hits 88508 88553 +45
+ Misses 11788 11784 -4
- Partials 2508 2516 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
6b9f7ec to
59b1623
Compare
tnull
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.
Note: This is a breaking change for InvoiceBuilder. Downstream consumers (like ldk-node) will need to update their builder calls to pass PaymentHash directly.
Please note that we employ a "if you break it, you keep it" rule here by now. ;)
I.e., please make sure to open a PR on the LDK Node end to clean up the breakage as soon as this lands.
lightning/src/ln/channelmanager.rs
Outdated
| Err(()) => return None, | ||
| }; | ||
|
|
||
| let payment_hash = invoice.payment_hash(); |
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.
Unnecessary diff.
| let mut invoice_builder = InvoiceBuilder::new(currency) | ||
| .description(description.to_string()) | ||
| .payment_hash(payment_hash) | ||
| .payment_hash(PaymentHash(payment_hash.to_byte_array())) |
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.
Here too we're building a sha256::Hash just to undo it.
lightning/src/ln/invoice_utils.rs
Outdated
| Bolt11InvoiceDescriptionRef::Direct(&Description::new("test".to_string()).unwrap()) | ||
| ); | ||
| assert_eq!(invoice.payment_hash(), payment_hash); | ||
| assert_eq!(invoice.payment_hash().0, payment_hash.0); |
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.
Unnecessary diff.
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.
Fixed in the latest push
Understood! I'm happy to handle the LDK Node fix. I'll keep an eye on this and open the fix PR in ldk-node after this lands. |
59b1623 to
d652d86
Compare
Closes #4292
Note: This is a breaking change for InvoiceBuilder. Downstream consumers (like ldk-node) will need to update their builder calls to pass PaymentHash directly.
Refactors
RawBolt11Invoice,RawDataPart, andTaggedFieldto uselightning_types::payment::PaymentHashinstead ofbitcoin::hashes::sha256::Hash.This improves type safety and aligns the raw invoice types with the high-level
Bolt11Invoice.This is a follow-up to #4293 to complete the migration of invoice types to PaymentHash.
Specific changes:
TaggedField::PaymentHashnow holds aPaymentHash.InvoiceBuilder::payment_hashnow accepts aPaymentHashdirectly.serialization.
the TaggedField variant.
lightningcrate (channelmanager andinvoice_utils) to remove redundant hash conversions now that the builder
accepts the strong type.