@@ -55,9 +55,7 @@ use crate::ln::channel_state::ChannelDetails;
5555use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
5656#[cfg(any(feature = "_test_utils", test))]
5757use crate::types::features::Bolt11InvoiceFeatures;
58- use crate::routing::router::{BlindedTail, InFlightHtlcs, Path, Payee, PaymentParameters, RouteParameters, Router};
59- #[cfg(test)]
60- use crate::routing::router::Route;
58+ use crate::routing::router::{BlindedTail, FixedRouter, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteParameters, Router};
6159use 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};
6260use crate::ln::msgs;
6361use crate::ln::onion_utils;
@@ -2393,9 +2391,6 @@ where
23932391 fee_estimator: LowerBoundedFeeEstimator<F>,
23942392 chain_monitor: M,
23952393 tx_broadcaster: T,
2396- #[cfg(fuzzing)]
2397- pub router: R,
2398- #[cfg(not(fuzzing))]
23992394 router: R,
24002395 message_router: MR,
24012396
@@ -4578,21 +4573,30 @@ where
45784573 }
45794574 }
45804575
4581- // Deprecated send method, for testing use [`Self::send_payment`] and
4582- // [`TestRouter::expect_find_route`] instead.
4583- //
4584- // [`TestRouter::expect_find_route`]: crate::util::test_utils::TestRouter::expect_find_route
4585- #[cfg(test)]
4586- pub(crate) fn send_payment_with_route(
4587- &self, route: Route, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields,
4576+ /// Sends a payment along a given route. See [`Self::send_payment`] for more info.
4577+ ///
4578+ /// LDK will not automatically retry this payment, though it may be manually re-sent after an
4579+ /// [`Event::PaymentFailed`] is generated.
4580+ pub fn send_payment_with_route(
4581+ &self, mut route: Route, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields,
45884582 payment_id: PaymentId
4589- ) -> Result<(), PaymentSendFailure > {
4583+ ) -> Result<(), RetryableSendFailure > {
45904584 let best_block_height = self.best_block.read().unwrap().height;
45914585 let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4586+ let route_params = route.route_params.clone().unwrap_or_else(|| {
4587+ // Create a dummy since route params are a required parameter but unused in this case
4588+ let payment_params = PaymentParameters::from_node_id(
4589+ self.get_our_node_id(), MIN_FINAL_CLTV_EXPIRY_DELTA as u32
4590+ );
4591+ RouteParameters::from_payment_params_and_value(payment_params, route.get_total_amount())
4592+ });
4593+ if route.route_params.is_none() { route.route_params = Some(route_params.clone()); }
4594+ let router = FixedRouter::new(route);
45924595 self.pending_outbound_payments
4593- .send_payment_with_route(&route, payment_hash, recipient_onion, payment_id,
4594- &self.entropy_source, &self.node_signer, best_block_height,
4595- |args| self.send_payment_along_path(args))
4596+ .send_payment(payment_hash, recipient_onion, payment_id, Retry::Attempts(0),
4597+ route_params, &router, self.list_usable_channels(), || self.compute_inflight_htlcs(),
4598+ &self.entropy_source, &self.node_signer, best_block_height, &self.logger,
4599+ &self.pending_events, |args| self.send_payment_along_path(args))
45964600 }
45974601
45984602 /// Sends a payment to the route found using the provided [`RouteParameters`], retrying failed
@@ -4621,7 +4625,8 @@ where
46214625 /// [`ChannelManager::list_recent_payments`] for more information.
46224626 ///
46234627 /// Routes are automatically found using the [`Router] provided on startup. To fix a route for a
4624- /// particular payment, match the [`PaymentId`] passed to [`Router::find_route_with_id`].
4628+ /// particular payment, use [`Self::send_payment_with_route`] or match the [`PaymentId`] passed to
4629+ /// [`Router::find_route_with_id`].
46254630 ///
46264631 /// [`Event::PaymentSent`]: events::Event::PaymentSent
46274632 /// [`Event::PaymentFailed`]: events::Event::PaymentFailed
@@ -14354,7 +14359,7 @@ mod tests {
1435414359 use crate::events::{Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, ClosureReason};
1435514360 use crate::ln::types::ChannelId;
1435614361 use crate::types::payment::{PaymentPreimage, PaymentHash, PaymentSecret};
14357- use crate::ln::channelmanager::{create_recv_pending_htlc_info, HTLCForwardInfo, inbound_payment, PaymentId, PaymentSendFailure, RecipientOnionFields, InterceptId};
14362+ use crate::ln::channelmanager::{create_recv_pending_htlc_info, HTLCForwardInfo, inbound_payment, PaymentId, RecipientOnionFields, InterceptId};
1435814363 use crate::ln::functional_test_utils::*;
1435914364 use crate::ln::msgs::{self, ErrorAction};
1436014365 use crate::ln::msgs::ChannelMessageHandler;
@@ -14785,14 +14790,17 @@ mod tests {
1478514790 route.paths[1].hops[0].short_channel_id = chan_2_id;
1478614791 route.paths[1].hops[1].short_channel_id = chan_4_id;
1478714792
14788- match nodes[0].node.send_payment_with_route(route, payment_hash,
14789- RecipientOnionFields::spontaneous_empty(), PaymentId(payment_hash.0))
14790- .unwrap_err() {
14791- PaymentSendFailure::ParameterError(APIError::APIMisuseError { ref err }) => {
14792- assert!(regex::Regex::new(r"Payment secret is required for multi-path payments").unwrap().is_match(err))
14793- },
14794- _ => panic!("unexpected error")
14793+ nodes[0].node.send_payment_with_route(route, payment_hash,
14794+ RecipientOnionFields::spontaneous_empty(), PaymentId(payment_hash.0)).unwrap();
14795+ let events = nodes[0].node.get_and_clear_pending_events();
14796+ assert_eq!(events.len(), 1);
14797+ match events[0] {
14798+ Event::PaymentFailed { reason, .. } => {
14799+ assert_eq!(reason.unwrap(), crate::events::PaymentFailureReason::UnexpectedError);
14800+ }
14801+ _ => panic!()
1479514802 }
14803+ nodes[0].logger.assert_log_contains("lightning::ln::outbound_payment", "Payment secret is required for multi-path payments", 2);
1479614804 assert!(nodes[0].node.list_recent_payments().is_empty());
1479714805 }
1479814806
0 commit comments