@@ -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,31 @@ 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 route params since they're a required parameter but unused in this case
4588+ let (payee_node_id, cltv_delta) = route.paths.first()
4589+ .and_then(|path| path.hops.last().map(|hop| (hop.pubkey, hop.cltv_expiry_delta as u32)))
4590+ .unwrap_or_else(|| (PublicKey::from_slice(&[2; 32]).unwrap(), MIN_FINAL_CLTV_EXPIRY_DELTA as u32));
4591+ let dummy_payment_params = PaymentParameters::from_node_id(payee_node_id, cltv_delta);
4592+ RouteParameters::from_payment_params_and_value(dummy_payment_params, route.get_total_amount())
4593+ });
4594+ if route.route_params.is_none() { route.route_params = Some(route_params.clone()); }
4595+ let router = FixedRouter::new(route);
45924596 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))
4597+ .send_payment(payment_hash, recipient_onion, payment_id, Retry::Attempts(0),
4598+ route_params, &&router, self.list_usable_channels(), || self.compute_inflight_htlcs(),
4599+ &self.entropy_source, &self.node_signer, best_block_height, &self.logger,
4600+ &self.pending_events, |args| self.send_payment_along_path(args))
45964601 }
45974602
45984603 /// Sends a payment to the route found using the provided [`RouteParameters`], retrying failed
@@ -4621,7 +4626,8 @@ where
46214626 /// [`ChannelManager::list_recent_payments`] for more information.
46224627 ///
46234628 /// 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`].
4629+ /// particular payment, use [`Self::send_payment_with_route`] or match the [`PaymentId`] passed to
4630+ /// [`Router::find_route_with_id`].
46254631 ///
46264632 /// [`Event::PaymentSent`]: events::Event::PaymentSent
46274633 /// [`Event::PaymentFailed`]: events::Event::PaymentFailed
@@ -14354,7 +14360,7 @@ mod tests {
1435414360 use crate::events::{Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, ClosureReason};
1435514361 use crate::ln::types::ChannelId;
1435614362 use crate::types::payment::{PaymentPreimage, PaymentHash, PaymentSecret};
14357- use crate::ln::channelmanager::{create_recv_pending_htlc_info, HTLCForwardInfo, inbound_payment, PaymentId, PaymentSendFailure, RecipientOnionFields, InterceptId};
14363+ use crate::ln::channelmanager::{create_recv_pending_htlc_info, HTLCForwardInfo, inbound_payment, PaymentId, RecipientOnionFields, InterceptId};
1435814364 use crate::ln::functional_test_utils::*;
1435914365 use crate::ln::msgs::{self, ErrorAction};
1436014366 use crate::ln::msgs::ChannelMessageHandler;
@@ -14785,14 +14791,17 @@ mod tests {
1478514791 route.paths[1].hops[0].short_channel_id = chan_2_id;
1478614792 route.paths[1].hops[1].short_channel_id = chan_4_id;
1478714793
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")
14794+ nodes[0].node.send_payment_with_route(route, payment_hash,
14795+ RecipientOnionFields::spontaneous_empty(), PaymentId(payment_hash.0)).unwrap();
14796+ let events = nodes[0].node.get_and_clear_pending_events();
14797+ assert_eq!(events.len(), 1);
14798+ match events[0] {
14799+ Event::PaymentFailed { reason, .. } => {
14800+ assert_eq!(reason.unwrap(), crate::events::PaymentFailureReason::UnexpectedError);
14801+ }
14802+ _ => panic!()
1479514803 }
14804+ nodes[0].logger.assert_log_contains("lightning::ln::outbound_payment", "Payment secret is required for multi-path payments", 2);
1479614805 assert!(nodes[0].node.list_recent_payments().is_empty());
1479714806 }
1479814807
0 commit comments