@@ -1354,12 +1354,14 @@ impl OutboundPayments {
13541354 }
13551355 let mut has_ok = false ;
13561356 let mut has_err = false ;
1357- let mut pending_amt_unsent = 0 ;
1357+ let mut has_unsent = false ;
13581358 let mut total_ok_fees_msat = 0 ;
1359+ let mut total_ok_amt_sent_msat = 0 ;
13591360 for ( res, path) in results. iter ( ) . zip ( route. paths . iter ( ) ) {
13601361 if res. is_ok ( ) {
13611362 has_ok = true ;
13621363 total_ok_fees_msat += path. fee_msat ( ) ;
1364+ total_ok_amt_sent_msat += path. final_value_msat ( ) ;
13631365 }
13641366 if res. is_err ( ) { has_err = true ; }
13651367 if let & Err ( APIError :: MonitorUpdateInProgress ) = res {
@@ -1368,23 +1370,28 @@ impl OutboundPayments {
13681370 has_err = true ;
13691371 has_ok = true ;
13701372 total_ok_fees_msat += path. fee_msat ( ) ;
1373+ total_ok_amt_sent_msat += path. final_value_msat ( ) ;
13711374 } else if res. is_err ( ) {
1372- pending_amt_unsent += path . final_value_msat ( ) ;
1375+ has_unsent = true ;
13731376 }
13741377 }
13751378 if has_err && has_ok {
13761379 Err ( PaymentSendFailure :: PartialFailure {
13771380 results,
13781381 payment_id,
1379- failed_paths_retry : if pending_amt_unsent != 0 {
1382+ failed_paths_retry : if has_unsent {
13801383 if let Some ( route_params) = & route. route_params {
13811384 let mut route_params = route_params. clone ( ) ;
13821385 // We calculate the leftover fee budget we're allowed to spend by
13831386 // subtracting the used fee from the total fee budget.
13841387 route_params. max_total_routing_fee_msat = route_params
13851388 . max_total_routing_fee_msat . map ( |m| m. saturating_sub ( total_ok_fees_msat) ) ;
1386- route_params. final_value_msat = pending_amt_unsent;
13871389
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) ;
13881395 Some ( route_params)
13891396 } else { None }
13901397 } else { None } ,
0 commit comments