@@ -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 ;
@@ -70,7 +70,11 @@ pub(crate) enum PendingOutboundPayment {
70
70
AwaitingInvoice {
71
71
expiration : StaleExpiration ,
72
72
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`.
73
76
max_total_routing_fee_msat : Option < u64 > ,
77
+ route_params_config : RouteParametersConfig ,
74
78
retryable_invoice_request : Option < RetryableInvoiceRequest >
75
79
} ,
76
80
// This state will never be persisted to disk because we transition from `AwaitingInvoice` to
@@ -79,9 +83,12 @@ pub(crate) enum PendingOutboundPayment {
79
83
InvoiceReceived {
80
84
payment_hash : PaymentHash ,
81
85
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.
84
87
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 ,
85
92
} ,
86
93
// This state applies when we are paying an often-offline recipient and another node on the
87
94
// network served us a static invoice on the recipient's behalf in response to our invoice
@@ -850,14 +857,21 @@ impl OutboundPayments {
850
857
match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
851
858
hash_map:: Entry :: Occupied ( entry) => match entry. get ( ) {
852
859
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 , ..
854
861
} => {
855
862
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 ;
857
870
* entry. into_mut ( ) = PendingOutboundPayment :: InvoiceReceived {
858
871
payment_hash,
859
872
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,
861
875
} ;
862
876
} ,
863
877
_ => return Err ( Bolt12PaymentError :: DuplicateInvoice ) ,
@@ -1751,6 +1765,11 @@ impl OutboundPayments {
1751
1765
max_total_routing_fee_msat : Option < u64 > , retryable_invoice_request : Option < RetryableInvoiceRequest >
1752
1766
) -> Result < ( ) , ( ) > {
1753
1767
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
+ ) ;
1754
1773
match pending_outbounds. entry ( payment_id) {
1755
1774
hash_map:: Entry :: Occupied ( _) => Err ( ( ) ) ,
1756
1775
hash_map:: Entry :: Vacant ( entry) => {
@@ -1760,7 +1779,9 @@ impl OutboundPayments {
1760
1779
entry. insert ( PendingOutboundPayment :: AwaitingInvoice {
1761
1780
expiration,
1762
1781
retry_strategy,
1763
- max_total_routing_fee_msat,
1782
+ route_params_config,
1783
+ // Retained for downgrade support.
1784
+ max_total_routing_fee_msat : None ,
1764
1785
retryable_invoice_request,
1765
1786
} ) ;
1766
1787
@@ -2392,10 +2413,12 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
2392
2413
( 2 , retry_strategy, required) ,
2393
2414
( 4 , max_total_routing_fee_msat, option) ,
2394
2415
( 5 , retryable_invoice_request, option) ,
2416
+ ( 7 , route_params_config, ( default_value, RouteParametersConfig :: new( ) ) ) ,
2395
2417
} ,
2396
2418
( 7 , InvoiceReceived ) => {
2397
2419
( 0 , payment_hash, required) ,
2398
2420
( 2 , retry_strategy, required) ,
2421
+ ( 3 , route_params_config, ( default_value, RouteParametersConfig :: new( ) ) ) ,
2399
2422
( 4 , max_total_routing_fee_msat, option) ,
2400
2423
} ,
2401
2424
// Added in 0.1. Prior versions will drop these outbounds on downgrade, which is safe because no
0 commit comments