@@ -851,7 +851,7 @@ impl OutboundPayments {
851
851
SP : Fn ( SendAlongPathArgs ) -> Result < ( ) , APIError > ,
852
852
{
853
853
let payment_hash = invoice. payment_hash ( ) ;
854
- let max_total_routing_fee_msat ;
854
+ let params_config ;
855
855
let retry_strategy;
856
856
match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
857
857
hash_map:: Entry :: Occupied ( entry) => match entry. get ( ) {
@@ -863,14 +863,14 @@ impl OutboundPayments {
863
863
// This supports the standard behavior during downgrades.
864
864
let route_params_config = max_total_fee. map_or (
865
865
* 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) ,
867
867
) ;
868
- max_total_routing_fee_msat = route_params_config. max_total_routing_fee_msat ;
868
+ params_config = route_params_config;
869
869
* entry. into_mut ( ) = PendingOutboundPayment :: InvoiceReceived {
870
870
payment_hash,
871
871
retry_strategy : * retry,
872
872
max_total_routing_fee_msat : * max_total_fee,
873
- route_params_config : route_params_config ,
873
+ route_params_config,
874
874
} ;
875
875
} ,
876
876
_ => return Err ( Bolt12PaymentError :: DuplicateInvoice ) ,
@@ -886,11 +886,13 @@ impl OutboundPayments {
886
886
}
887
887
888
888
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 ( )
890
890
) ;
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) ;
893
894
}
895
+
894
896
self . send_payment_for_bolt12_invoice_internal (
895
897
payment_id, payment_hash, None , route_params, retry_strategy, router, first_hops,
896
898
inflight_htlcs, entropy_source, node_signer, node_id_lookup, secp_ctx, best_block_height,
@@ -1018,7 +1020,7 @@ impl OutboundPayments {
1018
1020
match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
1019
1021
hash_map:: Entry :: Occupied ( mut entry) => match entry. get ( ) {
1020
1022
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 , ..
1022
1024
} => {
1023
1025
let invreq = & retryable_invoice_request
1024
1026
. as_ref ( )
@@ -1041,11 +1043,22 @@ impl OutboundPayments {
1041
1043
return Err ( Bolt12PaymentError :: UnknownRequiredFeatures )
1042
1044
}
1043
1045
} ;
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
+
1044
1054
let keysend_preimage = PaymentPreimage ( entropy_source. get_secure_random_bytes ( ) ) ;
1045
1055
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 ) ;
1047
1057
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
+ }
1049
1062
1050
1063
if let Err ( ( ) ) = onion_utils:: set_max_path_length (
1051
1064
& mut route_params, & RecipientOnionFields :: spontaneous_empty ( ) , Some ( keysend_preimage) ,
0 commit comments