@@ -55,9 +55,7 @@ use crate::ln::channel_state::ChannelDetails;
55
55
use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
56
56
#[cfg(any(feature = "_test_utils", test))]
57
57
use 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};
61
59
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};
62
60
use crate::ln::msgs;
63
61
use crate::ln::onion_utils;
@@ -2393,9 +2391,6 @@ where
2393
2391
fee_estimator: LowerBoundedFeeEstimator<F>,
2394
2392
chain_monitor: M,
2395
2393
tx_broadcaster: T,
2396
- #[cfg(fuzzing)]
2397
- pub router: R,
2398
- #[cfg(not(fuzzing))]
2399
2394
router: R,
2400
2395
message_router: MR,
2401
2396
@@ -4578,21 +4573,30 @@ where
4578
4573
}
4579
4574
}
4580
4575
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,
4588
4582
payment_id: PaymentId
4589
- ) -> Result<(), PaymentSendFailure > {
4583
+ ) -> Result<(), RetryableSendFailure > {
4590
4584
let best_block_height = self.best_block.read().unwrap().height;
4591
4585
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);
4592
4595
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))
4596
4600
}
4597
4601
4598
4602
/// Sends a payment to the route found using the provided [`RouteParameters`], retrying failed
@@ -4621,7 +4625,8 @@ where
4621
4625
/// [`ChannelManager::list_recent_payments`] for more information.
4622
4626
///
4623
4627
/// 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`].
4625
4630
///
4626
4631
/// [`Event::PaymentSent`]: events::Event::PaymentSent
4627
4632
/// [`Event::PaymentFailed`]: events::Event::PaymentFailed
@@ -14354,7 +14359,7 @@ mod tests {
14354
14359
use crate::events::{Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, ClosureReason};
14355
14360
use crate::ln::types::ChannelId;
14356
14361
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};
14358
14363
use crate::ln::functional_test_utils::*;
14359
14364
use crate::ln::msgs::{self, ErrorAction};
14360
14365
use crate::ln::msgs::ChannelMessageHandler;
@@ -14785,14 +14790,17 @@ mod tests {
14785
14790
route.paths[1].hops[0].short_channel_id = chan_2_id;
14786
14791
route.paths[1].hops[1].short_channel_id = chan_4_id;
14787
14792
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!()
14795
14802
}
14803
+ nodes[0].logger.assert_log_contains("lightning::ln::outbound_payment", "Payment secret is required for multi-path payments", 2);
14796
14804
assert!(nodes[0].node.list_recent_payments().is_empty());
14797
14805
}
14798
14806
0 commit comments