Skip to content

Commit 812f867

Browse files
Remove retry_payments method
We're no longer supporting manual retries since ChannelManager::send_payment_with_retry can be parameterized by a retry strategy This commit also updates all docs related to retry_payment and abandon_payment. Since these docs frequently overlap with changes in preceding commits where we start abandoning payments on behalf of the user, all the docs are updated in one go.
1 parent b13ab12 commit 812f867

File tree

5 files changed

+64
-157
lines changed

5 files changed

+64
-157
lines changed

lightning/src/ln/channelmanager.rs

+13-33
Original file line numberDiff line numberDiff line change
@@ -1190,9 +1190,9 @@ pub enum RecentPaymentDetails {
11901190
/// made before LDK version 0.0.104.
11911191
payment_hash: Option<PaymentHash>,
11921192
},
1193-
/// After a payment is explicitly abandoned by calling [`ChannelManager::abandon_payment`], it
1194-
/// is marked as abandoned until an [`Event::PaymentFailed`] is generated. A payment could also
1195-
/// be marked as abandoned if pathfinding fails repeatedly or retries have been exhausted.
1193+
/// After a payment's retries are exhausted per the provided [`Retry`], or it is explicitly
1194+
/// abandoned via [`ChannelManager::abandon_payment`], it is marked as abandoned until an
1195+
/// [`Event::PaymentFailed`] is generated.
11961196
Abandoned {
11971197
/// Hash of the payment that we have given up trying to send.
11981198
payment_hash: PaymentHash,
@@ -1718,7 +1718,7 @@ where
17181718
///
17191719
/// This can be useful for payments that may have been prepared, but ultimately not sent, as a
17201720
/// result of a crash. If such a payment exists, is not listed here, and an
1721-
/// [`Event::PaymentSent`] has not been received, you may consider retrying the payment.
1721+
/// [`Event::PaymentSent`] has not been received, you may consider resending the payment.
17221722
///
17231723
/// [`Event::PaymentSent`]: events::Event::PaymentSent
17241724
pub fn list_recent_payments(&self) -> Vec<RecentPaymentDetails> {
@@ -2475,8 +2475,8 @@ where
24752475
/// If a pending payment is currently in-flight with the same [`PaymentId`] provided, this
24762476
/// method will error with an [`APIError::InvalidRoute`]. Note, however, that once a payment
24772477
/// is no longer pending (either via [`ChannelManager::abandon_payment`], or handling of an
2478-
/// [`Event::PaymentSent`]) LDK will not stop you from sending a second payment with the same
2479-
/// [`PaymentId`].
2478+
/// [`Event::PaymentSent`] or [`Event::PaymentFailed`]) LDK will not stop you from sending a
2479+
/// second payment with the same [`PaymentId`].
24802480
///
24812481
/// Thus, in order to ensure duplicate payments are not sent, you should implement your own
24822482
/// tracking of payments, including state to indicate once a payment has completed. Because you
@@ -2521,6 +2521,7 @@ where
25212521
/// [`Route`], we assume the invoice had the basic_mpp feature set.
25222522
///
25232523
/// [`Event::PaymentSent`]: events::Event::PaymentSent
2524+
/// [`Event::PaymentFailed`]: events::Event::PaymentFailed
25242525
/// [`PeerManager::process_events`]: crate::ln::peer_handler::PeerManager::process_events
25252526
/// [`ChannelMonitorUpdateStatus::InProgress`]: crate::chain::ChannelMonitorUpdateStatus::InProgress
25262527
pub fn send_payment(&self, route: &Route, payment_hash: PaymentHash, payment_secret: &Option<PaymentSecret>, payment_id: PaymentId) -> Result<(), PaymentSendFailure> {
@@ -2558,41 +2559,20 @@ where
25582559
}
25592560

25602561

2561-
/// Retries a payment along the given [`Route`].
2562-
///
2563-
/// Errors returned are a superset of those returned from [`send_payment`], so see
2564-
/// [`send_payment`] documentation for more details on errors. This method will also error if the
2565-
/// retry amount puts the payment more than 10% over the payment's total amount, if the payment
2566-
/// for the given `payment_id` cannot be found (likely due to timeout or success), or if
2567-
/// further retries have been disabled with [`abandon_payment`].
2568-
///
2569-
/// [`send_payment`]: [`ChannelManager::send_payment`]
2570-
/// [`abandon_payment`]: [`ChannelManager::abandon_payment`]
2571-
pub fn retry_payment(&self, route: &Route, payment_id: PaymentId) -> Result<(), PaymentSendFailure> {
2572-
let best_block_height = self.best_block.read().unwrap().height();
2573-
self.pending_outbound_payments.retry_payment_with_route(route, payment_id, &self.entropy_source, &self.node_signer, best_block_height,
2574-
|path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
2575-
self.send_payment_along_path(path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv))
2576-
}
2577-
2578-
/// Signals that no further retries for the given payment will occur.
2562+
/// Signals that no further retries for the given payment should occur. Useful if you have a
2563+
/// pending outbound payment with retries remaining, but wish to stop retrying the payment before
2564+
/// retries are exhausted.
25792565
///
2580-
/// After this method returns, no future calls to [`retry_payment`] for the given `payment_id`
2581-
/// are allowed. If no [`Event::PaymentFailed`] event had been generated before, one will be
2582-
/// generated as soon as there are no remaining pending HTLCs for this payment.
2566+
/// If no [`Event::PaymentFailed`] event had been generated before, one will be generated as soon
2567+
/// as there are no remaining pending HTLCs for this payment.
25832568
///
25842569
/// Note that calling this method does *not* prevent a payment from succeeding. You must still
25852570
/// wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to
25862571
/// determine the ultimate status of a payment.
25872572
///
25882573
/// If an [`Event::PaymentFailed`] event is generated and we restart without this
2589-
/// [`ChannelManager`] having been persisted, the payment may still be in the pending state
2590-
/// upon restart. This allows further calls to [`retry_payment`] (and requiring a second call
2591-
/// to [`abandon_payment`] to mark the payment as failed again). Otherwise, future calls to
2592-
/// [`retry_payment`] will fail with [`PaymentSendFailure::ParameterError`].
2574+
/// [`ChannelManager`] having been persisted, another [`Event::PaymentFailed`] may be generated.
25932575
///
2594-
/// [`abandon_payment`]: Self::abandon_payment
2595-
/// [`retry_payment`]: Self::retry_payment
25962576
/// [`Event::PaymentFailed`]: events::Event::PaymentFailed
25972577
/// [`Event::PaymentSent`]: events::Event::PaymentSent
25982578
pub fn abandon_payment(&self, payment_id: PaymentId) {

lightning/src/ln/outbound_payment.rs

+23-33
Original file line numberDiff line numberDiff line change
@@ -323,68 +323,58 @@ pub enum PaymentSendFailure {
323323
///
324324
/// You can freely resend the payment in full (with the parameter error fixed).
325325
///
326-
/// Because the payment failed outright, no payment tracking is done, you do not need to call
327-
/// [`ChannelManager::abandon_payment`] and [`ChannelManager::retry_payment`] will *not* work
328-
/// for this payment.
326+
/// Because the payment failed outright, no payment tracking is done and no
327+
/// [`Event::PaymentPathFailed`] or [`Event::PaymentFailed`] events will be generated.
329328
///
330-
/// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
331-
/// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
329+
/// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
330+
/// [`Event::PaymentFailed`]: crate::util::events::Event::PaymentFailed
332331
ParameterError(APIError),
333332
/// A parameter in a single path which was passed to send_payment was invalid, preventing us
334333
/// from attempting to send the payment at all.
335334
///
336335
/// You can freely resend the payment in full (with the parameter error fixed).
337336
///
337+
/// Because the payment failed outright, no payment tracking is done and no
338+
/// [`Event::PaymentPathFailed`] or [`Event::PaymentFailed`] events will be generated.
339+
///
338340
/// The results here are ordered the same as the paths in the route object which was passed to
339341
/// send_payment.
340342
///
341-
/// Because the payment failed outright, no payment tracking is done, you do not need to call
342-
/// [`ChannelManager::abandon_payment`] and [`ChannelManager::retry_payment`] will *not* work
343-
/// for this payment.
344-
///
345-
/// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
346-
/// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
343+
/// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
344+
/// [`Event::PaymentFailed`]: crate::util::events::Event::PaymentFailed
347345
PathParameterError(Vec<Result<(), APIError>>),
348346
/// All paths which were attempted failed to send, with no channel state change taking place.
349347
/// You can freely resend the payment in full (though you probably want to do so over different
350348
/// paths than the ones selected).
351349
///
352-
/// Because the payment failed outright, no payment tracking is done, you do not need to call
353-
/// [`ChannelManager::abandon_payment`] and [`ChannelManager::retry_payment`] will *not* work
354-
/// for this payment.
350+
/// Because the payment failed outright, no payment tracking is done and no
351+
/// [`Event::PaymentPathFailed`] or [`Event::PaymentFailed`] events will be generated.
355352
///
356-
/// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
357-
/// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
353+
/// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
354+
/// [`Event::PaymentFailed`]: crate::util::events::Event::PaymentFailed
358355
AllFailedResendSafe(Vec<APIError>),
359356
/// Indicates that a payment for the provided [`PaymentId`] is already in-flight and has not
360-
/// yet completed (i.e. generated an [`Event::PaymentSent`]) or been abandoned (via
361-
/// [`ChannelManager::abandon_payment`]).
357+
/// yet completed (i.e. generated an [`Event::PaymentSent`] or [`Event::PaymentFailed`]).
362358
///
363359
/// [`PaymentId`]: crate::ln::channelmanager::PaymentId
364360
/// [`Event::PaymentSent`]: crate::util::events::Event::PaymentSent
365-
/// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
361+
/// [`Event::PaymentFailed`]: crate::util::events::Event::PaymentFailed
366362
DuplicatePayment,
367363
/// Some paths which were attempted failed to send, though possibly not all. At least some
368-
/// paths have irrevocably committed to the HTLC and retrying the payment in full would result
369-
/// in over-/re-payment.
364+
/// paths have irrevocably committed to the HTLC.
370365
///
371366
/// The results here are ordered the same as the paths in the route object which was passed to
372-
/// send_payment, and any `Err`s which are not [`APIError::MonitorUpdateInProgress`] can be
373-
/// safely retried via [`ChannelManager::retry_payment`].
367+
/// send_payment.
374368
///
375-
/// Any entries which contain `Err(APIError::MonitorUpdateInprogress)` or `Ok(())` MUST NOT be
376-
/// retried as they will result in over-/re-payment. These HTLCs all either successfully sent
377-
/// (in the case of `Ok(())`) or will send once a [`MonitorEvent::Completed`] is provided for
378-
/// the next-hop channel with the latest update_id.
369+
/// Any entries which contain `Err(APIError::MonitorUpdateInprogress)` will send once a
370+
/// [`MonitorEvent::Completed`] is provided for the next-hop channel with the latest update_id.
379371
///
380-
/// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
381372
/// [`MonitorEvent::Completed`]: crate::chain::channelmonitor::MonitorEvent::Completed
382373
PartialFailure {
383-
/// The errors themselves, in the same order as the route hops.
374+
/// The errors themselves, in the same order as the paths from the route.
384375
results: Vec<Result<(), APIError>>,
385376
/// If some paths failed without irrevocably committing to the new HTLC(s), this will
386-
/// contain a [`RouteParameters`] object which can be used to calculate a new route that
387-
/// will pay all remaining unpaid balance.
377+
/// contain a [`RouteParameters`] object for the failing paths.
388378
failed_paths_retry: Option<RouteParameters>,
389379
/// The payment id for the payment, which is now at least partially pending.
390380
payment_id: PaymentId,
@@ -899,8 +889,8 @@ impl OutboundPayments {
899889
.map_err(|e| { self.remove_outbound_if_all_failed(payment_id, &e); e })
900890
}
901891

902-
// If we failed to send any paths, we should remove the new PaymentId from the
903-
// `pending_outbound_payments` map, as the user isn't expected to `abandon_payment`.
892+
// If we failed to send any paths, remove the new PaymentId from the `pending_outbound_payments`
893+
// map as the payment is free to be resent.
904894
fn remove_outbound_if_all_failed(&self, payment_id: PaymentId, err: &PaymentSendFailure) {
905895
if let &PaymentSendFailure::AllFailedResendSafe(_) = err {
906896
let removed = self.pending_outbound_payments.lock().unwrap().remove(&payment_id).is_some();

lightning/src/ln/payment_tests.rs

+12-52
Original file line numberDiff line numberDiff line change
@@ -237,55 +237,6 @@ fn mpp_receive_timeout() {
237237
do_mpp_receive_timeout(false);
238238
}
239239

240-
#[test]
241-
fn retry_expired_payment() {
242-
let chanmon_cfgs = create_chanmon_cfgs(3);
243-
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
244-
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]);
245-
let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs);
246-
247-
let _chan_0 = create_announced_chan_between_nodes(&nodes, 0, 1);
248-
let chan_1 = create_announced_chan_between_nodes(&nodes, 2, 1);
249-
// Rebalance to find a route
250-
send_payment(&nodes[2], &vec!(&nodes[1])[..], 3_000_000);
251-
252-
let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], 100_000);
253-
254-
// Rebalance so that the first hop fails.
255-
send_payment(&nodes[1], &vec!(&nodes[2])[..], 2_000_000);
256-
257-
// Make sure the payment fails on the first hop.
258-
nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), PaymentId(payment_hash.0)).unwrap();
259-
check_added_monitors!(nodes[0], 1);
260-
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
261-
assert_eq!(events.len(), 1);
262-
let mut payment_event = SendEvent::from_event(events.pop().unwrap());
263-
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
264-
check_added_monitors!(nodes[1], 0);
265-
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
266-
expect_pending_htlcs_forwardable!(nodes[1]);
267-
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(&nodes[1], vec![HTLCDestination::NextHopChannel { node_id: Some(nodes[2].node.get_our_node_id()), channel_id: chan_1.2 }]);
268-
let htlc_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
269-
assert!(htlc_updates.update_add_htlcs.is_empty());
270-
assert_eq!(htlc_updates.update_fail_htlcs.len(), 1);
271-
assert!(htlc_updates.update_fulfill_htlcs.is_empty());
272-
assert!(htlc_updates.update_fail_malformed_htlcs.is_empty());
273-
check_added_monitors!(nodes[1], 1);
274-
nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &htlc_updates.update_fail_htlcs[0]);
275-
commitment_signed_dance!(nodes[0], nodes[1], htlc_updates.commitment_signed, false);
276-
expect_payment_failed!(nodes[0], payment_hash, false);
277-
278-
// Mine blocks so the payment will have expired.
279-
connect_blocks(&nodes[0], 3);
280-
281-
// Retry the payment and make sure it errors as expected.
282-
if let Err(PaymentSendFailure::ParameterError(APIError::APIMisuseError { err })) = nodes[0].node.retry_payment(&route, PaymentId(payment_hash.0)) {
283-
assert!(err.contains("not found"));
284-
} else {
285-
panic!("Unexpected error");
286-
}
287-
}
288-
289240
#[test]
290241
fn no_pending_leak_on_initial_send_failure() {
291242
// In an earlier version of our payment tracking, we'd have a retry entry even when the initial
@@ -619,7 +570,10 @@ fn do_test_completed_payment_not_retryable_on_reload(use_dust: bool) {
619570
// If we attempt to retry prior to the HTLC-Timeout (or commitment transaction, for dust HTLCs)
620571
// confirming, we will fail as it's considered still-pending...
621572
let (new_route, _, _, _) = get_route_and_payment_hash!(nodes[0], nodes[2], if use_dust { 1_000 } else { 1_000_000 });
622-
assert!(nodes[0].node.retry_payment(&new_route, payment_id).is_err());
573+
match nodes[0].node.send_payment(&new_route, payment_hash, &Some(payment_secret), payment_id) {
574+
Err(PaymentSendFailure::DuplicatePayment) => {},
575+
_ => panic!("Unexpected error")
576+
}
623577
assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
624578

625579
// After ANTI_REORG_DELAY confirmations, the HTLC should be failed and we can try the payment
@@ -649,7 +603,10 @@ fn do_test_completed_payment_not_retryable_on_reload(use_dust: bool) {
649603
pass_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], if use_dust { 1_000 } else { 1_000_000 }, payment_hash, payment_secret);
650604
claim_payment(&nodes[0], &[&nodes[1], &nodes[2]], payment_preimage);
651605

652-
assert!(nodes[0].node.send_payment(&new_route, payment_hash, &Some(payment_secret), payment_id).is_err());
606+
match nodes[0].node.send_payment(&new_route, payment_hash, &Some(payment_secret), payment_id) {
607+
Err(PaymentSendFailure::DuplicatePayment) => {},
608+
_ => panic!("Unexpected error")
609+
}
653610
assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
654611

655612
let chan_0_monitor_serialized = get_monitor!(nodes[0], chan_id).encode();
@@ -663,7 +620,10 @@ fn do_test_completed_payment_not_retryable_on_reload(use_dust: bool) {
663620

664621
reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
665622

666-
assert!(nodes[0].node.retry_payment(&new_route, payment_id).is_err());
623+
match nodes[0].node.send_payment(&new_route, payment_hash, &Some(payment_secret), payment_id) {
624+
Err(PaymentSendFailure::DuplicatePayment) => {},
625+
_ => panic!("Unexpected error")
626+
}
667627
assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
668628
}
669629

lightning/src/routing/router.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl Readable for Route {
333333
/// Parameters needed to find a [`Route`].
334334
///
335335
/// Passed to [`find_route`] and [`build_route_from_hops`], but also provided in
336-
/// [`Event::PaymentPathFailed`] for retrying a failed payment path.
336+
/// [`Event::PaymentPathFailed`].
337337
///
338338
/// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
339339
#[derive(Clone, Debug, PartialEq, Eq)]

0 commit comments

Comments
 (0)