@@ -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 ; 
@@ -62,15 +62,15 @@ pub(crate) enum PendingOutboundPayment {
6262AwaitingOffer  { 
6363		expiration :  StaleExpiration , 
6464		retry_strategy :  Retry , 
65- 		max_total_routing_fee_msat :   Option < u64 > , 
65+ 		route_params_config :   RouteParametersConfig , 
6666		/// Human Readable Names-originated payments should always specify an explicit amount to 
6767/// send up-front, which we track here and enforce once we receive the offer. 
6868amount_msats :  u64 , 
6969	} , 
7070	AwaitingInvoice  { 
7171		expiration :  StaleExpiration , 
7272		retry_strategy :  Retry , 
73- 		max_total_routing_fee_msat :   Option < u64 > , 
73+ 		route_params_config :   RouteParametersConfig , 
7474		retryable_invoice_request :  Option < RetryableInvoiceRequest > 
7575	} , 
7676	// This state will never be persisted to disk because we transition from `AwaitingInvoice` to 
@@ -79,9 +79,10 @@ pub(crate) enum PendingOutboundPayment {
7979	InvoiceReceived  { 
8080		payment_hash :  PaymentHash , 
8181		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 , 
8586	} , 
8687	// This state applies when we are paying an often-offline recipient and another node on the 
8788	// network served us a static invoice on the recipient's behalf in response to our invoice 
@@ -850,14 +851,14 @@ impl OutboundPayments {
850851		match  self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id)  { 
851852			hash_map:: Entry :: Occupied ( entry)  => match  entry. get ( )  { 
852853				PendingOutboundPayment :: AwaitingInvoice  { 
853- 					retry_strategy :  retry,  max_total_routing_fee_msat :  max_total_fee ,  ..
854+ 					retry_strategy :  retry,  route_params_config ,  ..
854855				}  => { 
855856					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 ; 
857858					* entry. into_mut ( )  = PendingOutboundPayment :: InvoiceReceived  { 
858859						payment_hash, 
859860						retry_strategy :  * retry, 
860- 						max_total_routing_fee_msat , 
861+ 						route_params_config :   * route_params_config , 
861862					} ; 
862863				} , 
863864				_ => return  Err ( Bolt12PaymentError :: DuplicateInvoice ) , 
@@ -1018,7 +1019,7 @@ impl OutboundPayments {
10181019		match  self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id)  { 
10191020			hash_map:: Entry :: Occupied ( mut  entry)  => match  entry. get_mut ( )  { 
10201021				PendingOutboundPayment :: AwaitingInvoice  { 
1021- 					retry_strategy,  retryable_invoice_request,  max_total_routing_fee_msat ,  ..
1022+ 					retry_strategy,  retryable_invoice_request,  route_params_config ,  ..
10221023				}  => { 
10231024					let  invreq = & retryable_invoice_request
10241025						. as_ref ( ) 
@@ -1050,7 +1051,7 @@ impl OutboundPayments {
10501051					let  payment_hash = PaymentHash ( Sha256 :: hash ( & keysend_preimage. 0 ) . to_byte_array ( ) ) ; 
10511052					let  pay_params = PaymentParameters :: from_static_invoice ( invoice) ; 
10521053					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 ; 
10541055
10551056					if  let  Err ( ( ) )  = onion_utils:: set_max_path_length ( 
10561057						& mut  route_params,  & RecipientOnionFields :: spontaneous_empty ( ) ,  Some ( keysend_preimage) , 
@@ -1696,13 +1697,17 @@ impl OutboundPayments {
16961697		max_total_routing_fee_msat :  Option < u64 > ,  amount_msats :  u64 , 
16971698	)  -> Result < ( ) ,  ( ) >  { 
16981699		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+ 		) ; 
16991704		match  pending_outbounds. entry ( payment_id)  { 
17001705			hash_map:: Entry :: Occupied ( _)  => Err ( ( ) ) , 
17011706			hash_map:: Entry :: Vacant ( entry)  => { 
17021707				entry. insert ( PendingOutboundPayment :: AwaitingOffer  { 
17031708					expiration, 
17041709					retry_strategy, 
1705- 					max_total_routing_fee_msat , 
1710+ 					route_params_config , 
17061711					amount_msats, 
17071712				} ) ; 
17081713
@@ -1729,12 +1734,12 @@ impl OutboundPayments {
17291734		match  self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id)  { 
17301735			hash_map:: Entry :: Occupied ( entry)  => match  entry. get ( )  { 
17311736				PendingOutboundPayment :: AwaitingOffer  { 
1732- 					expiration,  retry_strategy,  max_total_routing_fee_msat ,  ..
1737+ 					expiration,  retry_strategy,  route_params_config ,  ..
17331738				}  => { 
17341739					let  mut  new_val = PendingOutboundPayment :: AwaitingInvoice  { 
17351740						expiration :  * expiration, 
17361741						retry_strategy :  * retry_strategy, 
1737- 						max_total_routing_fee_msat :  * max_total_routing_fee_msat , 
1742+ 						route_params_config :  * route_params_config , 
17381743						retryable_invoice_request, 
17391744					} ; 
17401745					core:: mem:: swap ( & mut  new_val,  entry. into_mut ( ) ) ; 
@@ -1751,6 +1756,11 @@ impl OutboundPayments {
17511756		max_total_routing_fee_msat :  Option < u64 > ,  retryable_invoice_request :  Option < RetryableInvoiceRequest > 
17521757	)  -> Result < ( ) ,  ( ) >  { 
17531758		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+ 		) ; 
17541764		match  pending_outbounds. entry ( payment_id)  { 
17551765			hash_map:: Entry :: Occupied ( _)  => Err ( ( ) ) , 
17561766			hash_map:: Entry :: Vacant ( entry)  => { 
@@ -1760,7 +1770,7 @@ impl OutboundPayments {
17601770				entry. insert ( PendingOutboundPayment :: AwaitingInvoice  { 
17611771					expiration, 
17621772					retry_strategy, 
1763- 					max_total_routing_fee_msat , 
1773+ 					route_params_config , 
17641774					retryable_invoice_request, 
17651775				} ) ; 
17661776
@@ -2390,13 +2400,15 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
23902400	( 5 ,  AwaitingInvoice )  => { 
23912401		( 0 ,  expiration,  required) , 
23922402		( 2 ,  retry_strategy,  required) , 
2393- 		( 4 ,  max_total_routing_fee_msat ,  option ) , 
2403+ 		// TODO: Add support for legacy `max_total_routing_fee_msat` 
23942404		( 5 ,  retryable_invoice_request,  option) , 
2405+ 		( 7 ,  route_params_config,  ( default_value,  RouteParametersConfig :: new( ) ) ) , 
23952406	} , 
23962407	( 7 ,  InvoiceReceived )  => { 
23972408		( 0 ,  payment_hash,  required) , 
23982409		( 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` 
24002412	} , 
24012413	// Added in 0.1. Prior versions will drop these outbounds on downgrade, which is safe because no 
24022414	// HTLCs are in-flight. 
@@ -2412,7 +2424,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
24122424	( 11 ,  AwaitingOffer )  => { 
24132425		( 0 ,  expiration,  required) , 
24142426		( 2 ,  retry_strategy,  required) , 
2415- 		( 4 ,  max_total_routing_fee_msat ,  option ) , 
2427+ 		( 5 ,  route_params_config ,   ( default_value ,   RouteParametersConfig :: new ( ) ) ) , 
24162428		( 6 ,  amount_msats,  required) , 
24172429	} , 
24182430) ; 
0 commit comments