Skip to content

Commit 09dd163

Browse files
WIP: Abandon payment on behalf of the user on payment path failure
TODO: tests
1 parent 6dd807e commit 09dd163

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lightning/src/ln/outbound_payment.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,7 @@ impl OutboundPayments {
10031003
#[cfg(not(test))]
10041004
let (network_update, short_channel_id, payment_retryable, _, _) = onion_error.decode_onion_failure(secp_ctx, logger, &source);
10051005

1006+
let payment_is_probe = payment_is_probe(payment_hash, &payment_id, probing_cookie_secret);
10061007
let mut session_priv_bytes = [0; 32];
10071008
session_priv_bytes.copy_from_slice(&session_priv[..]);
10081009
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
@@ -1019,7 +1020,7 @@ impl OutboundPayments {
10191020
log_trace!(logger, "Received failure of HTLC with payment_hash {} after payment completion", log_bytes!(payment_hash.0));
10201021
return
10211022
}
1022-
let is_retryable_now = payment.get().is_auto_retryable_now();
1023+
let mut is_retryable_now = payment.get().is_auto_retryable_now();
10231024
if let Some(scid) = short_channel_id {
10241025
payment.get_mut().insert_previously_failed_scid(scid);
10251026
}
@@ -1050,6 +1051,12 @@ impl OutboundPayments {
10501051
});
10511052
}
10521053

1054+
// Abandon if we were rejected by the destination, the payment is not retryable, or no retry
1055+
// parameters are available
1056+
if !is_retryable_now || !payment_retryable || (!payment_is_probe && retry.is_none()) {
1057+
let _ = payment.get_mut().mark_abandoned(); // we'll only Err if it's a legacy payment
1058+
is_retryable_now = false;
1059+
}
10531060
if payment.get().remaining_parts() == 0 {
10541061
all_paths_failed = true;
10551062
if payment.get().abandoned() {
@@ -1069,7 +1076,7 @@ impl OutboundPayments {
10691076
log_trace!(logger, "Failing outbound payment HTLC with payment_hash {}", log_bytes!(payment_hash.0));
10701077

10711078
let path_failure = {
1072-
if payment_is_probe(payment_hash, &payment_id, probing_cookie_secret) {
1079+
if payment_is_probe {
10731080
if !payment_retryable {
10741081
events::Event::ProbeSuccessful {
10751082
payment_id: *payment_id,

0 commit comments

Comments
 (0)