@@ -851,7 +851,7 @@ impl OutboundPayments {
851851 SP : Fn ( SendAlongPathArgs ) -> Result < ( ) , APIError > ,
852852 {
853853 let payment_hash = invoice. payment_hash ( ) ;
854- let max_total_routing_fee_msat ;
854+ let params_config ;
855855 let retry_strategy;
856856 match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
857857 hash_map:: Entry :: Occupied ( entry) => match entry. get ( ) {
@@ -863,14 +863,14 @@ impl OutboundPayments {
863863 // This supports the standard behavior during downgrades.
864864 let route_params_config = max_total_fee. map_or (
865865 * route_params_config,
866- |fee_msat| route_params_config. with_max_total_routing_fee_msat ( fee_msat)
866+ |fee_msat| route_params_config. with_max_total_routing_fee_msat ( fee_msat) ,
867867 ) ;
868- max_total_routing_fee_msat = route_params_config. max_total_routing_fee_msat ;
868+ params_config = route_params_config;
869869 * entry. into_mut ( ) = PendingOutboundPayment :: InvoiceReceived {
870870 payment_hash,
871871 retry_strategy : * retry,
872872 max_total_routing_fee_msat : * max_total_fee,
873- route_params_config : route_params_config ,
873+ route_params_config,
874874 } ;
875875 } ,
876876 _ => return Err ( Bolt12PaymentError :: DuplicateInvoice ) ,
@@ -886,11 +886,13 @@ impl OutboundPayments {
886886 }
887887
888888 let mut route_params = RouteParameters :: from_payment_params_and_value (
889- PaymentParameters :: from_bolt12_invoice ( & invoice) , invoice. amount_msats ( )
889+ PaymentParameters :: from_bolt12_invoice ( & invoice) . with_user_config ( params_config ) , invoice. amount_msats ( )
890890 ) ;
891- if let Some ( max_fee_msat) = max_total_routing_fee_msat {
892- route_params. max_total_routing_fee_msat = Some ( max_fee_msat) ;
891+
892+ if let Some ( fee_msat) = params_config. max_total_routing_fee_msat {
893+ route_params. max_total_routing_fee_msat = Some ( fee_msat) ;
893894 }
895+
894896 self . send_payment_for_bolt12_invoice_internal (
895897 payment_id, payment_hash, None , route_params, retry_strategy, router, first_hops,
896898 inflight_htlcs, entropy_source, node_signer, node_id_lookup, secp_ctx, best_block_height,
@@ -1018,7 +1020,7 @@ impl OutboundPayments {
10181020 match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
10191021 hash_map:: Entry :: Occupied ( mut entry) => match entry. get ( ) {
10201022 PendingOutboundPayment :: AwaitingInvoice {
1021- retry_strategy, retryable_invoice_request, max_total_routing_fee_msat, ..
1023+ retry_strategy, retryable_invoice_request, max_total_routing_fee_msat, route_params_config , ..
10221024 } => {
10231025 let invreq = & retryable_invoice_request
10241026 . as_ref ( )
@@ -1041,11 +1043,22 @@ impl OutboundPayments {
10411043 return Err ( Bolt12PaymentError :: UnknownRequiredFeatures )
10421044 }
10431045 } ;
1046+
1047+ // If max_total_fee is present, update route_params_config with the specified fee.
1048+ // This supports the standard behavior during downgrades.
1049+ let params_config = max_total_routing_fee_msat. map_or (
1050+ * route_params_config,
1051+ |fee_msat| route_params_config. with_max_total_routing_fee_msat ( fee_msat) ,
1052+ ) ;
1053+
10441054 let keysend_preimage = PaymentPreimage ( entropy_source. get_secure_random_bytes ( ) ) ;
10451055 let payment_hash = PaymentHash ( Sha256 :: hash ( & keysend_preimage. 0 ) . to_byte_array ( ) ) ;
1046- let pay_params = PaymentParameters :: from_static_invoice ( invoice) ;
1056+ let pay_params = PaymentParameters :: from_static_invoice ( invoice) . with_user_config ( params_config ) ;
10471057 let mut route_params = RouteParameters :: from_payment_params_and_value ( pay_params, amount_msat) ;
1048- route_params. max_total_routing_fee_msat = * max_total_routing_fee_msat;
1058+
1059+ if let Some ( fee_msat) = params_config. max_total_routing_fee_msat {
1060+ route_params. max_total_routing_fee_msat = Some ( fee_msat) ;
1061+ }
10491062
10501063 if let Err ( ( ) ) = onion_utils:: set_max_path_length (
10511064 & mut route_params, & RecipientOnionFields :: spontaneous_empty ( ) , Some ( keysend_preimage) ,
0 commit comments