Skip to content

Commit be1088a

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 8c99e34 commit be1088a

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lightning/src/ln/outbound_payment.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -1354,12 +1354,14 @@ impl OutboundPayments {
13541354
}
13551355
let mut has_ok = false;
13561356
let mut has_err = false;
1357-
let mut pending_amt_unsent = 0;
1357+
let mut has_unsent = false;
13581358
let mut total_ok_fees_msat = 0;
1359+
let mut total_ok_amt_sent_msat = 0;
13591360
for (res, path) in results.iter().zip(route.paths.iter()) {
13601361
if res.is_ok() {
13611362
has_ok = true;
13621363
total_ok_fees_msat += path.fee_msat();
1364+
total_ok_amt_sent_msat += path.final_value_msat();
13631365
}
13641366
if res.is_err() { has_err = true; }
13651367
if let &Err(APIError::MonitorUpdateInProgress) = res {
@@ -1368,23 +1370,27 @@ impl OutboundPayments {
13681370
has_err = true;
13691371
has_ok = true;
13701372
total_ok_fees_msat += path.fee_msat();
1373+
total_ok_amt_sent_msat += path.final_value_msat();
13711374
} else if res.is_err() {
1372-
pending_amt_unsent += path.final_value_msat();
1375+
has_unsent = true;
13731376
}
13741377
}
13751378
if has_err && has_ok {
13761379
Err(PaymentSendFailure::PartialFailure {
13771380
results,
13781381
payment_id,
1379-
failed_paths_retry: if pending_amt_unsent != 0 {
1382+
failed_paths_retry: if has_unsent {
13801383
if let Some(route_params) = &route.route_params {
13811384
let mut route_params = route_params.clone();
13821385
// We calculate the leftover fee budget we're allowed to spend by
13831386
// subtracting the used fee from the total fee budget.
13841387
route_params.max_total_routing_fee_msat = route_params
13851388
.max_total_routing_fee_msat.map(|m| m.saturating_sub(total_ok_fees_msat));
1386-
route_params.final_value_msat = pending_amt_unsent;
13871389

1390+
// We calculate the remaining target amount by subtracting the succeded
1391+
// path values.
1392+
route_params.final_value_msat = route_params.final_value_msat
1393+
.saturating_sub(total_ok_amt_sent_msat);
13881394
Some(route_params)
13891395
} else { None }
13901396
} else { None },

lightning/src/ln/payment_tests.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2736,9 +2736,7 @@ fn retry_multi_path_single_failed_payment() {
27362736
let mut pay_params = route.route_params.clone().unwrap().payment_params;
27372737
pay_params.previously_failed_channels.push(chans[1].short_channel_id.unwrap());
27382738

2739-
// Note that the second request here requests the amount we originally failed to send,
2740-
// not the amount remaining on the full payment, which should be changed.
2741-
let mut retry_params = RouteParameters::from_payment_params_and_value(pay_params, 100_000_001);
2739+
let mut retry_params = RouteParameters::from_payment_params_and_value(pay_params, 100_000_000);
27422740
retry_params.max_total_routing_fee_msat = None;
27432741
route.route_params.as_mut().unwrap().final_value_msat = 100_000_000;
27442742
nodes[0].router.expect_find_route(retry_params, Ok(route.clone()));

0 commit comments

Comments
 (0)