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

(3/3) Add Failure Reason to HTLCHandlingFailed #3700

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

carlaKC
Copy link
Contributor

@carlaKC carlaKC commented Apr 2, 2025

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 6df8025, 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

@ldk-reviews-bot
Copy link

👋 Hi! I see this is a draft PR.
I'll wait to assign reviewers until you mark it as ready for review.
Just convert it out of draft status when you're ready for review!

@carlaKC carlaKC changed the title Add Failure Reason to HTLCHandlingFailed (3/3) Add Failure Reason to HTLCHandlingFailed Apr 2, 2025
@carlaKC carlaKC force-pushed the 3541-api-changes branch 2 times, most recently from d049301 to 6138779 Compare April 4, 2025 20:36
/// The HTLC was failed locally by our node.
Local {
/// The reason that our node chose to fail the HTLC.
reason: LocalHTLCFailureReason,
Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts on renaming LocalHTLCFailureReason to HTLCFailureReason? Then we can have Downstream just be a variant within the big enum and use the same big enum for the handling_failure field. It's a bit awkward that HTLCFailReason is another type in the codebase, but that could either be renamed to RawOnionFailure (no pun intended) or something, or punted for later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then we can have Downstream just be a variant within the big enum and use the same big enum for the handling_failure field. It

Doesn't this get a bit mesy when it comes to mapping to B04 codes because Downstream wouldn't have a value?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I was missing that. Good point indeed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Echo your sentiment though, sinceHTLCHandlingFailureReason is pretty much just an API-facing version of HTLCFailReason (hiding all the onion details the API doesn't care about) it is confusing to have two pretty similar structs.

Might still be worth doing a rename of HTLCFailReason?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I tend to agree that a rename would still be nice. Looks like ~70 occurrences of HTLCFailReason currently, I think if you're up for it then go for it!

carlaKC added 17 commits April 11, 2025 10:40
Introduce an enum representation of BOLT04 error codes that will be
introduced in the commits that follow, along with being extended to
represent failures that are otherwise erased by BOLT04 error codes
(insufficient liquidity which is erased by temporary channel failure,
for example).
Now that we're passing around more than a BOLT04 error code, rename
the field accordingly.
Now that we're not passing BOLT04 error codes around, rename the field
accordingly.
Now that we're not passing around error codes, update variable names
accordingly.
Update the failure reason that's persisted in HTLCFailReasonRepr to
store our newly added enum, rather than the old u16. In the commits
that follow, we'll add more variants create a many-to-one mapping
from enum to BOLT04 code (as we're surfacing internal information that
is intentionally erased by the BOLT04 codes). Without this change to
persistence, we'll lose the detail that these variants contain by
storing them as their erased BOLT04 code.
Sometimes the error codes that we return to the sender intentionally
obscure information about the payment to prevent probing/ leaking
information. This commit updates our internal representation to
surface some of these failures, which will be converted to their
corresponding bolt 04 codes when they're sent over the wire.
To be able to obtain the underlying error reason for the pending HTLC,
break up the helper method into two parts. This also removes some
unnecessary wrapping/unwrapping of messages in PendingHTLCStatus types.
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 infromation 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.
This struct doesn't just contain a failure reason, it has all the data
that's used to construct our failure.
Copy link

codecov bot commented Apr 11, 2025

Codecov Report

Attention: Patch coverage is 86.67546% with 101 lines in your changes missing coverage. Please review.

Project coverage is 89.09%. Comparing base (83e9e80) to head (2d39ef8).

Files with missing lines Patch % Lines
lightning/src/events/mod.rs 8.33% 33 Missing ⚠️
lightning/src/ln/onion_payment.rs 69.49% 16 Missing and 2 partials ⚠️
lightning/src/ln/onion_utils.rs 90.16% 18 Missing ⚠️
lightning/src/ln/channelmanager.rs 90.44% 16 Missing and 1 partial ⚠️
lightning/src/ln/channel.rs 77.55% 9 Missing and 2 partials ⚠️
lightning-liquidity/src/lsps2/service.rs 0.00% 2 Missing ⚠️
lightning/src/ln/functional_test_utils.rs 90.00% 0 Missing and 1 partial ⚠️
lightning/src/ln/monitor_tests.rs 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3700      +/-   ##
==========================================
- Coverage   89.12%   89.09%   -0.04%     
==========================================
  Files         156      156              
  Lines      123514   123670     +156     
  Branches   123514   123670     +156     
==========================================
+ Hits       110086   110186     +100     
- Misses      10749    10799      +50     
- Partials     2679     2685       +6     

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

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.

Add a reason enum to HTLCDestination in some variants Give HTLCHandlingFailed a reason of some kind
3 participants