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

Allow claiming a payment if a channel with an HTLC has closed #2148

Merged

Conversation

TheBlueMatt
Copy link
Collaborator

Previously, LDK would refuse to claim a payment if a channel on
which the payment was received had been closed between when the
HTLC was received and when we went to claim it. This makes sense in
the payment case - why pay an on-chain fee to claim the HTLC when
presumably the sender may retry later. Long ago it also reduced
total code in the claim pipeline.

However, this doesn't make sense if you're trying to do an atomic
swap or some other protocol that requires atomicity with some other
action - if your money got claimed elsewhere you need to be able to
claim the HTLC in lightning no matter what. Further, this is an
over-optimization - there should be a very, very low likelihood
that a channel closes between when we receive the last HTLC for a
payment and the user goes to claim the payment. Since we now have
code to handle this anyway we should allow it.

Fixes #2017.

@TheBlueMatt TheBlueMatt added this to the 0.0.115 milestone Apr 4, 2023
@codecov-commenter
Copy link

codecov-commenter commented Apr 4, 2023

Codecov Report

Patch coverage: 97.36% and project coverage change: +0.63 🎉

Comparison is base (3b8bf93) 91.35% compared to head (8be723c) 91.98%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2148      +/-   ##
==========================================
+ Coverage   91.35%   91.98%   +0.63%     
==========================================
  Files         102      102              
  Lines       49909    54805    +4896     
  Branches    49909    54805    +4896     
==========================================
+ Hits        45592    50413    +4821     
- Misses       4317     4392      +75     
Impacted Files Coverage Δ
lightning/src/ln/payment_tests.rs 97.40% <96.87%> (-0.04%) ⬇️
lightning/src/events/mod.rs 33.15% <100.00%> (+2.30%) ⬆️
lightning/src/ln/chanmon_update_fail_tests.rs 98.59% <100.00%> (ø)
lightning/src/ln/channelmanager.rs 89.29% <100.00%> (+0.16%) ⬆️
lightning/src/ln/functional_test_utils.rs 92.60% <100.00%> (+<0.01%) ⬆️
lightning/src/ln/functional_tests.rs 99.03% <100.00%> (+0.80%) ⬆️

... and 8 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did #2017 (comment) not end up being needed?

lightning/src/ln/channelmanager.rs Show resolved Hide resolved
lightning/src/ln/payment_tests.rs Outdated Show resolved Hide resolved
@TheBlueMatt
Copy link
Collaborator Author

Did #2017 (comment) not end up being needed?

Yea, I think its fine if we put the timeout in the event? We could guarantee the timeout will be at least two blocks away but I'm not sure if we need to?

@wpaulino
Copy link
Contributor

wpaulino commented Apr 4, 2023

LGTM after squash

Previously, LDK would refuse to claim a payment if a channel on
which the payment was received had been closed between when the
HTLC was received and when we went to claim it. This makes sense in
the payment case - why pay an on-chain fee to claim the HTLC when
presumably the sender may retry later. Long ago it also reduced
total code in the claim pipeline.

However, this doesn't make sense if you're trying to do an atomic
swap or some other protocol that requires atomicity with some other
action - if your money got claimed elsewhere you need to be able to
claim the HTLC in lightning no matter what. Further, this is an
over-optimization - there should be a very, very low likelihood
that a channel closes between when we receive the last HTLC for a
payment and the user goes to claim the payment. Since we now have
code to handle this anyway we should allow it.

Fixes lightningdevkit#2017.
@TheBlueMatt
Copy link
Collaborator Author

Squashed without further changes.

tnull
tnull previously approved these changes Apr 5, 2023
Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a few generally non-blocking nits.

lightning/src/ln/chanmon_update_fail_tests.rs Show resolved Hide resolved
lightning/src/ln/payment_tests.rs Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
@tnull
Copy link
Contributor

tnull commented Apr 6, 2023

Feel free to squash the fixup!

Now that we guarantee `claim_payment` will always succeed we have
to let the user know what the deadline is. We still fail payments
if they haven't been claimed in time, which we now expose in
`PaymentClaimable`.
@TheBlueMatt TheBlueMatt merged commit 568a20b into lightningdevkit:main Apr 7, 2023
14 checks passed
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.

Support claiming from closed channels
4 participants