@@ -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 {
6262 AwaitingOffer {
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.
6868 amount_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
@@ -867,14 +868,14 @@ impl OutboundPayments {
867868 match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
868869 hash_map:: Entry :: Occupied ( entry) => match entry. get ( ) {
869870 PendingOutboundPayment :: AwaitingInvoice {
870- retry_strategy : retry, max_total_routing_fee_msat : max_total_fee , ..
871+ retry_strategy : retry, route_params_config , ..
871872 } => {
872873 retry_strategy = * retry;
873- max_total_routing_fee_msat = * max_total_fee ;
874+ max_total_routing_fee_msat = route_params_config . max_total_routing_fee_msat ;
874875 * entry. into_mut ( ) = PendingOutboundPayment :: InvoiceReceived {
875876 payment_hash,
876877 retry_strategy : * retry,
877- max_total_routing_fee_msat ,
878+ route_params_config : * route_params_config ,
878879 } ;
879880 } ,
880881 _ => return Err ( Bolt12PaymentError :: DuplicateInvoice ) ,
@@ -1035,7 +1036,7 @@ impl OutboundPayments {
10351036 match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
10361037 hash_map:: Entry :: Occupied ( mut entry) => match entry. get_mut ( ) {
10371038 PendingOutboundPayment :: AwaitingInvoice {
1038- retry_strategy, retryable_invoice_request, max_total_routing_fee_msat , ..
1039+ retry_strategy, retryable_invoice_request, route_params_config , ..
10391040 } => {
10401041 let invreq = & retryable_invoice_request
10411042 . as_ref ( )
@@ -1067,7 +1068,7 @@ impl OutboundPayments {
10671068 let payment_hash = PaymentHash ( Sha256 :: hash ( & keysend_preimage. 0 ) . to_byte_array ( ) ) ;
10681069 let pay_params = PaymentParameters :: from_static_invoice ( invoice) ;
10691070 let mut route_params = RouteParameters :: from_payment_params_and_value ( pay_params, amount_msat) ;
1070- route_params. max_total_routing_fee_msat = * max_total_routing_fee_msat;
1071+ route_params. max_total_routing_fee_msat = route_params_config . max_total_routing_fee_msat ;
10711072
10721073 if let Err ( ( ) ) = onion_utils:: set_max_path_length (
10731074 & mut route_params, & RecipientOnionFields :: spontaneous_empty ( ) , Some ( keysend_preimage) ,
@@ -1713,13 +1714,17 @@ impl OutboundPayments {
17131714 max_total_routing_fee_msat : Option < u64 > , amount_msats : u64 ,
17141715 ) -> Result < ( ) , ( ) > {
17151716 let mut pending_outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1717+ let route_params_config = max_total_routing_fee_msat. map_or (
1718+ RouteParametersConfig :: default ( ) ,
1719+ |fee_msat| RouteParametersConfig :: default ( ) . with_max_total_routing_fee_msat ( fee_msat)
1720+ ) ;
17161721 match pending_outbounds. entry ( payment_id) {
17171722 hash_map:: Entry :: Occupied ( _) => Err ( ( ) ) ,
17181723 hash_map:: Entry :: Vacant ( entry) => {
17191724 entry. insert ( PendingOutboundPayment :: AwaitingOffer {
17201725 expiration,
17211726 retry_strategy,
1722- max_total_routing_fee_msat ,
1727+ route_params_config ,
17231728 amount_msats,
17241729 } ) ;
17251730
@@ -1746,12 +1751,12 @@ impl OutboundPayments {
17461751 match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
17471752 hash_map:: Entry :: Occupied ( entry) => match entry. get ( ) {
17481753 PendingOutboundPayment :: AwaitingOffer {
1749- expiration, retry_strategy, max_total_routing_fee_msat , ..
1754+ expiration, retry_strategy, route_params_config , ..
17501755 } => {
17511756 let mut new_val = PendingOutboundPayment :: AwaitingInvoice {
17521757 expiration : * expiration,
17531758 retry_strategy : * retry_strategy,
1754- max_total_routing_fee_msat : * max_total_routing_fee_msat ,
1759+ route_params_config : * route_params_config ,
17551760 retryable_invoice_request,
17561761 } ;
17571762 core:: mem:: swap ( & mut new_val, entry. into_mut ( ) ) ;
@@ -1768,6 +1773,11 @@ impl OutboundPayments {
17681773 max_total_routing_fee_msat : Option < u64 > , retryable_invoice_request : Option < RetryableInvoiceRequest >
17691774 ) -> Result < ( ) , ( ) > {
17701775 let mut pending_outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1776+ let route_params_config = max_total_routing_fee_msat. map_or (
1777+ RouteParametersConfig :: default ( ) ,
1778+ |fee_msats| RouteParametersConfig :: default ( )
1779+ . with_max_total_routing_fee_msat ( fee_msats)
1780+ ) ;
17711781 match pending_outbounds. entry ( payment_id) {
17721782 hash_map:: Entry :: Occupied ( _) => Err ( ( ) ) ,
17731783 hash_map:: Entry :: Vacant ( entry) => {
@@ -1777,7 +1787,7 @@ impl OutboundPayments {
17771787 entry. insert ( PendingOutboundPayment :: AwaitingInvoice {
17781788 expiration,
17791789 retry_strategy,
1780- max_total_routing_fee_msat ,
1790+ route_params_config ,
17811791 retryable_invoice_request,
17821792 } ) ;
17831793
@@ -2411,13 +2421,35 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
24112421 ( 5 , AwaitingInvoice ) => {
24122422 ( 0 , expiration, required) ,
24132423 ( 2 , retry_strategy, required) ,
2414- ( 4 , max_total_routing_fee_msat, option) ,
2424+ ( 4 , _max_total_routing_fee_msat, ( legacy, u64 ,
2425+ |us: & PendingOutboundPayment | match us {
2426+ PendingOutboundPayment :: AwaitingInvoice { route_params_config, .. } => route_params_config. max_total_routing_fee_msat,
2427+ _ => None ,
2428+ }
2429+ ) ) ,
24152430 ( 5 , retryable_invoice_request, option) ,
2431+ ( 7 , route_params_config, ( default_value, (
2432+ _max_total_routing_fee_msat. map_or(
2433+ RouteParametersConfig :: default ( ) ,
2434+ |fee_msat| RouteParametersConfig :: default ( ) . with_max_total_routing_fee_msat( fee_msat)
2435+ )
2436+ ) ) ) ,
24162437 } ,
24172438 ( 7 , InvoiceReceived ) => {
24182439 ( 0 , payment_hash, required) ,
24192440 ( 2 , retry_strategy, required) ,
2420- ( 4 , max_total_routing_fee_msat, option) ,
2441+ ( 4 , _max_total_routing_fee_msat, ( legacy, u64 ,
2442+ |us: & PendingOutboundPayment | match us {
2443+ PendingOutboundPayment :: InvoiceReceived { route_params_config, .. } => route_params_config. max_total_routing_fee_msat,
2444+ _ => None ,
2445+ }
2446+ ) ) ,
2447+ ( 5 , route_params_config, ( default_value, (
2448+ _max_total_routing_fee_msat. map_or(
2449+ RouteParametersConfig :: default ( ) ,
2450+ |fee_msat| RouteParametersConfig :: default ( ) . with_max_total_routing_fee_msat( fee_msat)
2451+ )
2452+ ) ) ) ,
24212453 } ,
24222454 // Added in 0.1. Prior versions will drop these outbounds on downgrade, which is safe because no
24232455 // HTLCs are in-flight.
@@ -2433,7 +2465,18 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
24332465 ( 11 , AwaitingOffer ) => {
24342466 ( 0 , expiration, required) ,
24352467 ( 2 , retry_strategy, required) ,
2436- ( 4 , max_total_routing_fee_msat, option) ,
2468+ ( 4 , _max_total_routing_fee_msat, ( legacy, u64 ,
2469+ |us: & PendingOutboundPayment | match us {
2470+ PendingOutboundPayment :: AwaitingOffer { route_params_config, .. } => route_params_config. max_total_routing_fee_msat,
2471+ _ => None ,
2472+ }
2473+ ) ) ,
2474+ ( 5 , route_params_config, ( default_value, (
2475+ _max_total_routing_fee_msat. map_or(
2476+ RouteParametersConfig :: default ( ) ,
2477+ |fee_msat| RouteParametersConfig :: default ( ) . with_max_total_routing_fee_msat( fee_msat)
2478+ )
2479+ ) ) ) ,
24372480 ( 6 , amount_msats, required) ,
24382481 } ,
24392482) ;
0 commit comments