Skip to content
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

Support receiving async payments #3440

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

valentinewallace
Copy link
Contributor

@valentinewallace valentinewallace commented Dec 4, 2024

Finishes support for receiving async payments.

The last piece after this for the async-receive side is support for being the async receiver's LSP and serving invoices on their behalf.

Partially addresses #2298

Based on #3408, #3517
Also based on #2933, it enables the use of one of the test utils due to more uniform handling of HTLC receive failures.

@valentinewallace
Copy link
Contributor Author

This still needs some work and tests but I opened it in case it's useful for reviewing #3408.

@valentinewallace valentinewallace mentioned this pull request Dec 4, 2024
26 tasks
@valentinewallace valentinewallace force-pushed the 2024-12-async-payment-receive branch 2 times, most recently from 904adf6 to 6f7fcba Compare January 9, 2025 20:50
valentinewallace and others added 13 commits January 17, 2025 13:26
Blinded HTLCs are always failed back with the same error, so DRY the test code
that fails them backwards. This util will also be used for async payments
testing in upcoming commits.
Needed to authenticate that the held_htlc_available message is being sent over
a reply path that we originally created and that isn't expired before we reply
with release_held_htlc. This context will be used in upcoming commits when we
add support for async receive.
Prior to this patch, if we received an expired static invoice we would delay
surfacing the payment failure until after the recipient had come online and
sent the release_held_htlc OM, which could be a long time later. Now, we'll
detect that the invoice is expired as soon as it's received.
Here we bubble up the payment context into PendingHTLCRouting::ReceiveKeysend
and check it when receiving a spontaneous payment prior to generating a
claimable event. Prior to this patch, we would have accepted out-of-context
keysends sent over blinded paths taken from our BOLT 12 invoices.

As a side effect of this, our blinded keysend success test cases now fail, so
those tests are now removed. Their coverage is re-added in future commits when
we add support for async receive, meaning we're able to receive blinded
keysends in the correct payment context.
This argument will be asserted on in a future commit to ensure we obtain
the intended `HTLCHandlingFailed::failed_next_destination` per HTLC
failure.
This commit ensures all new incoming HTLCs going forward will have their
onion decoded when they become fully committed to decide how we should
proceed with each one. As a result, we'll obtain `HTLCHandlingFailed`
events for _any_ failed HTLC that comes across a channel.

Previously, we would evaluate the incoming HTLC within
`can_accept_incoming_htlc` upon receiving it, but not yet committed, so
we'd always have to account for it ourselves manually when checking
certain HTLC limits. With this change, we no longer need to do so as it
will already be accounted for within the pending HTLC stats computation.

We will now start writing channels with the new serialization version
(4), and we will still be able to downgrade back to the commit that
introduced it since reading version 4 is supported.

Note that existing pending inbound HTLCs may already have their
resolution if they were received in a previous version of LDK. We must
support those until we no longer allow downgrading beyond this commit.
Store an absolute expiry in blinded message contexts for inbound async
payments. Without this, anyone with the path corresponding to this context is
able to trivially ask if we're online forever.
If we receive a message that an HTLC is being held upstream for us, send a
reply onion message back releasing it since we are online to receive the
corresponding payment.
As part of receiving an async payment, we need to verify the sender's original
invoice request. Therefore, add support for parsing the invreq contained in the
onion and storing it in PendingHTLCForwards to prepare for when we add this
verification in an upcoming commit. The invreq also needs to be bubbled up for
inclusion in the PaymentClaimable event's PaymentPurpose.
After a lot of setup in prior commits, here we finally finish support for
receiving HTLCs paid to static BOLT 12 invoices. It amounts to verifying the
invoice request contained within the onion and generating the right
PaymentPurpose for the claimable event.
Previously, this test util did not account for config overrides supplied at
node creation time. Uncovered because it caused test nodes to be unable to
forward over private channels created with this util because that is not the
default.
In the previous commit we completed support for async receive from an
always-online sender to an often-offline receiver, minus support for acting as
the async receiver's always-online channel counterparty.
@valentinewallace valentinewallace force-pushed the 2024-12-async-payment-receive branch from 6f7fcba to f2ac259 Compare January 17, 2025 20:12
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.

2 participants