Skip to content

Commit f39790d

Browse files
committed
Don't retry overpaid values for PartialFailures
Previously, if an overpaid path would fail immediately, we'd retry a `PartialFailure` with the full path amount, _including_ any overpayment. Here, we now subtract the succeeded paths' values from the net. value to exclude the overpaid amounts on retry.
1 parent 071b3f3 commit f39790d

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lightning/src/ln/outbound_payment.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -1337,12 +1337,14 @@ impl OutboundPayments {
13371337
}
13381338
let mut has_ok = false;
13391339
let mut has_err = false;
1340-
let mut pending_amt_unsent = 0;
1340+
let mut has_unsent = false;
13411341
let mut total_ok_fees_msat = 0;
1342+
let mut total_ok_amt_sent_msat = 0;
13421343
for (res, path) in results.iter().zip(route.paths.iter()) {
13431344
if res.is_ok() {
13441345
has_ok = true;
13451346
total_ok_fees_msat += path.fee_msat();
1347+
total_ok_amt_sent_msat += path.final_value_msat();
13461348
}
13471349
if res.is_err() { has_err = true; }
13481350
if let &Err(APIError::MonitorUpdateInProgress) = res {
@@ -1351,23 +1353,28 @@ impl OutboundPayments {
13511353
has_err = true;
13521354
has_ok = true;
13531355
total_ok_fees_msat += path.fee_msat();
1356+
total_ok_amt_sent_msat += path.final_value_msat();
13541357
} else if res.is_err() {
1355-
pending_amt_unsent += path.final_value_msat();
1358+
has_unsent = true;
13561359
}
13571360
}
13581361
if has_err && has_ok {
13591362
Err(PaymentSendFailure::PartialFailure {
13601363
results,
13611364
payment_id,
1362-
failed_paths_retry: if pending_amt_unsent != 0 {
1365+
failed_paths_retry: if has_unsent {
13631366
if let Some(route_params) = &route.route_params {
13641367
let mut route_params = route_params.clone();
13651368
// We calculate the leftover fee budget we're allowed to spend by
13661369
// subtracting the used fee from the total fee budget.
13671370
route_params.max_total_routing_fee_msat = route_params
13681371
.max_total_routing_fee_msat.map(|m| m.saturating_sub(total_ok_fees_msat));
1369-
route_params.final_value_msat = pending_amt_unsent;
13701372

1373+
// We calculate the remaining target amount by subtracting the succeded
1374+
// path values.
1375+
let final_value_msat = core::cmp::min(route_params.final_value_msat, route.get_total_amount());
1376+
route_params.final_value_msat = final_value_msat
1377+
.saturating_sub(total_ok_amt_sent_msat);
13711378
Some(route_params)
13721379
} else { None }
13731380
} else { None },

lightning/src/ln/payment_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2732,7 +2732,7 @@ fn retry_multi_path_single_failed_payment() {
27322732

27332733
// Note that the second request here requests the amount we originally failed to send,
27342734
// not the amount remaining on the full payment, which should be changed.
2735-
let mut retry_params = RouteParameters::from_payment_params_and_value(pay_params, 100_000_001);
2735+
let mut retry_params = RouteParameters::from_payment_params_and_value(pay_params, 100_000_000);
27362736
retry_params.max_total_routing_fee_msat = None;
27372737
nodes[0].router.expect_find_route(retry_params, Ok(route.clone()));
27382738

0 commit comments

Comments
 (0)