Skip to content

Use LocalHTLCFailureReason in Onion Processing #3744

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

Merged
merged 4 commits into from
May 2, 2025

Conversation

carlaKC
Copy link
Contributor

@carlaKC carlaKC commented Apr 17, 2025

This PR contains some of the follow ups that didn't make it into #3601:

  • Implement Display for LocalHTLCFailureReason
  • Use LocalHTLCFailureReason in onion error processing, removing the last few places where we were using raw u16 values
  • Adds a very simple macro to de-dup use of u16 failure codes in failure_code and from<u16> to dedup codes

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Apr 17, 2025

👋 Thanks for assigning @valentinewallace as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@carlaKC
Copy link
Contributor Author

carlaKC commented Apr 21, 2025

@joostjager anything else that you'd like to add here?

Copy link
Contributor

@joostjager joostjager left a comment

Choose a reason for hiding this comment

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

The only comment that I think may not be in this PR is #3601 (comment)

If that one still applies now of course.

@carlaKC
Copy link
Contributor Author

carlaKC commented Apr 23, 2025

The only comment that I think may not be in this PR is #3601 (comment)

Addressed in 2cc8799

@carlaKC carlaKC marked this pull request as ready for review April 23, 2025 13:43
@carlaKC carlaKC requested a review from joostjager April 23, 2025 13:43
@ldk-reviews-bot
Copy link

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

joostjager
joostjager previously approved these changes Apr 26, 2025
@ldk-reviews-bot
Copy link

✅ Added second reviewer: @wpaulino

@carlaKC
Copy link
Contributor Author

carlaKC commented Apr 28, 2025

@joostjager your approval came in before I could address last comment last comment - diff here 🙏

joostjager
joostjager previously approved these changes Apr 28, 2025
self.failure_code() == LocalHTLCFailureReason::IncorrectPaymentDetails.failure_code()
|| *self == LocalHTLCFailureReason::FinalIncorrectCLTVExpiry
|| *self == LocalHTLCFailureReason::FinalIncorrectHTLCAmount
|| *self == LocalHTLCFailureReason::MPPTimeout
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is intended to only apply to errors that directly map from onion codes, but we could also include InvalidKeysendPreimage and PaymentSecretRequired here if we expect this method to be used elsewhere in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

InvalidKeysendPreimage will already be covered by self.failure_code() == LocalHTLCFailureReason::IncorrectPaymentDetails.failure_code()

PaymentSecretRequired

I think I'll update the doc a bit to note that this is only dealing with bolt 04 codes? Because we'd never get this variant as a sender, and RequiredNodeFeature (which it maps to) isn't a recipient-specific error.

Comment on lines 1388 to 1392
error_code,
error_code.failure_code(),
debug_field,
log_bytes!(&err_packet.failuremsg[4..4 + debug_field_size]),
description
error_code
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: no need to log error_code twice, similar below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought it would be nice to log the variant name ({:?}) and the string ({}) so that the variant was easy to look up.

Will update based on whether we keep display.

cur_height, outgoing_cltv_value, msg.cltv_expiry,
) {
return Err(InboundHTLCErr {
msg: err_msg,
msg: "incoming cltv check failed",
Copy link
Contributor Author

@carlaKC carlaKC May 1, 2025

Choose a reason for hiding this comment

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

Just a note here for review: this msg loses a bit of granularity - previously it had the descriptive string, and now it's just got this generic statement because we can't get a &str from format!({:?}, reason)'s String that lives long enough (afaik).

I think that this is okay because peel_payment_onion isn't used anywhere in the codebase, and the new reason is now available to provide the information that's lost in the string. If it's not ok, I can revert check_incoming_htlc_cltv to still return &str, LocalHTLCFailureReason.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems legit 👍 Thanks for the diligence!

@carlaKC
Copy link
Contributor Author

carlaKC commented May 1, 2025

Dropped Display + updated logging, commit_check will fail because the logging changes are fixups.

@valentinewallace
Copy link
Contributor

valentinewallace commented May 1, 2025

Looks like this needs another test fix :( seems one of the formerly logged strings is being asserted on still?

Also good with a squash!

@carlaKC
Copy link
Contributor Author

carlaKC commented May 1, 2025

Looks like this needs another test fix :( seems one of the formerly logged strings is being asserted on still?

Squash should fix it, fixup commit contained the test fix so the unsquashed commit's build check failed 👍

nvm: enum variant name is logged twice not the expected once - diff to fix

In some places where we have LocalHTLCFailureReason, the string we're
passing around is redundant.

This isn't the case in all uses of LocalHTLCFailureReason, for example
InboundHTLCError provides additional information about payload and
blinding related errors that isn't captured in LocalHTLCFailureReason.
In these cases we keep the error string, tolerating some duplication.
carlaKC added 3 commits May 1, 2025 12:53
These error codes were removed from the specification seven years ago
to prevent probing, so we don't need to handle these cases anymore.
De-duplicate use of u16 failure codes by using a macro that will
match against each variant's failure_code instead.
@joostjager joostjager merged commit c9fb114 into lightningdevkit:main May 2, 2025
27 of 28 checks passed
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.

4 participants