-
Notifications
You must be signed in to change notification settings - Fork 384
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
Add a reason to HTLCHandlingFailed event #3601
Open
carlaKC
wants to merge
1
commit into
lightningdevkit:main
Choose a base branch
from
carlaKC:3541-failure-reason
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+52
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -627,6 +627,26 @@ pub enum InboundChannelFunds { | |
DualFunded, | ||
} | ||
|
||
/// Used to describe the types of failures that may occur when handling HTLCs. | ||
#[derive(Clone, Debug, PartialEq, Eq)] | ||
pub enum HTLCHandlingFailure { | ||
/// The HTLC was failed by the local node. | ||
Local { | ||
/// The BOLT 04 failure code providing a specific failure reason. | ||
failure_code: u16 | ||
}, | ||
/// The HTLC was failed by the remote downstream node. The specific reason for failure is not | ||
/// known because it is encrypted. | ||
Remote, | ||
} | ||
|
||
impl_writeable_tlv_based_enum!(HTLCHandlingFailure, | ||
(0, Local) => { | ||
(0, failure_code, required) | ||
}, | ||
(1, Remote) => {}, | ||
); | ||
|
||
/// An Event which you should probably take some action in response to. | ||
/// | ||
/// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use | ||
|
@@ -1441,6 +1461,10 @@ pub enum Event { | |
prev_channel_id: ChannelId, | ||
/// Destination of the HTLC that failed to be processed. | ||
failed_next_destination: HTLCDestination, | ||
/// The cause of the processing failure. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its worth noting that |
||
/// | ||
/// This field will be `None` for objects serialized prior to LDK 0.1.1. | ||
reason: Option<HTLCHandlingFailure>, | ||
}, | ||
/// Indicates that a transaction originating from LDK needs to have its fee bumped. This event | ||
/// requires confirmed external funds to be readily available to spend. | ||
|
@@ -1743,10 +1767,11 @@ impl Writeable for Event { | |
(8, path.blinded_tail, option), | ||
}) | ||
}, | ||
&Event::HTLCHandlingFailed { ref prev_channel_id, ref failed_next_destination } => { | ||
&Event::HTLCHandlingFailed { ref prev_channel_id, ref failed_next_destination, ref reason} => { | ||
25u8.write(writer)?; | ||
write_tlv_fields!(writer, { | ||
(0, prev_channel_id, required), | ||
(1, reason, option), | ||
(2, failed_next_destination, required), | ||
}) | ||
}, | ||
|
@@ -2190,13 +2215,16 @@ impl MaybeReadable for Event { | |
let mut f = || { | ||
let mut prev_channel_id = ChannelId::new_zero(); | ||
let mut failed_next_destination_opt = UpgradableRequired(None); | ||
let mut reason = None; | ||
read_tlv_fields!(reader, { | ||
(0, prev_channel_id, required), | ||
(1, reason, option), | ||
(2, failed_next_destination_opt, upgradable_required), | ||
}); | ||
Ok(Some(Event::HTLCHandlingFailed { | ||
prev_channel_id, | ||
failed_next_destination: _init_tlv_based_struct_field!(failed_next_destination_opt, upgradable_required), | ||
reason, | ||
})) | ||
}; | ||
f() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 admit I'm not super excited about exposing the failure code as-is for two reasons - (a) we have very different constraints on the code - we may not always want to give the sender all the details about a failure (eg if the sender used a private channel but we didn't mean to expose it we might pretend the channel doesnt exist) vs what we want to tell the user about a failure (basically everything), (b) its not particularly easy to parse - users have to go read the BOLT then map that to what is actually happening in LDK code, if we had a big enum here we'd be able to provide good docs linking to config knobs and reasons why failures happened.
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.
Makes sense, will take a look at adding a more detailed enum or adding to
HTLCDestination
👍