Skip to content

Commit 5c07ed1

Browse files
f one match on pay error and fix buggy increment
1 parent af2ba27 commit 5c07ed1

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

lightning/src/ln/outbound_payment.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -486,34 +486,38 @@ impl OutboundPayments {
486486

487487
let res = self.retry_payment_with_route(&route, payment_id, entropy_source, node_signer, best_block_height, send_payment_along_path);
488488
match res {
489-
Err(PaymentSendFailure::AllFailedResendSafe(_)) | Err(PaymentSendFailure::PartialFailure { .. }) => {
489+
Err(PaymentSendFailure::AllFailedResendSafe(_)) => {
490490
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
491491
if let Some(payment) = outbounds.get_mut(&payment_id) {
492492
let retryable = payment.is_retryable_now();
493493
if retryable {
494494
payment.increment_attempts();
495495
} else { return res }
496496
} else { return res }
497-
}
498-
res => return res
499-
}
500-
match res {
501-
Err(PaymentSendFailure::AllFailedResendSafe(_)) => {
497+
core::mem::drop(outbounds);
502498
self.pay_internal(payment_id, route_params, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, send_payment_along_path)
503499
},
504-
Err(PaymentSendFailure::PartialFailure { failed_paths_retry, .. }) => {
505-
if let Some(retry) = failed_paths_retry {
506-
// Some paths were sent, even if we failed to send the full MPP value our recipient may
507-
// misbehave and claim the funds, at which point we have to consider the payment sent, so
508-
// return `Ok()` here, ignoring any retry errors.
509-
let _ = self.pay_internal(payment_id, retry, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, send_payment_along_path);
510-
Ok(())
511-
} else {
512-
// This may happen if we send a payment and some paths fail, but only due to a temporary
513-
// monitor failure or the like, implying they're really in-flight, but we haven't sent the
514-
// initial HTLC-Add messages yet.
515-
Ok(())
516-
}
500+
Err(PaymentSendFailure::PartialFailure { failed_paths_retry: Some(retry), results, .. }) => {
501+
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
502+
if let Some(payment) = outbounds.get_mut(&payment_id) {
503+
let retryable = payment.is_retryable_now();
504+
if retryable {
505+
payment.increment_attempts();
506+
} else { return Err(PaymentSendFailure::PartialFailure { failed_paths_retry: Some(retry), results, payment_id }) }
507+
} else { return Err(PaymentSendFailure::PartialFailure { failed_paths_retry: Some(retry), results, payment_id }) }
508+
core::mem::drop(outbounds);
509+
510+
// Some paths were sent, even if we failed to send the full MPP value our recipient may
511+
// misbehave and claim the funds, at which point we have to consider the payment sent, so
512+
// return `Ok()` here, ignoring any retry errors.
513+
let _ = self.pay_internal(payment_id, retry, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, send_payment_along_path);
514+
Ok(())
515+
},
516+
Err(PaymentSendFailure::PartialFailure { failed_paths_retry: None, .. }) => {
517+
// This may happen if we send a payment and some paths fail, but only due to a temporary
518+
// monitor failure or the like, implying they're really in-flight, but we haven't sent the
519+
// initial HTLC-Add messages yet.
520+
Ok(())
517521
},
518522
res => res,
519523
}

0 commit comments

Comments
 (0)