File tree 1 file changed +13
-2
lines changed
1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -1057,14 +1057,19 @@ impl OutboundPayments {
1057
1057
let mut has_ok = false ;
1058
1058
let mut has_err = false ;
1059
1059
let mut pending_amt_unsent = 0 ;
1060
+ let mut total_ok_fees_msat = 0 ;
1060
1061
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
+ }
1062
1066
if res. is_err ( ) { has_err = true ; }
1063
1067
if let & Err ( APIError :: MonitorUpdateInProgress ) = res {
1064
1068
// MonitorUpdateInProgress is inherently unsafe to retry, so we call it a
1065
1069
// PartialFailure.
1066
1070
has_err = true ;
1067
1071
has_ok = true ;
1072
+ total_ok_fees_msat += path. fee_msat ( ) ;
1068
1073
} else if res. is_err ( ) {
1069
1074
pending_amt_unsent += path. final_value_msat ( ) ;
1070
1075
}
@@ -1075,8 +1080,14 @@ impl OutboundPayments {
1075
1080
payment_id,
1076
1081
failed_paths_retry : if pending_amt_unsent != 0 {
1077
1082
if let Some ( payment_params) = & route. payment_params {
1083
+ let mut payment_params = payment_params. clone ( ) ;
1084
+ // We calculate the leftover fee budget we're allowed to spend by
1085
+ // subtracting the used fee from the total fee budget.
1086
+ payment_params. max_total_routing_fee_msat = payment_params
1087
+ . max_total_routing_fee_msat . map ( |m| m. saturating_sub ( total_ok_fees_msat) ) ;
1088
+
1078
1089
Some ( RouteParameters {
1079
- payment_params : payment_params . clone ( ) ,
1090
+ payment_params,
1080
1091
final_value_msat : pending_amt_unsent,
1081
1092
} )
1082
1093
} else { None }
You can’t perform that action at this time.
0 commit comments