-
Notifications
You must be signed in to change notification settings - Fork 402
(3/3) Add Failure Reason to HTLCHandlingFailed #3700
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
base: main
Are you sure you want to change the base?
Conversation
👋 Thanks for assigning @joostjager as a reviewer! |
d049301
to
6138779
Compare
6138779
to
2d39ef8
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3700 +/- ##
==========================================
+ Coverage 89.13% 89.60% +0.46%
==========================================
Files 156 158 +2
Lines 123600 127663 +4063
Branches 123600 127663 +4063
==========================================
+ Hits 110176 114390 +4214
+ Misses 10757 10640 -117
+ Partials 2667 2633 -34 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
2d39ef8
to
b48c6ce
Compare
Needs rebase 🥳 |
b48c6ce
to
cda8de5
Compare
🔔 1st Reminder Hey @valentinewallace! This PR has been waiting for your review. |
cda8de5
to
6638118
Compare
Pushed suggested comment/style changes + rename of Happy to drop the last two commits as discussed here if the renames aren't strong enough to justify the change! |
Downstream, | ||
/// The HTLC was failed locally by our node. | ||
Local { | ||
/// The reason that our node chose to fail the HTLC. | ||
reason: LocalHTLCFailureReason, | ||
}, |
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'm wondering if it would be nicer to avoid this outer enum and just document on the field "Will be None if the HTLC failed downstream or this event was created prior to 0.2." Seems simpler, loses a bit of information for a period of time though.
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 think that it would be nice to surface hold_time
along with Downstream
in future (nice thing to put on a dashboard IMO) so tend towards keeping the enum for the sake of being able to easily add that.
Opinion not very strongly held though.
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.
Oh, I didn't realize that was a potential goal but that makes sense! We may want to document this on the attributable failures issue, if there is one.
lightning/src/events/mod.rs
Outdated
// [`LocalHTLCFailureReason::UnknownNextHop`]. This will cover both the case | ||
// where we have a legacy 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.
nit: incomplete sentence
lightning/src/events/mod.rs
Outdated
@@ -480,12 +480,16 @@ pub enum HTLCHandlingType { | |||
channel_id: ChannelId, | |||
}, | |||
/// Scenario where we are unsure of the next node to forward the HTLC to. | |||
/// | |||
/// Deprecated: will only be used in versions before LDK v0.2.0. |
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 think you can use the official deprecated
attribute on this: https://doc.rust-lang.org/reference/attributes/diagnostics.html#r-attributes.diagnostics.deprecated
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.
TIL this exists!
Struggling to #[allow(deprecated)]
for the impl_writeable_tlv_based_enum_upgradable
invocation to silence the cargo warning though..
6638118
to
c78304f
Compare
Removed the last 2 rename commits (I don't think they're that much of an improvement) + fixed up comment. Couldn't find a way to use deprecation attribute without making changes to the serialization macro so left it out. |
lightning/src/events/mod.rs
Outdated
/// The type of HTLC that was handled. | ||
handling_type: HTLCHandlingType, | ||
/// The reason that the HTLC failed. | ||
/// | ||
/// This field will be `None` only for objects serialized prior to LDK 0.2.0. | ||
handling_failure: Option<HTLCHandlingFailureReason> |
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.
Consulted @jkczyz our resident naming expert --
He suggested renaming HTLCHandlingType
to HTLCHandlingFailureType
, and renaming the fields within the event to failure_type
and failure_reason
. This would also imply possibly renaming the HTLCHandlingFailureType::ReceiveFailed
to just ::Receive
, similarly for forwards. Reasoning being that the type of HTLC handling is moreso the type of failure, conceptually (Jeff feel free to correct me here).
Thoughts on this naming scheme? cc @joostjager
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.
Sounds like an improvement to me.
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.
🫡 gone ahead and also changed ForwardFailed
-> Forward
with the same reasoning as ReceiveFailed
-> Receive
HTLCDestination currently contains a combination of information about the type of HTLC we handled to fail (a payment, a forward etc) and error information for a select set of cases (unknown next peer, for example). In preparation for a refactor that will split the failure reason out into its own enum, this commit renames HTLCDestination to HTLCHandlingType.
Rename variant to be more specific to the current context - a FailedPayment could be a payment that we failed to dispatch or one that we rejected on receive.
Standardize naming within the HTLCHandlingType struct to present more consistent API terminology.
This variant of HTLCHandlingType contains information about the failure cause along with its type - as an UnknownNextPeer is just an InvalidForward that has the failure type UnknownNextPeer. This commit deprecates the variant's use, while still writing it to disk to allow the option to downgrade. The deprecated attribute is not used because it cannot be silenced in impl_writeable_tlv_based_enum, which uses UnknownNextPeer to remain downgradable.
c78304f
to
51eb743
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.
Nothing blocking if we want to Just Land and save the ser tweak for follow-up
lightning/src/events/mod.rs
Outdated
let downgradable_type = match (failure_type, failure_reason) { | ||
(HTLCHandlingFailureType::InvalidForward { requested_forward_scid }, | ||
Some(HTLCHandlingFailureReason::Local { | ||
reason: LocalHTLCFailureReason::UnknownNextPeer | ||
})) | ||
=> HTLCHandlingFailureType::UnknownNextHop { | ||
requested_forward_scid: *requested_forward_scid, | ||
}, | ||
_ => failure_type.clone() | ||
}; |
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.
Apologies if I signed off on this previously, but I think it would make more sense to always write the non-deprecated type and then include a release note that downgrades will result in reading the deprecated type as ::InvalidForward
, since it'll save some complexity here and keep the door open for us to delete the variant in the future.
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.
Having done it this way, I think it looks much better 👍 doesn't seem like that much of a loss to have less information on downgrade in comparison
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.
Are there no functional consequences after the downgrade for this loss of information?
lightning/src/events/mod.rs
Outdated
failure_reason: Some(LocalHTLCFailureReason::UnknownNextPeer.into()), | ||
} | ||
} | ||
_ => panic!("HTLCHandlingFailed wrong type") |
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.
Wait, is this panic reachable? May want to just remove it or use debug_assert
instead
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.
Yikes yeah, reverted to just match on HTLCHandlingType
(was like this before change suggestion) - think the panic should be ok if it's for a variant we just declared right above?
This allows us to more easily get rid of this variant (as we stop writing it), and removes the need for custom serialization. The tradeoff here is that downgrading nodes lose some information, as the UnknownNextPeer variant will be represented as InvalidForward (because they can't read the accompanying reason that specifies that it's a UnknownNextPeer.
This PR surfaces a failure reason in
HTLCHandlingFailed
events. Opening up early to add some context to the prefactor PR #3601.The heart of the PR is in d35d35f, and it could probably be reduced to just this commit. I've made some quite opinionated renaming / deprecation decisions in the other commits which aren't required for this change, but I think make for a more readable API overall - happy to drop them if it ain't broke, don't fix it applies.
Fixes: #3561
Fixes: #3541