Skip to content

LSPS2: Fail (or abandon) intercepted HTLCs if LSP channel open fails #3712

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

martinsaposnic
Copy link

Closes #3479

Allows the LSP to signal when a channel open fails or is abandoned.

  • Fail variant: All pending payments are failed backward, and the channel state resets to PendingInitialPayment, allowing the payer to retry.
  • Abandon variant: Instead of resetting for retrial, this prunes all channel-related state, fully discarding the attempt.

Inspired by previous work and a suggestion from @tnull to add an abandon variant apart from the reset.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Apr 7, 2025

👋 Thanks for assigning @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

Copy link

codecov bot commented Apr 7, 2025

Codecov Report

Attention: Patch coverage is 85.71429% with 10 lines in your changes missing coverage. Please review.

Project coverage is 89.04%. Comparing base (c4d23bc) to head (0d8ba10).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
lightning-liquidity/src/lsps2/service.rs 85.71% 5 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3712      +/-   ##
==========================================
- Coverage   89.05%   89.04%   -0.02%     
==========================================
  Files         155      155              
  Lines      122019   122162     +143     
  Branches   122019   122162     +143     
==========================================
+ Hits       108666   108774     +108     
- Misses      10695    10717      +22     
- Partials     2658     2671      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tnull tnull requested review from tnull and removed request for valentinewallace April 7, 2025 17:10
Add two LSPS2Service methods:
'Abandoned' prunes all channel open state.
'Failed' resets JIT channel to fail HTLCs.
It allows a retry on channel open.
Closes lightningdevkit#3479.
Add integration tests to verify channel open reset and
pruning handlers. Tests cover:
- channel_open_failed resetting state to allow retry.
- channel_open_failed error on invalid state.
- channel_open_abandoned pruning all open state.
- error handling for nonexistent channels.
@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 2nd Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 3rd Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

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.

Thanks for looking into this, and excuse the delay! We'll probably wait with this until after #3509 landed either way though.

/// without resetting the state for a potential payment retry. It removes the intercept SCID
/// mapping along with any outbound channel state and related channel ID mappings associated with
/// the specified `user_channel_id`.
pub fn channel_open_abandoned(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think to make this a bit safer, it should probably fail if we're already at PendingPaymentForward or later, i.e., we already opened the channel?

Also, what would happen if this is called after the LSPS2ServiceEvent::OpenChannel has been emitted?

})?;

let jit_channel = peer_state
.outbound_channels_by_intercept_scid
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: indentation seems off.

),
})?;

jit_channel.state = match &jit_channel.state {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use the matches! macro here?

@@ -24,6 +25,7 @@ use lightning_invoice::{Bolt11Invoice, InvoiceBuilder, RoutingFees};
use bitcoin::hashes::{sha256, Hash};
use bitcoin::secp256k1::{PublicKey, Secp256k1};
use bitcoin::Network;
use lightning_types::payment::PaymentHash;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: move import up.

@ldk-reviews-bot
Copy link

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

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.

LSPS2: Fail intercepted htlcs if lsp open channel fails for whatever reason
3 participants