Skip to content

Commit ac57163

Browse files
committed
Account for leftover fee budget when retrying PartialFailures
1 parent b1a878f commit ac57163

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

lightning/src/ln/outbound_payment.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,14 +1322,19 @@ impl OutboundPayments {
13221322
let mut has_ok = false;
13231323
let mut has_err = false;
13241324
let mut pending_amt_unsent = 0;
1325+
let mut total_ok_fees_msat = 0;
13251326
for (res, path) in results.iter().zip(route.paths.iter()) {
1326-
if res.is_ok() { has_ok = true; }
1327+
if res.is_ok() {
1328+
has_ok = true;
1329+
total_ok_fees_msat += path.fee_msat();
1330+
}
13271331
if res.is_err() { has_err = true; }
13281332
if let &Err(APIError::MonitorUpdateInProgress) = res {
13291333
// MonitorUpdateInProgress is inherently unsafe to retry, so we call it a
13301334
// PartialFailure.
13311335
has_err = true;
13321336
has_ok = true;
1337+
total_ok_fees_msat += path.fee_msat();
13331338
} else if res.is_err() {
13341339
pending_amt_unsent += path.final_value_msat();
13351340
}
@@ -1339,12 +1344,15 @@ impl OutboundPayments {
13391344
results,
13401345
payment_id,
13411346
failed_paths_retry: if pending_amt_unsent != 0 {
1342-
if let Some(payment_params) = route.route_params.as_ref().map(|p| p.payment_params.clone()) {
1343-
Some(RouteParameters {
1344-
payment_params,
1345-
final_value_msat: pending_amt_unsent,
1346-
max_total_routing_fee_msat: None,
1347-
})
1347+
if let Some(route_params) = &route.route_params {
1348+
let mut route_params = route_params.clone();
1349+
// We calculate the leftover fee budget we're allowed to spend by
1350+
// subtracting the used fee from the total fee budget.
1351+
route_params.max_total_routing_fee_msat = route_params
1352+
.max_total_routing_fee_msat.map(|m| m.saturating_sub(total_ok_fees_msat));
1353+
route_params.final_value_msat = pending_amt_unsent;
1354+
1355+
Some(route_params)
13481356
} else { None }
13491357
} else { None },
13501358
})

0 commit comments

Comments
 (0)