-
Notifications
You must be signed in to change notification settings - Fork 80
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
Expose payer_note
in PaymentKind::Bolt12
#327
Expose payer_note
in PaymentKind::Bolt12
#327
Conversation
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 for looking into this!
While we're at it, we should probably also add the payer_note
field to the Bolt12Refund
variant and allow to set it via initiate_refund
in a second commit.
Seems some tests are failing currently |
d4a92b0
to
a2c1144
Compare
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.
Generally already looks pretty good, but please clean up the git history so that the changes match the commit messages. Preferably splitting to one commit per field or similar.
src/payment/bolt12.rs
Outdated
@@ -95,6 +96,9 @@ impl Bolt12Payment { | |||
preimage: None, | |||
secret: None, | |||
offer_id: offer.id(), | |||
payer_note: payer_note.map(UntrustedString), | |||
payer_id: None, |
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.
Mh, this is a bit weird as internally to LDK we very well know the payer_id
at this point. Maybe we should consider returning the InvoiceRequest
from pay_for_offer
.
For consistency it would also be good to actually set the payer note based on the invoice request field rather than what the user gave us.
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.
Mh, this is a bit weird as internally to LDK we very well know the
payer_id
at this point. Maybe we should consider returning theInvoiceRequest
frompay_for_offer
.For consistency it would also be good to actually set the payer note based on the invoice request field rather than what the user gave us.
Should I open an issue on rust-lightning before making the change, or should I just make the change and open a PR directly?
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.
We discussed already a bit offline and may actually arrive at removing payer_id
from the LDK APIs if we can make it work, but it's not sure yet. See lightningdevkit/rust-lightning#3198
a2c1144
to
d89ad6c
Compare
For now, I removed the |
7d1bbd9
to
b1ddd4d
Compare
813856f
to
1b0f4da
Compare
rebased |
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.
Mostly looks good to me, just one comment.
Tests are currently failing due to inconsistent argument ordering:
error[E0308]: arguments to this method are incorrect
--> tests/integration_tests_rust.rs:470:4
|
470 | .send_using_amount(&offer, None, None, less_than_offer_amount)
| ^^^^^^^^^^^^^^^^^ ---- ---------------------- expected `std::option::Option<u64>`, found `u64`
| |
| expected `u64`, found `std::option::Option<_>`
|
note: method defined here
--> /Users/erohrer/workspace/ldk-node/src/payment/bolt12.rs:152:9
|
152 | pub fn send_using_amount(
| ^^^^^^^^^^^^^^^^^
help: swap these arguments
|
470 | .send_using_amount(&offer, None, less_than_offer_amount, None)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error[E0308]: arguments to this method are incorrect
--> tests/integration_tests_rust.rs:474:4
|
474 | .send_using_amount(&offer, None, None, expected_amount_msat)
| ^^^^^^^^^^^^^^^^^ ---- -------------------- expected `std::option::Option<u64>`, found `u64`
| |
| expected `u64`, found `std::option::Option<_>`
|
note: method defined here
--> /Users/erohrer/workspace/ldk-node/src/payment/bolt12.rs:152:9
|
152 | pub fn send_using_amount(
| ^^^^^^^^^^^^^^^^^
help: swap these arguments
|
474 | .send_using_amount(&offer, None, expected_amount_msat, None)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error[E0308]: arguments to this method are incorrect
--> tests/integration_tests_rust.rs:514:39
|
514 | let refund = node_b.bolt12_payment().initiate_refund(overpaid_amount, None, 3600).unwrap();
| ^^^^^^^^^^^^^^^ ---- ---- expected `std::option::Option<u64>`, found `{integer}`
| |
| expected `u32`, found `std::option::Option<_>`
|
note: method defined here
--> /Users/erohrer/workspace/ldk-node/src/payment/bolt12.rs:316:9
|
316 | pub fn initiate_refund(
| ^^^^^^^^^^^^^^^
help: swap these arguments
|
514 | let refund = node_b.bolt12_payment().initiate_refund(overpaid_amount, 3600, None).unwrap();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For more information about this error, try `rustc --explain E0308`.
error: could not compile `ldk-node` (test "integration_tests_rust") due to 4 previous errors
exit 101
Feel free to squash fixups and rebase on current main to have CI pass.
src/payment/bolt12.rs
Outdated
@@ -143,14 +150,13 @@ impl Bolt12Payment { | |||
/// If `payer_note` is `Some` it will be seen by the recipient and reflected back in the invoice | |||
/// response. | |||
pub fn send_using_amount( | |||
&self, offer: &Offer, payer_note: Option<String>, amount_msat: u64, | |||
&self, offer: &Offer, payer_note: Option<String>, amount_msat: u64, quantity: Option<u64>, |
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.
Let's move amount_msat
directly after offer
to have all optional fields at the end.
1b0f4da
to
31f517d
Compare
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.
One comment, otherwise LGTM.
Also feel free to rebase to fix CI
31f517d
to
f35c8bb
Compare
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.
Cool, just two more nits.
Also, could we add some test coverage asserting that the payer_note
and quantity
we're setting while sending/initiating refunds actually appear as expected on the receiver's end?
f35c8bb
to
4788f82
Compare
@tnull I pushed an updated |
Ah, this seems to be a bug (?), i.e. the I think for now we just want to set the |
tests/integration_tests_rust.rs
Outdated
@@ -425,16 +425,27 @@ fn simple_bolt12_send_receive() { | |||
|
|||
let expected_amount_msat = 100_000_000; | |||
let offer = node_b.bolt12_payment().receive(expected_amount_msat, "asdf").unwrap(); | |||
let payment_id = node_a.bolt12_payment().send(&offer, None).unwrap(); | |||
let quantity = Some(1); |
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.
Could you prefix the expected quantity and payer note with expected_
? This also avoids the necessity to rename the fields in the match statements below.
Thanks for pointing that out! But, I noticed that it's not just |
Well this is expected: if you don't set a |
Ah okay! Makes sense |
4788f82
to
afe0c65
Compare
afe0c65
to
c34abe3
Compare
rebased |
Mh, I think you'll need another rebase, seems the CI caching issue wasn't fully fixed afterall. Sorry! |
3bbba2f
to
b45b799
Compare
So while setting the quantity 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.
So while setting the quantity to None when sending a payment via the bolt12 send results in a an InvoiceRequestCreationFailed. The only way I was able to get around it was defaulting the quantity to 1 when the user sets it to None. I know this isn't ideal though
Right, this is expected as you're currently always setting supported_quantity
on the offer. Please let's just not do this and drop the default quantity of 1
.
b45b799
to
ecf91cb
Compare
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.
LGTM
One tiny nit, feel free to address it while squashing in the (last) fixup commit, so we can land this PR ASAP.
Add support for including `payer_note` in `Bolt12Offer` and `PaymentKind::Bolt12` and updated the relevant code to handle where the new `payer_note` field was required.
ecf91cb
to
683bfb3
Compare
Okay, squashed! |
Resolves #320
This PR adds support for including the
payer_note
field inPaymentKind::Bolt12
. It also updates the relevant parts of the code to handle wherepayer_note
is required.