@@ -53,7 +53,9 @@ use crate::ln::channel_state::ChannelDetails;
53
53
use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
54
54
#[cfg(any(feature = "_test_utils", test))]
55
55
use 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;
57
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};
58
60
use crate::ln::msgs;
59
61
use crate::ln::onion_utils;
@@ -4880,47 +4882,21 @@ where
4880
4882
/// would be able to guess -- otherwise, an intermediate node may claim the payment and it will
4881
4883
/// never reach the recipient.
4882
4884
///
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
- ///
4904
4885
/// Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
4905
4886
/// [`send_payment`] for more information about the risks of duplicate preimage usage.
4906
4887
///
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.
4918
4890
///
4919
4891
/// See [`PaymentParameters::for_keysend`] for help in constructing `route_params` for spontaneous
4920
4892
/// payments.
4921
4893
///
4894
+ /// [`send_payment`]: Self::send_payment
4922
4895
/// [`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> {
4924
4900
let best_block_height = self.best_block.read().unwrap().height;
4925
4901
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4926
4902
self.pending_outbound_payments.send_spontaneous_payment(payment_preimage, recipient_onion,
@@ -14330,6 +14306,7 @@ mod tests {
14330
14306
use crate::ln::functional_test_utils::*;
14331
14307
use crate::ln::msgs::{self, ErrorAction};
14332
14308
use crate::ln::msgs::ChannelMessageHandler;
14309
+ use crate::ln::outbound_payment::Retry;
14333
14310
use crate::prelude::*;
14334
14311
use crate::routing::router::{PaymentParameters, RouteParameters, find_route};
14335
14312
use crate::util::errors::APIError;
@@ -14447,8 +14424,10 @@ mod tests {
14447
14424
pass_along_path(&nodes[0], &[&nodes[1]], 200_000, our_payment_hash, Some(payment_secret), events.drain(..).next().unwrap(), false, None);
14448
14425
14449
14426
// 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();
14452
14431
check_added_monitors!(nodes[0], 1);
14453
14432
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
14454
14433
assert_eq!(events.len(), 1);
@@ -14560,12 +14539,10 @@ mod tests {
14560
14539
let route_params = RouteParameters::from_payment_params_and_value(
14561
14540
PaymentParameters::for_keysend(expected_route.last().unwrap().node.get_our_node_id(),
14562
14541
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)
14566
14545
).unwrap();
14567
- nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
14568
- RecipientOnionFields::spontaneous_empty(), PaymentId(payment_preimage.0)).unwrap();
14569
14546
check_added_monitors!(nodes[0], 1);
14570
14547
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
14571
14548
assert_eq!(events.len(), 1);
@@ -14598,8 +14575,10 @@ mod tests {
14598
14575
&nodes[0].node.get_our_node_id(), &route_params, &nodes[0].network_graph,
14599
14576
None, nodes[0].logger, &scorer, &Default::default(), &random_seed_bytes
14600
14577
).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();
14603
14582
check_added_monitors!(nodes[0], 1);
14604
14583
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
14605
14584
assert_eq!(events.len(), 1);
@@ -14637,8 +14616,10 @@ mod tests {
14637
14616
14638
14617
// To start (3), send a keysend payment but don't claim it.
14639
14618
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();
14642
14623
check_added_monitors!(nodes[0], 1);
14643
14624
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
14644
14625
assert_eq!(events.len(), 1);
@@ -14651,13 +14632,11 @@ mod tests {
14651
14632
PaymentParameters::for_keysend(expected_route.last().unwrap().node.get_our_node_id(), TEST_FINAL_CLTV, false),
14652
14633
100_000
14653
14634
);
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();
14658
14635
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();
14661
14640
check_added_monitors!(nodes[0], 1);
14662
14641
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
14663
14642
assert_eq!(events.len(), 1);
0 commit comments