@@ -1322,14 +1322,19 @@ impl OutboundPayments {
1322
1322
let mut has_ok = false ;
1323
1323
let mut has_err = false ;
1324
1324
let mut pending_amt_unsent = 0 ;
1325
+ let mut total_ok_fees_msat = 0 ;
1325
1326
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
+ }
1327
1331
if res. is_err ( ) { has_err = true ; }
1328
1332
if let & Err ( APIError :: MonitorUpdateInProgress ) = res {
1329
1333
// MonitorUpdateInProgress is inherently unsafe to retry, so we call it a
1330
1334
// PartialFailure.
1331
1335
has_err = true ;
1332
1336
has_ok = true ;
1337
+ total_ok_fees_msat += path. fee_msat ( ) ;
1333
1338
} else if res. is_err ( ) {
1334
1339
pending_amt_unsent += path. final_value_msat ( ) ;
1335
1340
}
@@ -1339,12 +1344,15 @@ impl OutboundPayments {
1339
1344
results,
1340
1345
payment_id,
1341
1346
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)
1348
1356
} else { None }
1349
1357
} else { None } ,
1350
1358
} )
0 commit comments