Skip to content

Commit 95155d4

Browse files
committed
f Make payment cache removal happen at the callsite
1 parent 06a6dbc commit 95155d4

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

lightning-invoice/src/payment.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,14 @@ where
313313
// Some paths were sent, even if we failed to send the full MPP value our recipient may
314314
// misbehave and claim the funds, at which point we have to consider the payment sent,
315315
// so return `Ok()` here, ignoring any retry errors.
316-
let _ = self.retry_payment(true, payment_id, payment_hash, &retry);
316+
let _ = self.retry_payment(payment_id, payment_hash, &retry);
317317
Ok(payment_id)
318318
} else {
319319
self.pay_invoice_internal(invoice, amount_msats, retry_count + 1)
320320
}
321321
}
322322

323-
fn retry_payment(&self, other_paths_pending: bool, payment_id: PaymentId, payment_hash: PaymentHash, params: &RouteParameters)
323+
fn retry_payment(&self, payment_id: PaymentId, payment_hash: PaymentHash, params: &RouteParameters)
324324
-> Result<(), ()> {
325325
let route;
326326
{
@@ -339,11 +339,9 @@ where
339339

340340
if *attempts >= max_payment_attempts {
341341
log_trace!(self.logger, "Payment {} exceeded maximum attempts; not retrying (attempts: {})", log_bytes!(payment_hash.0), attempts);
342-
if !other_paths_pending { entry.remove(); }
343342
return Err(());
344343
} else if has_expired(params) {
345344
log_trace!(self.logger, "Invoice expired for payment {}; not retrying (attempts: {})", log_bytes!(payment_hash.0), attempts);
346-
if !other_paths_pending { entry.remove(); }
347345
return Err(());
348346
}
349347

@@ -352,7 +350,6 @@ where
352350
route = self.router.find_route(&payer, &params, Some(&first_hops.iter().collect::<Vec<_>>()), &self.scorer.lock());
353351
if route.is_err() {
354352
log_trace!(self.logger, "Failed to find a route for payment {}; not retrying (attempts: {})", log_bytes!(payment_hash.0), attempts);
355-
if !other_paths_pending { entry.remove(); }
356353
return Err(());
357354
}
358355
} else {
@@ -366,15 +363,14 @@ where
366363
Err(PaymentSendFailure::ParameterError(_)) |
367364
Err(PaymentSendFailure::PathParameterError(_)) => {
368365
log_trace!(self.logger, "Failed to retry for payment {} due to bogus route/payment data, not retrying.", log_bytes!(payment_hash.0));
369-
if !other_paths_pending { self.payment_cache.lock().unwrap().remove(&payment_hash); }
370366
return Err(());
371367
},
372368
Err(PaymentSendFailure::AllFailedRetrySafe(_)) => {
373-
self.retry_payment(other_paths_pending, payment_id, payment_hash, params)
369+
self.retry_payment(payment_id, payment_hash, params)
374370
},
375371
Err(PaymentSendFailure::PartialFailure { results: _, failed_paths_retry, .. }) => {
376372
if let Some(retry) = failed_paths_retry {
377-
self.retry_payment(true, payment_id, payment_hash, &retry)
373+
self.retry_payment(payment_id, payment_hash, &retry)
378374
} else {
379375
Ok(())
380376
}
@@ -420,19 +416,17 @@ where
420416

421417
if *rejected_by_dest {
422418
log_trace!(self.logger, "Payment {} rejected by destination; not retrying", log_bytes!(payment_hash.0));
423-
if *all_paths_failed { self.payment_cache.lock().unwrap().remove(payment_hash); }
424419
} else if payment_id.is_none() {
425420
log_trace!(self.logger, "Payment {} has no id; not retrying", log_bytes!(payment_hash.0));
426-
if *all_paths_failed { self.payment_cache.lock().unwrap().remove(payment_hash); }
427421
} else if let Some(params) = retry {
428-
if self.retry_payment(!all_paths_failed, payment_id.unwrap(), *payment_hash, params).is_ok() {
422+
if self.retry_payment(payment_id.unwrap(), *payment_hash, params).is_ok() {
429423
// We retried at least somewhat, don't provide the PaymentPathFailed event to the user.
430424
return;
431425
}
432426
} else {
433427
log_trace!(self.logger, "Payment {} missing retry params; not retrying", log_bytes!(payment_hash.0));
434-
if *all_paths_failed { self.payment_cache.lock().unwrap().remove(payment_hash); }
435428
}
429+
if *all_paths_failed { self.payment_cache.lock().unwrap().remove(payment_hash); }
436430
},
437431
Event::PaymentSent { payment_hash, .. } => {
438432
let mut payment_cache = self.payment_cache.lock().unwrap();

0 commit comments

Comments
 (0)