Skip to content

Commit 2c2aa98

Browse files
committed
Account for leftover fee budget when retrying PartialFailures
1 parent 8421b0e commit 2c2aa98

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lightning/src/ln/outbound_payment.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1057,8 +1057,12 @@ 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
@@ -1075,8 +1079,14 @@ impl OutboundPayments {
10751079
payment_id,
10761080
failed_paths_retry: if pending_amt_unsent != 0 {
10771081
if let Some(payment_params) = &route.payment_params {
1082+
let mut payment_params = payment_params.clone();
1083+
// We calculate the leftover fee budget we're allowed to spend by
1084+
// subtracting the used fee from the total fee budget.
1085+
payment_params.max_total_routing_fee_msat = payment_params
1086+
.max_total_routing_fee_msat.map(|m| m.saturating_sub(total_ok_fees_msat));
1087+
10781088
Some(RouteParameters {
1079-
payment_params: payment_params.clone(),
1089+
payment_params,
10801090
final_value_msat: pending_amt_unsent,
10811091
})
10821092
} else { None }

0 commit comments

Comments
 (0)