@@ -24,7 +24,7 @@ use crate::ln::onion_utils::{DecodedOnionFailure, HTLCFailReason};
2424use crate :: offers:: invoice:: Bolt12Invoice ;
2525use crate :: offers:: invoice_request:: InvoiceRequest ;
2626use crate :: offers:: nonce:: Nonce ;
27- use crate :: routing:: router:: { BlindedTail , InFlightHtlcs , Path , PaymentParameters , Route , RouteParameters , Router } ;
27+ use crate :: routing:: router:: { BlindedTail , InFlightHtlcs , RouteParametersConfig , Path , PaymentParameters , Route , RouteParameters , Router } ;
2828use crate :: sign:: { EntropySource , NodeSigner , Recipient } ;
2929use crate :: util:: errors:: APIError ;
3030use crate :: util:: logger:: Logger ;
@@ -70,7 +70,11 @@ pub(crate) enum PendingOutboundPayment {
7070 AwaitingInvoice {
7171 expiration : StaleExpiration ,
7272 retry_strategy : Retry ,
73+ // Deprecated: Retained for backward compatibility.
74+ // If set during read, this field overrides `RouteParameters::max_total_routing_fee_msat`
75+ // instead of `RouteParametersConfig::max_total_routing_fee_msat`.
7376 max_total_routing_fee_msat : Option < u64 > ,
77+ route_params_config : RouteParametersConfig ,
7478 retryable_invoice_request : Option < RetryableInvoiceRequest >
7579 } ,
7680 // This state will never be persisted to disk because we transition from `AwaitingInvoice` to
@@ -79,9 +83,12 @@ pub(crate) enum PendingOutboundPayment {
7983 InvoiceReceived {
8084 payment_hash : PaymentHash ,
8185 retry_strategy : Retry ,
82- // Note this field is currently just replicated from AwaitingInvoice but not actually
83- // used anywhere.
86+ // Deprecated: Retained for backward compatibility.
8487 max_total_routing_fee_msat : Option < u64 > ,
88+ // Currently unused, but replicated from `AwaitingInvoice` to avoid potential
89+ // race conditions where this field might be missing upon reload. It may be required
90+ // for future retries.
91+ route_params_config : RouteParametersConfig ,
8592 } ,
8693 // This state applies when we are paying an often-offline recipient and another node on the
8794 // network served us a static invoice on the recipient's behalf in response to our invoice
@@ -850,14 +857,21 @@ impl OutboundPayments {
850857 match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
851858 hash_map:: Entry :: Occupied ( entry) => match entry. get ( ) {
852859 PendingOutboundPayment :: AwaitingInvoice {
853- retry_strategy : retry, max_total_routing_fee_msat : max_total_fee, ..
860+ retry_strategy : retry, max_total_routing_fee_msat : max_total_fee, route_params_config , ..
854861 } => {
855862 retry_strategy = * retry;
856- max_total_routing_fee_msat = * max_total_fee;
863+ // If max_total_fee is present, update route_params_config with the specified fee.
864+ // This supports the standard behavior during downgrades.
865+ let route_params_config = max_total_fee. map_or (
866+ * route_params_config,
867+ |fee_msat| route_params_config. with_max_total_routing_fee_msat ( fee_msat)
868+ ) ;
869+ max_total_routing_fee_msat = route_params_config. max_total_routing_fee_msat ;
857870 * entry. into_mut ( ) = PendingOutboundPayment :: InvoiceReceived {
858871 payment_hash,
859872 retry_strategy : * retry,
860- max_total_routing_fee_msat,
873+ max_total_routing_fee_msat : * max_total_fee,
874+ route_params_config : route_params_config,
861875 } ;
862876 } ,
863877 _ => return Err ( Bolt12PaymentError :: DuplicateInvoice ) ,
@@ -1751,6 +1765,11 @@ impl OutboundPayments {
17511765 max_total_routing_fee_msat : Option < u64 > , retryable_invoice_request : Option < RetryableInvoiceRequest >
17521766 ) -> Result < ( ) , ( ) > {
17531767 let mut pending_outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1768+ let route_params_config = max_total_routing_fee_msat. map_or (
1769+ RouteParametersConfig :: new ( ) ,
1770+ |fee_msats| RouteParametersConfig :: new ( )
1771+ . with_max_total_routing_fee_msat ( fee_msats)
1772+ ) ;
17541773 match pending_outbounds. entry ( payment_id) {
17551774 hash_map:: Entry :: Occupied ( _) => Err ( ( ) ) ,
17561775 hash_map:: Entry :: Vacant ( entry) => {
@@ -1760,7 +1779,9 @@ impl OutboundPayments {
17601779 entry. insert ( PendingOutboundPayment :: AwaitingInvoice {
17611780 expiration,
17621781 retry_strategy,
1763- max_total_routing_fee_msat,
1782+ route_params_config,
1783+ // Retained for downgrade support.
1784+ max_total_routing_fee_msat : None ,
17641785 retryable_invoice_request,
17651786 } ) ;
17661787
@@ -2392,10 +2413,12 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
23922413 ( 2 , retry_strategy, required) ,
23932414 ( 4 , max_total_routing_fee_msat, option) ,
23942415 ( 5 , retryable_invoice_request, option) ,
2416+ ( 7 , route_params_config, ( default_value, RouteParametersConfig :: new( ) ) ) ,
23952417 } ,
23962418 ( 7 , InvoiceReceived ) => {
23972419 ( 0 , payment_hash, required) ,
23982420 ( 2 , retry_strategy, required) ,
2421+ ( 3 , route_params_config, ( default_value, RouteParametersConfig :: new( ) ) ) ,
23992422 ( 4 , max_total_routing_fee_msat, option) ,
24002423 } ,
24012424 // Added in 0.1. Prior versions will drop these outbounds on downgrade, which is safe because no
0 commit comments