Skip to content

Commit 90ef352

Browse files
committed
Account for leftover fee budget when retrying PartialFailures
1 parent caf0298 commit 90ef352

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lightning/src/ln/outbound_payment.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -1057,14 +1057,19 @@ impl OutboundPayments {
10571057
let mut has_ok = false;
10581058
let mut has_err = false;
10591059
let mut pending_amt_unsent = 0;
1060+
let mut total_ok_fees_msat = 0;
10601061
for (res, path) in results.iter().zip(route.paths.iter()) {
1061-
if res.is_ok() { has_ok = true; }
1062+
if res.is_ok() {
1063+
has_ok = true;
1064+
total_ok_fees_msat += path.fee_msat();
1065+
}
10621066
if res.is_err() { has_err = true; }
10631067
if let &Err(APIError::MonitorUpdateInProgress) = res {
10641068
// MonitorUpdateInProgress is inherently unsafe to retry, so we call it a
10651069
// PartialFailure.
10661070
has_err = true;
10671071
has_ok = true;
1072+
total_ok_fees_msat += path.fee_msat();
10681073
} else if res.is_err() {
10691074
pending_amt_unsent += path.final_value_msat();
10701075
}
@@ -1075,8 +1080,14 @@ impl OutboundPayments {
10751080
payment_id,
10761081
failed_paths_retry: if pending_amt_unsent != 0 {
10771082
if let Some(payment_params) = &route.payment_params {
1083+
let mut payment_params = payment_params.clone();
1084+
// We calculate the leftover fee budget we're allowed to spend by
1085+
// subtracting the used fee from the total fee budget.
1086+
payment_params.max_total_routing_fee_msat = payment_params
1087+
.max_total_routing_fee_msat.map(|m| m.saturating_sub(total_ok_fees_msat));
1088+
10781089
Some(RouteParameters {
1079-
payment_params: payment_params.clone(),
1090+
payment_params,
10801091
final_value_msat: pending_amt_unsent,
10811092
})
10821093
} else { None }

0 commit comments

Comments
 (0)