@@ -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 , RouteParametersOverride , 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 `RouteParametersOverride::max_total_routing_fee_msat`.
64
67
max_total_routing_fee_msat : Option < u64 > ,
68
+ route_params_override : Option < RouteParametersOverride > ,
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,10 @@ 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.
75
- max_total_routing_fee_msat : Option < u64 > ,
77
+ // Currently unused, but replicated from `AwaitingInvoice` to avoid potential
78
+ // race conditions where this field might be missing upon reload. It may be required
79
+ // for future retries.
80
+ route_params_override : Option < RouteParametersOverride > ,
76
81
} ,
77
82
// This state applies when we are paying an often-offline recipient and another node on the
78
83
// network served us a static invoice on the recipient's behalf in response to our invoice
@@ -849,14 +854,23 @@ impl OutboundPayments {
849
854
match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
850
855
hash_map:: Entry :: Occupied ( entry) => match entry. get ( ) {
851
856
PendingOutboundPayment :: AwaitingInvoice {
852
- retry_strategy : retry, max_total_routing_fee_msat : max_total_fee, ..
857
+ retry_strategy : retry, max_total_routing_fee_msat : max_total_fee, route_params_override , ..
853
858
} => {
854
859
retry_strategy = * retry;
855
- max_total_routing_fee_msat = * max_total_fee;
860
+ // If max_total_fee is present, update route_params_override with the specified fee.
861
+ // This supports the standard behavior during downgrades.
862
+ let route_params_override = max_total_fee. map_or ( * route_params_override, |fee_msat| {
863
+ route_params_override. map ( |params_override|
864
+ params_override. with_max_total_routing_fee_msat ( fee_msat)
865
+ ) . or_else ( || Some ( RouteParametersOverride :: new ( ) . with_max_total_routing_fee_msat ( fee_msat) ) )
866
+ } ) ;
867
+ max_total_routing_fee_msat = route_params_override. and_then (
868
+ |params| params. max_total_routing_fee_msat
869
+ ) ;
856
870
* entry. into_mut ( ) = PendingOutboundPayment :: InvoiceReceived {
857
871
payment_hash,
858
872
retry_strategy : * retry,
859
- max_total_routing_fee_msat ,
873
+ route_params_override : route_params_override ,
860
874
} ;
861
875
} ,
862
876
_ => return Err ( Bolt12PaymentError :: DuplicateInvoice ) ,
@@ -1004,7 +1018,7 @@ impl OutboundPayments {
1004
1018
match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
1005
1019
hash_map:: Entry :: Occupied ( mut entry) => match entry. get ( ) {
1006
1020
PendingOutboundPayment :: AwaitingInvoice {
1007
- retry_strategy, retryable_invoice_request, max_total_routing_fee_msat , ..
1021
+ retry_strategy, retryable_invoice_request, route_params_override , ..
1008
1022
} => {
1009
1023
let invreq = & retryable_invoice_request
1010
1024
. as_ref ( )
@@ -1031,7 +1045,7 @@ impl OutboundPayments {
1031
1045
let payment_hash = PaymentHash ( Sha256 :: hash ( & keysend_preimage. 0 ) . to_byte_array ( ) ) ;
1032
1046
let pay_params = PaymentParameters :: from_static_invoice ( invoice) ;
1033
1047
let mut route_params = RouteParameters :: from_payment_params_and_value ( pay_params, amount_msat) ;
1034
- route_params. max_total_routing_fee_msat = * max_total_routing_fee_msat;
1048
+ route_params. max_total_routing_fee_msat = route_params_override . map ( |params| params . max_total_routing_fee_msat ) . flatten ( ) ;
1035
1049
1036
1050
if let Err ( ( ) ) = onion_utils:: set_max_path_length (
1037
1051
& mut route_params, & RecipientOnionFields :: spontaneous_empty ( ) , Some ( keysend_preimage) ,
@@ -1599,6 +1613,10 @@ 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_override = max_total_routing_fee_msat. map (
1617
+ |fee_msats| RouteParametersOverride :: new ( )
1618
+ . with_max_total_routing_fee_msat ( fee_msats)
1619
+ ) ;
1602
1620
match pending_outbounds. entry ( payment_id) {
1603
1621
hash_map:: Entry :: Occupied ( _) => Err ( ( ) ) ,
1604
1622
hash_map:: Entry :: Vacant ( entry) => {
@@ -1608,7 +1626,9 @@ impl OutboundPayments {
1608
1626
entry. insert ( PendingOutboundPayment :: AwaitingInvoice {
1609
1627
expiration,
1610
1628
retry_strategy,
1611
- max_total_routing_fee_msat,
1629
+ route_params_override,
1630
+ // Retained for downgrade support.
1631
+ max_total_routing_fee_msat : None ,
1612
1632
retryable_invoice_request,
1613
1633
} ) ;
1614
1634
@@ -2240,11 +2260,12 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
2240
2260
( 2 , retry_strategy, required) ,
2241
2261
( 4 , max_total_routing_fee_msat, option) ,
2242
2262
( 5 , retryable_invoice_request, option) ,
2263
+ ( 7 , route_params_override, option) ,
2243
2264
} ,
2244
2265
( 7 , InvoiceReceived ) => {
2245
2266
( 0 , payment_hash, required) ,
2246
2267
( 2 , retry_strategy, required) ,
2247
- ( 4 , max_total_routing_fee_msat , option) ,
2268
+ ( 3 , route_params_override , option) ,
2248
2269
} ,
2249
2270
// Added in 0.0.125. Prior versions will drop these outbounds on downgrade, which is safe because
2250
2271
// no HTLCs are in-flight.
0 commit comments