@@ -1337,12 +1337,14 @@ impl OutboundPayments {
1337
1337
}
1338
1338
let mut has_ok = false ;
1339
1339
let mut has_err = false ;
1340
- let mut pending_amt_unsent = 0 ;
1340
+ let mut has_unsent = false ;
1341
1341
let mut total_ok_fees_msat = 0 ;
1342
+ let mut total_ok_amt_sent_msat = 0 ;
1342
1343
for ( res, path) in results. iter ( ) . zip ( route. paths . iter ( ) ) {
1343
1344
if res. is_ok ( ) {
1344
1345
has_ok = true ;
1345
1346
total_ok_fees_msat += path. fee_msat ( ) ;
1347
+ total_ok_amt_sent_msat += path. final_value_msat ( ) ;
1346
1348
}
1347
1349
if res. is_err ( ) { has_err = true ; }
1348
1350
if let & Err ( APIError :: MonitorUpdateInProgress ) = res {
@@ -1351,23 +1353,28 @@ impl OutboundPayments {
1351
1353
has_err = true ;
1352
1354
has_ok = true ;
1353
1355
total_ok_fees_msat += path. fee_msat ( ) ;
1356
+ total_ok_amt_sent_msat += path. final_value_msat ( ) ;
1354
1357
} else if res. is_err ( ) {
1355
- pending_amt_unsent += path . final_value_msat ( ) ;
1358
+ has_unsent = true ;
1356
1359
}
1357
1360
}
1358
1361
if has_err && has_ok {
1359
1362
Err ( PaymentSendFailure :: PartialFailure {
1360
1363
results,
1361
1364
payment_id,
1362
- failed_paths_retry : if pending_amt_unsent != 0 {
1365
+ failed_paths_retry : if has_unsent {
1363
1366
if let Some ( route_params) = & route. route_params {
1364
1367
let mut route_params = route_params. clone ( ) ;
1365
1368
// We calculate the leftover fee budget we're allowed to spend by
1366
1369
// subtracting the used fee from the total fee budget.
1367
1370
route_params. max_total_routing_fee_msat = route_params
1368
1371
. max_total_routing_fee_msat . map ( |m| m. saturating_sub ( total_ok_fees_msat) ) ;
1369
- route_params. final_value_msat = pending_amt_unsent;
1370
1372
1373
+ // We calculate the remaining target amount by subtracting the succeded
1374
+ // path values.
1375
+ let final_value_msat = core:: cmp:: min ( route_params. final_value_msat , route. get_total_amount ( ) ) ;
1376
+ route_params. final_value_msat = final_value_msat
1377
+ . saturating_sub ( total_ok_amt_sent_msat) ;
1371
1378
Some ( route_params)
1372
1379
} else { None }
1373
1380
} else { None } ,
0 commit comments