@@ -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 ;
@@ -62,15 +62,15 @@ pub(crate) enum PendingOutboundPayment {
62
62
AwaitingOffer {
63
63
expiration : StaleExpiration ,
64
64
retry_strategy : Retry ,
65
- max_total_routing_fee_msat : Option < u64 > ,
65
+ route_params_config : RouteParametersConfig ,
66
66
/// Human Readable Names-originated payments should always specify an explicit amount to
67
67
/// send up-front, which we track here and enforce once we receive the offer.
68
68
amount_msats : u64 ,
69
69
} ,
70
70
AwaitingInvoice {
71
71
expiration : StaleExpiration ,
72
72
retry_strategy : Retry ,
73
- max_total_routing_fee_msat : Option < u64 > ,
73
+ route_params_config : RouteParametersConfig ,
74
74
retryable_invoice_request : Option < RetryableInvoiceRequest >
75
75
} ,
76
76
// This state will never be persisted to disk because we transition from `AwaitingInvoice` to
@@ -79,9 +79,10 @@ pub(crate) enum PendingOutboundPayment {
79
79
InvoiceReceived {
80
80
payment_hash : PaymentHash ,
81
81
retry_strategy : Retry ,
82
- // Note this field is currently just replicated from AwaitingInvoice but not actually
83
- // used anywhere.
84
- max_total_routing_fee_msat : Option < u64 > ,
82
+ // Currently unused, but replicated from `AwaitingInvoice` to avoid potential
83
+ // race conditions where this field might be missing upon reload. It may be required
84
+ // for future retries.
85
+ route_params_config : RouteParametersConfig ,
85
86
} ,
86
87
// This state applies when we are paying an often-offline recipient and another node on the
87
88
// network served us a static invoice on the recipient's behalf in response to our invoice
@@ -850,14 +851,14 @@ impl OutboundPayments {
850
851
match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
851
852
hash_map:: Entry :: Occupied ( entry) => match entry. get ( ) {
852
853
PendingOutboundPayment :: AwaitingInvoice {
853
- retry_strategy : retry, max_total_routing_fee_msat : max_total_fee , ..
854
+ retry_strategy : retry, route_params_config , ..
854
855
} => {
855
856
retry_strategy = * retry;
856
- max_total_routing_fee_msat = * max_total_fee ;
857
+ max_total_routing_fee_msat = route_params_config . max_total_routing_fee_msat ;
857
858
* entry. into_mut ( ) = PendingOutboundPayment :: InvoiceReceived {
858
859
payment_hash,
859
860
retry_strategy : * retry,
860
- max_total_routing_fee_msat ,
861
+ route_params_config : * route_params_config ,
861
862
} ;
862
863
} ,
863
864
_ => return Err ( Bolt12PaymentError :: DuplicateInvoice ) ,
@@ -1018,7 +1019,7 @@ impl OutboundPayments {
1018
1019
match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
1019
1020
hash_map:: Entry :: Occupied ( mut entry) => match entry. get_mut ( ) {
1020
1021
PendingOutboundPayment :: AwaitingInvoice {
1021
- retry_strategy, retryable_invoice_request, max_total_routing_fee_msat , ..
1022
+ retry_strategy, retryable_invoice_request, route_params_config , ..
1022
1023
} => {
1023
1024
let invreq = & retryable_invoice_request
1024
1025
. as_ref ( )
@@ -1050,7 +1051,7 @@ impl OutboundPayments {
1050
1051
let payment_hash = PaymentHash ( Sha256 :: hash ( & keysend_preimage. 0 ) . to_byte_array ( ) ) ;
1051
1052
let pay_params = PaymentParameters :: from_static_invoice ( invoice) ;
1052
1053
let mut route_params = RouteParameters :: from_payment_params_and_value ( pay_params, amount_msat) ;
1053
- route_params. max_total_routing_fee_msat = * max_total_routing_fee_msat;
1054
+ route_params. max_total_routing_fee_msat = route_params_config . max_total_routing_fee_msat ;
1054
1055
1055
1056
if let Err ( ( ) ) = onion_utils:: set_max_path_length (
1056
1057
& mut route_params, & RecipientOnionFields :: spontaneous_empty ( ) , Some ( keysend_preimage) ,
@@ -1696,13 +1697,17 @@ impl OutboundPayments {
1696
1697
max_total_routing_fee_msat : Option < u64 > , amount_msats : u64 ,
1697
1698
) -> Result < ( ) , ( ) > {
1698
1699
let mut pending_outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1700
+ let route_params_config = max_total_routing_fee_msat. map_or (
1701
+ RouteParametersConfig :: new ( ) ,
1702
+ |fee_msat| RouteParametersConfig :: new ( ) . with_max_total_routing_fee_msat ( fee_msat)
1703
+ ) ;
1699
1704
match pending_outbounds. entry ( payment_id) {
1700
1705
hash_map:: Entry :: Occupied ( _) => Err ( ( ) ) ,
1701
1706
hash_map:: Entry :: Vacant ( entry) => {
1702
1707
entry. insert ( PendingOutboundPayment :: AwaitingOffer {
1703
1708
expiration,
1704
1709
retry_strategy,
1705
- max_total_routing_fee_msat ,
1710
+ route_params_config ,
1706
1711
amount_msats,
1707
1712
} ) ;
1708
1713
@@ -1729,12 +1734,12 @@ impl OutboundPayments {
1729
1734
match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
1730
1735
hash_map:: Entry :: Occupied ( entry) => match entry. get ( ) {
1731
1736
PendingOutboundPayment :: AwaitingOffer {
1732
- expiration, retry_strategy, max_total_routing_fee_msat , ..
1737
+ expiration, retry_strategy, route_params_config , ..
1733
1738
} => {
1734
1739
let mut new_val = PendingOutboundPayment :: AwaitingInvoice {
1735
1740
expiration : * expiration,
1736
1741
retry_strategy : * retry_strategy,
1737
- max_total_routing_fee_msat : * max_total_routing_fee_msat ,
1742
+ route_params_config : * route_params_config ,
1738
1743
retryable_invoice_request,
1739
1744
} ;
1740
1745
core:: mem:: swap ( & mut new_val, entry. into_mut ( ) ) ;
@@ -1751,6 +1756,11 @@ impl OutboundPayments {
1751
1756
max_total_routing_fee_msat : Option < u64 > , retryable_invoice_request : Option < RetryableInvoiceRequest >
1752
1757
) -> Result < ( ) , ( ) > {
1753
1758
let mut pending_outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1759
+ let route_params_config = max_total_routing_fee_msat. map_or (
1760
+ RouteParametersConfig :: new ( ) ,
1761
+ |fee_msats| RouteParametersConfig :: new ( )
1762
+ . with_max_total_routing_fee_msat ( fee_msats)
1763
+ ) ;
1754
1764
match pending_outbounds. entry ( payment_id) {
1755
1765
hash_map:: Entry :: Occupied ( _) => Err ( ( ) ) ,
1756
1766
hash_map:: Entry :: Vacant ( entry) => {
@@ -1760,7 +1770,7 @@ impl OutboundPayments {
1760
1770
entry. insert ( PendingOutboundPayment :: AwaitingInvoice {
1761
1771
expiration,
1762
1772
retry_strategy,
1763
- max_total_routing_fee_msat ,
1773
+ route_params_config ,
1764
1774
retryable_invoice_request,
1765
1775
} ) ;
1766
1776
@@ -2390,13 +2400,15 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
2390
2400
( 5 , AwaitingInvoice ) => {
2391
2401
( 0 , expiration, required) ,
2392
2402
( 2 , retry_strategy, required) ,
2393
- ( 4 , max_total_routing_fee_msat , option ) ,
2403
+ // TODO: Add support for legacy `max_total_routing_fee_msat`
2394
2404
( 5 , retryable_invoice_request, option) ,
2405
+ ( 7 , route_params_config, ( default_value, RouteParametersConfig :: new( ) ) ) ,
2395
2406
} ,
2396
2407
( 7 , InvoiceReceived ) => {
2397
2408
( 0 , payment_hash, required) ,
2398
2409
( 2 , retry_strategy, required) ,
2399
- ( 4 , max_total_routing_fee_msat, option) ,
2410
+ ( 3 , route_params_config, ( default_value, RouteParametersConfig :: new( ) ) ) ,
2411
+ // TODO: Add support for legacy `max_total_routing_fee_msat`
2400
2412
} ,
2401
2413
// Added in 0.1. Prior versions will drop these outbounds on downgrade, which is safe because no
2402
2414
// HTLCs are in-flight.
@@ -2412,7 +2424,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
2412
2424
( 11 , AwaitingOffer ) => {
2413
2425
( 0 , expiration, required) ,
2414
2426
( 2 , retry_strategy, required) ,
2415
- ( 4 , max_total_routing_fee_msat , option ) ,
2427
+ ( 5 , route_params_config , ( default_value , RouteParametersConfig :: new ( ) ) ) ,
2416
2428
( 6 , amount_msats, required) ,
2417
2429
} ,
2418
2430
) ;
0 commit comments