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

LSPS2: ability to signal channel open failure #137

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

johncantrell97
Copy link
Contributor

Closes #130

There are a number of reasons a channel open might fail or be abandoned by the LSP. This adds a way for the LSP to signal back to the library that this has happened.

All pending payments are failed backwards and the channel state is reset to PendingInitialPayment as per the spec. This allows the payer to try again.

@johncantrell97 johncantrell97 changed the title ability to signal channel open failure LSPS2: ability to signal channel open failure May 17, 2024
Copy link
Collaborator

@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.

Excuse the delay here!

LGTM, mod some minor questions/nits.

///
/// Should be called in response to receiving a [`LSPS2ServiceEvent::OpenChannel`] event.
///
/// The JIT channel state is reset such that the payer can attempt payment again.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we also expose a "abandon" variant that doesn't reset, but just prunes all state related to the channel open?

@@ -898,6 +904,79 @@ where
Ok(())
}

/// Used by LSP to fail intercepted htlcs backwards when the channel open fails for any reason.
///
/// Should be called in response to receiving a [`LSPS2ServiceEvent::OpenChannel`] event.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment is a bit misleading. It should be called after we get the event, but of course only if the channel open failed?

@@ -49,8 +49,8 @@ impl PaymentQueue {
position.map(|position| self.payments.remove(position))
}

pub(crate) fn clear(&mut self) -> Vec<InterceptedHTLC> {
self.payments.drain(..).map(|(_k, v)| v).flatten().collect()
pub(crate) fn clear(&mut self) -> Vec<(PaymentHash, Vec<InterceptedHTLC>)> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Not sure this change is worth as it makes things more complex and you only make use of it in one place where you then have to map to get rid of the InterceptedHTLCs. Why not just use InterceptedHTLC::payment_hash instead? If you're worried about duplicates, could just use dedup or collect a HashSet?

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
2 participants