@@ -53,7 +53,9 @@ use crate::ln::channel_state::ChannelDetails;
5353use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
5454#[cfg(any(feature = "_test_utils", test))]
5555use crate::types::features::Bolt11InvoiceFeatures;
56- use crate::routing::router::{BlindedTail, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteParameters, Router};
56+ use crate::routing::router::{BlindedTail, InFlightHtlcs, Path, Payee, PaymentParameters, RouteParameters, Router};
57+ #[cfg(any(test, fuzzing))]
58+ use crate::routing::router::Route;
5759use 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};
5860use crate::ln::msgs;
5961use crate::ln::onion_utils;
@@ -4880,47 +4882,21 @@ where
48804882 /// would be able to guess -- otherwise, an intermediate node may claim the payment and it will
48814883 /// never reach the recipient.
48824884 ///
4883- /// See [`send_payment`] documentation for more details on the idempotency guarantees provided by
4884- /// the [`PaymentId`] key.
4885- ///
4886- /// # Possible Error States on [`PaymentSendFailure`]
4887- ///
4888- /// Each path may have a different return value, and [`PaymentSendFailure`] may return a `Vec` with
4889- /// each entry matching the corresponding-index entry in the route paths, see
4890- /// [`PaymentSendFailure`] for more info.
4891- ///
4892- /// In general, a path may raise:
4893- /// * [`APIError::InvalidRoute`] when an invalid route or forwarding parameter (cltv_delta, fee,
4894- /// node public key) is specified.
4895- /// * [`APIError::ChannelUnavailable`] if the next-hop channel is not available as it has been
4896- /// closed, doesn't exist, or the peer is currently disconnected.
4897- /// * [`APIError::MonitorUpdateInProgress`] if a new monitor update failure prevented sending the
4898- /// relevant updates.
4899- ///
4900- /// Note that depending on the type of the [`PaymentSendFailure`] the HTLC may have been
4901- /// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
4902- /// different route unless you intend to pay twice!
4903- ///
49044885 /// Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
49054886 /// [`send_payment`] for more information about the risks of duplicate preimage usage.
49064887 ///
4907- /// [`send_payment`]: Self::send_payment
4908- pub fn send_spontaneous_payment(&self, route: &Route, payment_preimage: Option<PaymentPreimage>, recipient_onion: RecipientOnionFields, payment_id: PaymentId) -> Result<PaymentHash, PaymentSendFailure> {
4909- let best_block_height = self.best_block.read().unwrap().height;
4910- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4911- self.pending_outbound_payments.send_spontaneous_payment_with_route(
4912- route, payment_preimage, recipient_onion, payment_id, &self.entropy_source,
4913- &self.node_signer, best_block_height, |args| self.send_payment_along_path(args))
4914- }
4915-
4916- /// Similar to [`ChannelManager::send_spontaneous_payment`], but will automatically find a route
4917- /// based on `route_params` and retry failed payment paths based on `retry_strategy`.
4888+ /// See [`send_payment`] documentation for more details on the idempotency guarantees provided by
4889+ /// the [`PaymentId`] key.
49184890 ///
49194891 /// See [`PaymentParameters::for_keysend`] for help in constructing `route_params` for spontaneous
49204892 /// payments.
49214893 ///
4894+ /// [`send_payment`]: Self::send_payment
49224895 /// [`PaymentParameters::for_keysend`]: crate::routing::router::PaymentParameters::for_keysend
4923- pub fn send_spontaneous_payment_with_retry(&self, payment_preimage: Option<PaymentPreimage>, recipient_onion: RecipientOnionFields, payment_id: PaymentId, route_params: RouteParameters, retry_strategy: Retry) -> Result<PaymentHash, RetryableSendFailure> {
4896+ pub fn send_spontaneous_payment(
4897+ &self, payment_preimage: Option<PaymentPreimage>, recipient_onion: RecipientOnionFields,
4898+ payment_id: PaymentId, route_params: RouteParameters, retry_strategy: Retry
4899+ ) -> Result<PaymentHash, RetryableSendFailure> {
49244900 let best_block_height = self.best_block.read().unwrap().height;
49254901 let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
49264902 self.pending_outbound_payments.send_spontaneous_payment(payment_preimage, recipient_onion,
@@ -14330,6 +14306,7 @@ mod tests {
1433014306 use crate::ln::functional_test_utils::*;
1433114307 use crate::ln::msgs::{self, ErrorAction};
1433214308 use crate::ln::msgs::ChannelMessageHandler;
14309+ use crate::ln::outbound_payment::Retry;
1433314310 use crate::prelude::*;
1433414311 use crate::routing::router::{PaymentParameters, RouteParameters, find_route};
1433514312 use crate::util::errors::APIError;
@@ -14447,8 +14424,10 @@ mod tests {
1444714424 pass_along_path(&nodes[0], &[&nodes[1]], 200_000, our_payment_hash, Some(payment_secret), events.drain(..).next().unwrap(), false, None);
1444814425
1444914426 // Next, send a keysend payment with the same payment_hash and make sure it fails.
14450- nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
14451- RecipientOnionFields::spontaneous_empty(), PaymentId(payment_preimage.0)).unwrap();
14427+ nodes[0].node.send_spontaneous_payment(
14428+ Some(payment_preimage), RecipientOnionFields::spontaneous_empty(),
14429+ PaymentId(payment_preimage.0), route.route_params.clone().unwrap(), Retry::Attempts(0)
14430+ ).unwrap();
1445214431 check_added_monitors!(nodes[0], 1);
1445314432 let mut events = nodes[0].node.get_and_clear_pending_msg_events();
1445414433 assert_eq!(events.len(), 1);
@@ -14560,12 +14539,10 @@ mod tests {
1456014539 let route_params = RouteParameters::from_payment_params_and_value(
1456114540 PaymentParameters::for_keysend(expected_route.last().unwrap().node.get_our_node_id(),
1456214541 TEST_FINAL_CLTV, false), 100_000);
14563- let route = find_route (
14564- &nodes[0].node.get_our_node_id( ), &route_params, &nodes[0].network_graph ,
14565- None, nodes[0].logger, &scorer, &Default::default(), &random_seed_bytes
14542+ nodes[0].node.send_spontaneous_payment (
14543+ Some(payment_preimage ), RecipientOnionFields::spontaneous_empty() ,
14544+ PaymentId(payment_preimage.0), route_params.clone(), Retry::Attempts(0)
1456614545 ).unwrap();
14567- nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
14568- RecipientOnionFields::spontaneous_empty(), PaymentId(payment_preimage.0)).unwrap();
1456914546 check_added_monitors!(nodes[0], 1);
1457014547 let mut events = nodes[0].node.get_and_clear_pending_msg_events();
1457114548 assert_eq!(events.len(), 1);
@@ -14598,8 +14575,10 @@ mod tests {
1459814575 &nodes[0].node.get_our_node_id(), &route_params, &nodes[0].network_graph,
1459914576 None, nodes[0].logger, &scorer, &Default::default(), &random_seed_bytes
1460014577 ).unwrap();
14601- let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
14602- RecipientOnionFields::spontaneous_empty(), PaymentId(payment_preimage.0)).unwrap();
14578+ let payment_hash = nodes[0].node.send_spontaneous_payment(
14579+ Some(payment_preimage), RecipientOnionFields::spontaneous_empty(),
14580+ PaymentId(payment_preimage.0), route.route_params.clone().unwrap(), Retry::Attempts(0)
14581+ ).unwrap();
1460314582 check_added_monitors!(nodes[0], 1);
1460414583 let mut events = nodes[0].node.get_and_clear_pending_msg_events();
1460514584 assert_eq!(events.len(), 1);
@@ -14637,8 +14616,10 @@ mod tests {
1463714616
1463814617 // To start (3), send a keysend payment but don't claim it.
1463914618 let payment_id_1 = PaymentId([44; 32]);
14640- let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
14641- RecipientOnionFields::spontaneous_empty(), payment_id_1).unwrap();
14619+ let payment_hash = nodes[0].node.send_spontaneous_payment(
14620+ Some(payment_preimage), RecipientOnionFields::spontaneous_empty(), payment_id_1,
14621+ route.route_params.clone().unwrap(), Retry::Attempts(0)
14622+ ).unwrap();
1464214623 check_added_monitors!(nodes[0], 1);
1464314624 let mut events = nodes[0].node.get_and_clear_pending_msg_events();
1464414625 assert_eq!(events.len(), 1);
@@ -14651,13 +14632,11 @@ mod tests {
1465114632 PaymentParameters::for_keysend(expected_route.last().unwrap().node.get_our_node_id(), TEST_FINAL_CLTV, false),
1465214633 100_000
1465314634 );
14654- let route = find_route(
14655- &nodes[0].node.get_our_node_id(), &route_params, &nodes[0].network_graph,
14656- None, nodes[0].logger, &scorer, &Default::default(), &random_seed_bytes
14657- ).unwrap();
1465814635 let payment_id_2 = PaymentId([45; 32]);
14659- nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
14660- RecipientOnionFields::spontaneous_empty(), payment_id_2).unwrap();
14636+ nodes[0].node.send_spontaneous_payment(
14637+ Some(payment_preimage), RecipientOnionFields::spontaneous_empty(), payment_id_2, route_params,
14638+ Retry::Attempts(0)
14639+ ).unwrap();
1466114640 check_added_monitors!(nodes[0], 1);
1466214641 let mut events = nodes[0].node.get_and_clear_pending_msg_events();
1466314642 assert_eq!(events.len(), 1);
0 commit comments