-
Notifications
You must be signed in to change notification settings - Fork 2.2k
switchrpc: improve TrackOnion error handling #10472
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: elle-base-branch-payment-service
Are you sure you want to change the base?
switchrpc: improve TrackOnion error handling #10472
Conversation
Summary of ChangesHello @calvinrzachman, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the error handling mechanism for the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request significantly improves error handling for the TrackOnion RPC by introducing structured error messages using protobuf's oneof feature. This is a great improvement over the previous string-based error reporting, making the API more robust and easier for clients to consume. The changes correctly separate RPC-level errors (communicated via gRPC status codes) from application-level payment failures. The implementation is solid, but I found one issue where the ErrorCode field is not being set for certain failure types, which I've commented on. Overall, this is a high-quality change that enhances the switchrpc API.
|
This leads to a code structure in the RPC client code like: switch result := trackResp.Result.(type) {
case *switchrpc.TrackOnionResponse_Preimage:
preimage, err := lntypes.MakePreimage(result.Preimage)
if err != nil {
// This is a data corruption error from the server. It
// is NOT a definitive payment failure.
}
// Do something with pre-image...
case *switchrpc.TrackOnionResponse_FailureDetails:
details := result.FailureDetails
translatedErr, err := switchrpc.UnmarshallFailureDetails(
details, deobfuscator,
)
// Do something to handle attempt result (either settle/fail or retry if uncertain) |
5575fec to
a70b135
Compare
307e665 to
3e0967d
Compare
The new structure uses a top-level `oneof` to provide a compile-time distinction between a successful payment (preimage) and a failed one. Additional information on a failed attempt can be found in FailureDetails. We now also use a structured ForwardingFailure type for communicating the failure index and wire message from failures which occur during htlc forwarding downstream in the route.
a70b135 to
7b98465
Compare
| hex.EncodeToString(buf.Bytes())), nil | ||
| // marshallFailureDetails creates the FailureDetails message for the | ||
| // TrackOnion response body. | ||
| func marshallFailureDetails(err error) *FailureDetails { |
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.
The code repetition here and in translageErrorForRPC isn't ideal, but I like the clarity of using one_of. Mabye we could do a similar approach in the SendOnion error to also add a ClearTextFailure.
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.
Yep, for sure. I have a similar PR incoming which updates the way SendOnion rpc communicates error information. It will remove translateErrorForRPC. Just wanted to keep the PRs as small as possible to facilitate review.
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.
One thing to consider is that SendOnion semantics differ a bit from TrackOnion. For TrackOnion, the gRPC request can itself be successful, but deliver information to the client about the failure of the given attempt ID being queried. For such failures, it makes sense to transport those via the RPC proto response message.
The SendOnion PR will likely move away from transporting error information via the proto response message. Instead we can reserve gRPC status status.OK for successful dispatches only and then transport structured error information via Details as mentioned in these docs:
I think this has added benefit to observability in that we'll be able to track gRPC failures/non-OK status for SendOnion endpoint more clearly to see if the remote router is having issues communicating with Switch RPC servers.
Change Description
Following up on some review comments from #9489, we explore an update to the communication of error information via
TrackOnionResponse.TrackOnionResponsethrough a top-leveloneof.ForwardingError, instead opting for structured protobuf messages (FailureDetails) to transport rich error details without loss of information.oneoffailure) withinFailureDetailsto carry specific failure types:ForwardingFailure,ClearTextFailure, or rawencrypted_error_databytes.TrackOnionquery itself (e.g., attempt not found, server unavailable) via standard gRPC status codes (codes.NotFound,codes.Unavailable), cleanly separating them from application-level payment outcomes in the response body.NOTE: This is a breaking change for clients. Though given that this RPC is not included in any release, this seems perfectly fine. A follow-up PR is planned for SendOnion.
Steps to Test
make itest icase=track_oniongo test -v -timeout 30s -tags switchrpc -run ^TestTrackOnion$ github.com/lightningnetwork/lnd/lnrpc/switchrpcgo test -v -timeout 30s -tags switchrpc github.com/lightningnetwork/lnd/lnrpc/switchrpc