@@ -24,7 +24,7 @@ use crate::ln::onion_utils::{DecodedOnionFailure, HTLCFailReason};
24
24
use crate :: offers:: invoice:: Bolt12Invoice ;
25
25
use crate :: offers:: invoice_request:: InvoiceRequest ;
26
26
use 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 } ;
28
28
use crate :: sign:: { EntropySource , NodeSigner , Recipient } ;
29
29
use crate :: util:: errors:: APIError ;
30
30
use crate :: util:: logger:: Logger ;
@@ -61,7 +61,11 @@ pub(crate) enum PendingOutboundPayment {
61
61
AwaitingInvoice {
62
62
expiration : StaleExpiration ,
63
63
retry_strategy : Retry ,
64
+ // Deprecated: Retained for backward compatibility.
65
+ // If set during read, this field overrides `RouteParameters::max_total_routing_fee_msat`
66
+ // instead of `RouteParametersConfig::max_total_routing_fee_msat`.
64
67
max_total_routing_fee_msat : Option < u64 > ,
68
+ route_params_config : RouteParametersConfig ,
65
69
retryable_invoice_request : Option < RetryableInvoiceRequest >
66
70
} ,
67
71
// This state will never be persisted to disk because we transition from `AwaitingInvoice` to
@@ -70,9 +74,12 @@ pub(crate) enum PendingOutboundPayment {
70
74
InvoiceReceived {
71
75
payment_hash : PaymentHash ,
72
76
retry_strategy : Retry ,
73
- // Note this field is currently just replicated from AwaitingInvoice but not actually
74
- // used anywhere.
77
+ // Deprecated: Retained for backward compatibility.
75
78
max_total_routing_fee_msat : Option < u64 > ,
79
+ // Currently unused, but replicated from `AwaitingInvoice` to avoid potential
80
+ // race conditions where this field might be missing upon reload. It may be required
81
+ // for future retries.
82
+ route_params_config : RouteParametersConfig ,
76
83
} ,
77
84
// This state applies when we are paying an often-offline recipient and another node on the
78
85
// network served us a static invoice on the recipient's behalf in response to our invoice
@@ -849,14 +856,21 @@ impl OutboundPayments {
849
856
match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
850
857
hash_map:: Entry :: Occupied ( entry) => match entry. get ( ) {
851
858
PendingOutboundPayment :: AwaitingInvoice {
852
- retry_strategy : retry, max_total_routing_fee_msat : max_total_fee, ..
859
+ retry_strategy : retry, max_total_routing_fee_msat : max_total_fee, route_params_config , ..
853
860
} => {
854
861
retry_strategy = * retry;
855
- max_total_routing_fee_msat = * max_total_fee;
862
+ // If max_total_fee is present, update route_params_config with the specified fee.
863
+ // This supports the standard behavior during downgrades.
864
+ let route_params_config = max_total_fee. map_or (
865
+ * route_params_config,
866
+ |fee_msat| route_params_config. with_max_total_routing_fee_msat ( fee_msat)
867
+ ) ;
868
+ max_total_routing_fee_msat = route_params_config. max_total_routing_fee_msat ;
856
869
* entry. into_mut ( ) = PendingOutboundPayment :: InvoiceReceived {
857
870
payment_hash,
858
871
retry_strategy : * retry,
859
- max_total_routing_fee_msat,
872
+ max_total_routing_fee_msat : * max_total_fee,
873
+ route_params_config : route_params_config,
860
874
} ;
861
875
} ,
862
876
_ => return Err ( Bolt12PaymentError :: DuplicateInvoice ) ,
@@ -1599,6 +1613,11 @@ impl OutboundPayments {
1599
1613
max_total_routing_fee_msat : Option < u64 > , retryable_invoice_request : Option < RetryableInvoiceRequest >
1600
1614
) -> Result < ( ) , ( ) > {
1601
1615
let mut pending_outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1616
+ let route_params_config = max_total_routing_fee_msat. map_or (
1617
+ RouteParametersConfig :: new ( ) ,
1618
+ |fee_msats| RouteParametersConfig :: new ( )
1619
+ . with_max_total_routing_fee_msat ( fee_msats)
1620
+ ) ;
1602
1621
match pending_outbounds. entry ( payment_id) {
1603
1622
hash_map:: Entry :: Occupied ( _) => Err ( ( ) ) ,
1604
1623
hash_map:: Entry :: Vacant ( entry) => {
@@ -1608,7 +1627,9 @@ impl OutboundPayments {
1608
1627
entry. insert ( PendingOutboundPayment :: AwaitingInvoice {
1609
1628
expiration,
1610
1629
retry_strategy,
1611
- max_total_routing_fee_msat,
1630
+ route_params_config,
1631
+ // Retained for downgrade support.
1632
+ max_total_routing_fee_msat : None ,
1612
1633
retryable_invoice_request,
1613
1634
} ) ;
1614
1635
@@ -2240,10 +2261,12 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
2240
2261
( 2 , retry_strategy, required) ,
2241
2262
( 4 , max_total_routing_fee_msat, option) ,
2242
2263
( 5 , retryable_invoice_request, option) ,
2264
+ ( 7 , route_params_config, ( default_value, RouteParametersConfig :: new( ) ) ) ,
2243
2265
} ,
2244
2266
( 7 , InvoiceReceived ) => {
2245
2267
( 0 , payment_hash, required) ,
2246
2268
( 2 , retry_strategy, required) ,
2269
+ ( 3 , route_params_config, ( default_value, RouteParametersConfig :: new( ) ) ) ,
2247
2270
( 4 , max_total_routing_fee_msat, option) ,
2248
2271
} ,
2249
2272
// Added in 0.0.125. Prior versions will drop these outbounds on downgrade, which is safe because
0 commit comments