@@ -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;
@@ -4784,47 +4786,21 @@ where
4784
4786
/// would be able to guess -- otherwise, an intermediate node may claim the payment and it will
4785
4787
/// never reach the recipient.
4786
4788
///
4787
- /// See [`send_payment`] documentation for more details on the idempotency guarantees provided by
4788
- /// the [`PaymentId`] key.
4789
- ///
4790
- /// # Possible Error States on [`PaymentSendFailure`]
4791
- ///
4792
- /// Each path may have a different return value, and [`PaymentSendFailure`] may return a `Vec` with
4793
- /// each entry matching the corresponding-index entry in the route paths, see
4794
- /// [`PaymentSendFailure`] for more info.
4795
- ///
4796
- /// In general, a path may raise:
4797
- /// * [`APIError::InvalidRoute`] when an invalid route or forwarding parameter (cltv_delta, fee,
4798
- /// node public key) is specified.
4799
- /// * [`APIError::ChannelUnavailable`] if the next-hop channel is not available as it has been
4800
- /// closed, doesn't exist, or the peer is currently disconnected.
4801
- /// * [`APIError::MonitorUpdateInProgress`] if a new monitor update failure prevented sending the
4802
- /// relevant updates.
4803
- ///
4804
- /// Note that depending on the type of the [`PaymentSendFailure`] the HTLC may have been
4805
- /// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
4806
- /// different route unless you intend to pay twice!
4807
- ///
4808
4789
/// Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
4809
4790
/// [`send_payment`] for more information about the risks of duplicate preimage usage.
4810
4791
///
4811
- /// [`send_payment`]: Self::send_payment
4812
- pub fn send_spontaneous_payment(&self, route: &Route, payment_preimage: Option<PaymentPreimage>, recipient_onion: RecipientOnionFields, payment_id: PaymentId) -> Result<PaymentHash, PaymentSendFailure> {
4813
- let best_block_height = self.best_block.read().unwrap().height;
4814
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4815
- self.pending_outbound_payments.send_spontaneous_payment_with_route(
4816
- route, payment_preimage, recipient_onion, payment_id, &self.entropy_source,
4817
- &self.node_signer, best_block_height, |args| self.send_payment_along_path(args))
4818
- }
4819
-
4820
- /// Similar to [`ChannelManager::send_spontaneous_payment`], but will automatically find a route
4821
- /// based on `route_params` and retry failed payment paths based on `retry_strategy`.
4792
+ /// See [`send_payment`] documentation for more details on the idempotency guarantees provided by
4793
+ /// the [`PaymentId`] key.
4822
4794
///
4823
4795
/// See [`PaymentParameters::for_keysend`] for help in constructing `route_params` for spontaneous
4824
4796
/// payments.
4825
4797
///
4798
+ /// [`send_payment`]: Self::send_payment
4826
4799
/// [`PaymentParameters::for_keysend`]: crate::routing::router::PaymentParameters::for_keysend
4827
- 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> {
4800
+ pub fn send_spontaneous_payment(
4801
+ &self, payment_preimage: Option<PaymentPreimage>, recipient_onion: RecipientOnionFields,
4802
+ payment_id: PaymentId, route_params: RouteParameters, retry_strategy: Retry
4803
+ ) -> Result<PaymentHash, RetryableSendFailure> {
4828
4804
let best_block_height = self.best_block.read().unwrap().height;
4829
4805
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4830
4806
self.pending_outbound_payments.send_spontaneous_payment(payment_preimage, recipient_onion,
@@ -14213,6 +14189,7 @@ mod tests {
14213
14189
use crate::ln::functional_test_utils::*;
14214
14190
use crate::ln::msgs::{self, ErrorAction};
14215
14191
use crate::ln::msgs::ChannelMessageHandler;
14192
+ use crate::ln::outbound_payment::Retry;
14216
14193
use crate::prelude::*;
14217
14194
use crate::routing::router::{PaymentParameters, RouteParameters, find_route};
14218
14195
use crate::util::errors::APIError;
@@ -14330,8 +14307,10 @@ mod tests {
14330
14307
pass_along_path(&nodes[0], &[&nodes[1]], 200_000, our_payment_hash, Some(payment_secret), events.drain(..).next().unwrap(), false, None);
14331
14308
14332
14309
// Next, send a keysend payment with the same payment_hash and make sure it fails.
14333
- nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
14334
- RecipientOnionFields::spontaneous_empty(), PaymentId(payment_preimage.0)).unwrap();
14310
+ nodes[0].node.send_spontaneous_payment(
14311
+ Some(payment_preimage), RecipientOnionFields::spontaneous_empty(),
14312
+ PaymentId(payment_preimage.0), route.route_params.clone().unwrap(), Retry::Attempts(0)
14313
+ ).unwrap();
14335
14314
check_added_monitors!(nodes[0], 1);
14336
14315
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
14337
14316
assert_eq!(events.len(), 1);
@@ -14453,12 +14432,10 @@ mod tests {
14453
14432
let route_params = RouteParameters::from_payment_params_and_value(
14454
14433
PaymentParameters::for_keysend(expected_route.last().unwrap().node.get_our_node_id(),
14455
14434
TEST_FINAL_CLTV, false), 100_000);
14456
- let route = find_route (
14457
- &nodes[0].node.get_our_node_id( ), &route_params, &nodes[0].network_graph ,
14458
- None, nodes[0].logger, &scorer, &Default::default(), &random_seed_bytes
14435
+ nodes[0].node.send_spontaneous_payment (
14436
+ Some(payment_preimage ), RecipientOnionFields::spontaneous_empty() ,
14437
+ PaymentId(payment_preimage.0), route_params.clone(), Retry::Attempts(0)
14459
14438
).unwrap();
14460
- nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
14461
- RecipientOnionFields::spontaneous_empty(), PaymentId(payment_preimage.0)).unwrap();
14462
14439
check_added_monitors!(nodes[0], 1);
14463
14440
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
14464
14441
assert_eq!(events.len(), 1);
@@ -14491,8 +14468,10 @@ mod tests {
14491
14468
&nodes[0].node.get_our_node_id(), &route_params, &nodes[0].network_graph,
14492
14469
None, nodes[0].logger, &scorer, &Default::default(), &random_seed_bytes
14493
14470
).unwrap();
14494
- let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
14495
- RecipientOnionFields::spontaneous_empty(), PaymentId(payment_preimage.0)).unwrap();
14471
+ let payment_hash = nodes[0].node.send_spontaneous_payment(
14472
+ Some(payment_preimage), RecipientOnionFields::spontaneous_empty(),
14473
+ PaymentId(payment_preimage.0), route.route_params.clone().unwrap(), Retry::Attempts(0)
14474
+ ).unwrap();
14496
14475
check_added_monitors!(nodes[0], 1);
14497
14476
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
14498
14477
assert_eq!(events.len(), 1);
@@ -14530,8 +14509,10 @@ mod tests {
14530
14509
14531
14510
// To start (3), send a keysend payment but don't claim it.
14532
14511
let payment_id_1 = PaymentId([44; 32]);
14533
- let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
14534
- RecipientOnionFields::spontaneous_empty(), payment_id_1).unwrap();
14512
+ let payment_hash = nodes[0].node.send_spontaneous_payment(
14513
+ Some(payment_preimage), RecipientOnionFields::spontaneous_empty(), payment_id_1,
14514
+ route.route_params.clone().unwrap(), Retry::Attempts(0)
14515
+ ).unwrap();
14535
14516
check_added_monitors!(nodes[0], 1);
14536
14517
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
14537
14518
assert_eq!(events.len(), 1);
@@ -14544,13 +14525,11 @@ mod tests {
14544
14525
PaymentParameters::for_keysend(expected_route.last().unwrap().node.get_our_node_id(), TEST_FINAL_CLTV, false),
14545
14526
100_000
14546
14527
);
14547
- let route = find_route(
14548
- &nodes[0].node.get_our_node_id(), &route_params, &nodes[0].network_graph,
14549
- None, nodes[0].logger, &scorer, &Default::default(), &random_seed_bytes
14550
- ).unwrap();
14551
14528
let payment_id_2 = PaymentId([45; 32]);
14552
- nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
14553
- RecipientOnionFields::spontaneous_empty(), payment_id_2).unwrap();
14529
+ nodes[0].node.send_spontaneous_payment(
14530
+ Some(payment_preimage), RecipientOnionFields::spontaneous_empty(), payment_id_2, route_params,
14531
+ Retry::Attempts(0)
14532
+ ).unwrap();
14554
14533
check_added_monitors!(nodes[0], 1);
14555
14534
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
14556
14535
assert_eq!(events.len(), 1);
0 commit comments