-
Notifications
You must be signed in to change notification settings - Fork 402
Include routing failures in Bolt12PaymentError
#3171
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
Conversation
Instead of returning Ok when path finding fails, allow returning a RetryableSendFailure from send_payment_for_bolt12_invoice. Follow up commits will return such failures.
This will be used later in send_payment_for_bolt12_invoice instead of find_route_and_send_payment as it will allow for returning RetryableSendFailure when path finding fails.
900c10f
to
2f087ab
Compare
I attempted to remove |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3171 +/- ##
==========================================
+ Coverage 89.74% 91.07% +1.32%
==========================================
Files 121 121
Lines 99858 111148 +11290
Branches 99858 111148 +11290
==========================================
+ Hits 89622 101230 +11608
+ Misses 7561 7427 -134
+ Partials 2675 2491 -184 ☔ View full report in Codecov by Sentry. |
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.
Mostly looks good to me, just a few nits/questions.
It also seems this only addresses the first point of #3159, i.e., we currently don't early-abort before sending the invoice request if we're positive that we'll be unable to send the payment. Should we address this in another PR? In this case it might be worth opening a separate issue for it?
Ok(route) => route, | ||
Err(e) => { | ||
let reason = match e { | ||
RetryableSendFailure::PaymentExpired => PaymentFailureReason::PaymentExpired, |
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.
Is it worth implementing From<RetryableSendFailure> for PaymentFailureReason
? Or wouldn't it be reusable outside of this context?
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.
Hmmm... I considered it but it seemed a bit out of place importing RetryableSendFailure
in the events
module. Might be worth taking a look at how to we might better organize these errors given some of the duplication between RetryableSendFailure
and Bolt12PaymentError
along with the event reason.
*payment.into_mut() = retryable_payment; | ||
(total_amount, recipient_onion, None, onion_session_privs) | ||
PendingOutboundPayment::InvoiceReceived { .. } => { | ||
log_error!(logger, "Payment already initiating"); |
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.
Should this log include the payment hash?
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.
We could though, I'm wondering also if we should make this a log_trace
. Given we'll send multiple invoice requests, we'll likely see multiple invoices even though we'll only handle the first one. The others may hit this case since the lock is released after transition to this state while path finding but before the payment is made.
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.
Actually, I was mistaken. We should never hit this case just like PendingOutboundPayment::AwaitingInvoice
. When we release the lock in send_payment_for_bolt12_invoice
, the payment will have transitioned to PendingOutboundPayment::AwaitingInvoice
. So attempting to handle another invoice with the same id will cause us to return Bolt12PaymentError::DuplicateInvoice
.
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.
Mhh, should this be a debug_assert
then?
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.
Done and did the same for PendingOutboundPayment::AwaitingInvoice
.
Yeah, let's do another PR for the second part. @slanesuke Do you think that's something you can look at? I'm juggling a few other tasks at the moment. |
Cool, now moved the second part to this issue: #3174 |
Yeah, I'll take care of it. |
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.
Feel free to squash the fixups
The BOLT11 and BOLT12 outbound payment initiation code differ in that the latter re-uses the retry path (i.e., find_route_and_send_payment). The drawback of this is that Ok is returned even if there is an error finding a route. Refactor send_payment_for_bolt12_invoice such that it re-uses find_initial_route instead so that errors can be returned.
579ebd1
to
b697fbe
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.
LGTM
Landing this without second reviewer as the changeset is manageable.
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.
Post-merge LGTM
Instead of returning
Ok
when path finding fails, allow returning aRetryableSendFailure
fromsend_payment_for_bolt12_invoice
. The BOLT11 and BOLT12 outbound payment initiation code differ in that the latter re-uses the retry path (i.e.,find_route_and_send_payment
). The drawback of this is thatOk
is returned even if there is an error finding a route. Refactorsend_payment_for_bolt12_invoice
such that it re-usesfind_initial_route
instead so that errors can be returned.Fixes #3159