-
Notifications
You must be signed in to change notification settings - Fork 17
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
base: main
Are you sure you want to change the base?
LSPS2: ability to signal channel open failure #137
Conversation
494a03c
to
8a7886c
Compare
8a7886c
to
b82779c
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.
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. |
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.
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. |
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.
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>)> { |
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.
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 InterceptedHTLC
s. Why not just use InterceptedHTLC::payment_hash
instead? If you're worried about duplicates, could just use dedup
or collect a HashSet
?
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.