diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index bdf67b5da7c..4d721a9ea3a 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -53,7 +53,7 @@ use crate::ln::channel_state::ChannelDetails; use crate::ln::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures}; #[cfg(any(feature = "_test_utils", test))] use crate::ln::features::Bolt11InvoiceFeatures; -use crate::routing::router::{BlindedTail, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteParameters, Router}; +use crate::routing::router::{BlindedTail, InFlightHtlcs, ManualRoutingParameters, Path, Payee, PaymentParameters, Route, RouteParameters, Router}; use crate::ln::onion_payment::{check_incoming_htlc_cltv, create_recv_pending_htlc_info, create_fwd_pending_htlc_info, decode_incoming_update_add_htlc_onion, InboundHTLCErr, NextPacketDetails}; use crate::ln::msgs; use crate::ln::onion_utils; @@ -1893,10 +1893,11 @@ where /// # use lightning::events::{Event, EventsProvider}; /// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, Retry}; /// # use lightning::offers::offer::Offer; +/// # use lightning::routing::router::ManualRoutingParameters; /// # /// # fn example( /// # channel_manager: T, offer: &Offer, quantity: Option, amount_msats: Option, -/// # payer_note: Option, retry: Retry, max_total_routing_fee_msat: Option +/// # payer_note: Option, retry: Retry, max_total_routing_fee_msat: Option /// # ) { /// # let channel_manager = channel_manager.get_cm(); /// let payment_id = PaymentId([42; 32]); @@ -9208,10 +9209,15 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop($self); + let manual_routing_params = max_total_routing_fee_msat.map( + |fee_msat| ManualRoutingParameters::new() + .with_max_total_routing_fee_msat(fee_msat) + ); + let expiration = StaleExpiration::AbsoluteTimeout(absolute_expiry); $self.pending_outbound_payments .add_new_awaiting_invoice( - payment_id, expiration, retry_strategy, max_total_routing_fee_msat, None, + payment_id, expiration, retry_strategy, manual_routing_params, None, ) .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?; @@ -9304,7 +9310,7 @@ where pub fn pay_for_offer( &self, offer: &Offer, quantity: Option, amount_msats: Option, payer_note: Option, payment_id: PaymentId, retry_strategy: Retry, - max_total_routing_fee_msat: Option + manual_routing_params: Option ) -> Result<(), Bolt12SemanticError> { let expanded_key = &self.inbound_payment_key; let entropy = &*self.entropy_source; @@ -9346,7 +9352,7 @@ where }; self.pending_outbound_payments .add_new_awaiting_invoice( - payment_id, expiration, retry_strategy, max_total_routing_fee_msat, + payment_id, expiration, retry_strategy, manual_routing_params, Some(retryable_invoice_request) ) .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?; diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index 238017b6df6..f60f2fb216c 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -1598,13 +1598,9 @@ impl OutboundPayments { pub(super) fn add_new_awaiting_invoice( &self, payment_id: PaymentId, expiration: StaleExpiration, retry_strategy: Retry, - max_total_routing_fee_msat: Option, retryable_invoice_request: Option + manual_routing_params: Option, retryable_invoice_request: Option ) -> Result<(), ()> { let mut pending_outbounds = self.pending_outbound_payments.lock().unwrap(); - let manual_routing_params = max_total_routing_fee_msat.map( - |fee_msats| ManualRoutingParameters::new() - .with_max_total_routing_fee_msat(fee_msats) - ); match pending_outbounds.entry(payment_id) { hash_map::Entry::Occupied(_) => Err(()), hash_map::Entry::Vacant(entry) => { @@ -2281,7 +2277,7 @@ mod tests { use crate::offers::offer::OfferBuilder; use crate::offers::test_utils::*; use crate::routing::gossip::NetworkGraph; - use crate::routing::router::{InFlightHtlcs, Path, PaymentParameters, Route, RouteHop, RouteParameters}; + use crate::routing::router::{InFlightHtlcs, ManualRoutingParameters, Path, PaymentParameters, Route, RouteHop, RouteParameters}; use crate::sync::{Arc, Mutex, RwLock}; use crate::util::errors::APIError; use crate::util::hash_tables::new_hash_map; @@ -2695,10 +2691,12 @@ mod tests { .build().unwrap() .sign(recipient_sign).unwrap(); + let manual_routing_params = ManualRoutingParameters::new().with_max_total_routing_fee_msat(invoice.amount_msats() / 100 + 50_000); + assert!( outbound_payments.add_new_awaiting_invoice( payment_id, expiration, Retry::Attempts(0), - Some(invoice.amount_msats() / 100 + 50_000), None, + Some(manual_routing_params), None, ).is_ok() ); assert!(outbound_payments.has_pending_payments()); @@ -2796,9 +2794,11 @@ mod tests { assert!(!outbound_payments.has_pending_payments()); assert!(pending_events.lock().unwrap().is_empty()); + let manual_routing_params = ManualRoutingParameters::new().with_max_total_routing_fee_msat(1234); + assert!( outbound_payments.add_new_awaiting_invoice( - payment_id, expiration, Retry::Attempts(0), Some(1234), None, + payment_id, expiration, Retry::Attempts(0), Some(manual_routing_params), None, ).is_ok() ); assert!(outbound_payments.has_pending_payments());