@@ -1354,12 +1354,14 @@ impl OutboundPayments {
1354
1354
}
1355
1355
let mut has_ok = false ;
1356
1356
let mut has_err = false ;
1357
- let mut pending_amt_unsent = 0 ;
1357
+ let mut has_unsent = false ;
1358
1358
let mut total_ok_fees_msat = 0 ;
1359
+ let mut total_ok_amt_sent_msat = 0 ;
1359
1360
for ( res, path) in results. iter ( ) . zip ( route. paths . iter ( ) ) {
1360
1361
if res. is_ok ( ) {
1361
1362
has_ok = true ;
1362
1363
total_ok_fees_msat += path. fee_msat ( ) ;
1364
+ total_ok_amt_sent_msat += path. final_value_msat ( ) ;
1363
1365
}
1364
1366
if res. is_err ( ) { has_err = true ; }
1365
1367
if let & Err ( APIError :: MonitorUpdateInProgress ) = res {
@@ -1368,23 +1370,28 @@ impl OutboundPayments {
1368
1370
has_err = true ;
1369
1371
has_ok = true ;
1370
1372
total_ok_fees_msat += path. fee_msat ( ) ;
1373
+ total_ok_amt_sent_msat += path. final_value_msat ( ) ;
1371
1374
} else if res. is_err ( ) {
1372
- pending_amt_unsent += path . final_value_msat ( ) ;
1375
+ has_unsent = true ;
1373
1376
}
1374
1377
}
1375
1378
if has_err && has_ok {
1376
1379
Err ( PaymentSendFailure :: PartialFailure {
1377
1380
results,
1378
1381
payment_id,
1379
- failed_paths_retry : if pending_amt_unsent != 0 {
1382
+ failed_paths_retry : if has_unsent {
1380
1383
if let Some ( route_params) = & route. route_params {
1381
1384
let mut route_params = route_params. clone ( ) ;
1382
1385
// We calculate the leftover fee budget we're allowed to spend by
1383
1386
// subtracting the used fee from the total fee budget.
1384
1387
route_params. max_total_routing_fee_msat = route_params
1385
1388
. max_total_routing_fee_msat . map ( |m| m. saturating_sub ( total_ok_fees_msat) ) ;
1386
- route_params. final_value_msat = pending_amt_unsent;
1387
1389
1390
+ // We calculate the remaining target amount by subtracting the succeded
1391
+ // path values.
1392
+ let final_value_msat = core:: cmp:: min ( route_params. final_value_msat , route. get_total_amount ( ) ) ;
1393
+ route_params. final_value_msat = final_value_msat
1394
+ . saturating_sub ( total_ok_amt_sent_msat) ;
1388
1395
Some ( route_params)
1389
1396
} else { None }
1390
1397
} else { None } ,
0 commit comments