@@ -1154,6 +1154,36 @@ impl ChannelDetails {
1154
1154
}
1155
1155
}
1156
1156
1157
+ /// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
1158
+ /// These include payments that have yet to find a successful path, or have unresolved HTLCs.
1159
+ #[ derive( Debug , PartialEq ) ]
1160
+ pub enum RecentPaymentDetails {
1161
+ /// When a payment is still being sent and awaiting successful delivery.
1162
+ Pending {
1163
+ /// Hash of the payment that is currently being sent but has yet to be fulfilled or
1164
+ /// abandoned.
1165
+ payment_hash : PaymentHash ,
1166
+ /// Total amount (in msat, excluding fees) across all paths for this payment,
1167
+ /// not just the amount currently inflight.
1168
+ total_msat : u64 ,
1169
+ } ,
1170
+ /// When a pending payment is fulfilled, we continue tracking it until all pending HTLCs have
1171
+ /// been resolved. Upon receiving [`Event::PaymentSent`], we delay for a few minutes before the
1172
+ /// payment is removed from tracking.
1173
+ Fulfilled {
1174
+ /// Hash of the payment that was claimed. `None` for serializations of [`ChannelManager`]
1175
+ /// made before LDK version 0.0.104.
1176
+ payment_hash : Option < PaymentHash > ,
1177
+ } ,
1178
+ /// After a payment is explicitly abandoned by calling [`ChannelManager::abandon_payment`], it
1179
+ /// is marked as abandoned until an [`Event::PaymentFailed`] is generated. A payment could also
1180
+ /// be marked as abandoned if pathfinding fails repeatedly or retries have been exhausted.
1181
+ Abandoned {
1182
+ /// Hash of the payment that we have given up trying to send.
1183
+ payment_hash : PaymentHash ,
1184
+ } ,
1185
+ }
1186
+
1157
1187
/// Route hints used in constructing invoices for [phantom node payents].
1158
1188
///
1159
1189
/// [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
@@ -1691,6 +1721,34 @@ where
1691
1721
self . list_channels_with_filter ( |& ( _, ref channel) | channel. is_live ( ) )
1692
1722
}
1693
1723
1724
+ /// Returns in an undefined order recent payments that -- if not fulfilled -- have yet to find a
1725
+ /// successful path, or have unresolved HTLCs.
1726
+ ///
1727
+ /// This can be useful for payments that may have been prepared, but ultimately not sent, as a
1728
+ /// result of a crash. If such a payment exists, is not listed here, and an
1729
+ /// [`Event::PaymentSent`] has not been received, you may consider retrying the payment.
1730
+ ///
1731
+ /// [`Event::PaymentSent`]: events::Event::PaymentSent
1732
+ pub fn list_recent_payments ( & self ) -> Vec < RecentPaymentDetails > {
1733
+ self . pending_outbound_payments . pending_outbound_payments . lock ( ) . unwrap ( ) . iter ( )
1734
+ . filter_map ( |( _, pending_outbound_payment) | match pending_outbound_payment {
1735
+ PendingOutboundPayment :: Retryable { payment_hash, total_msat, .. } => {
1736
+ Some ( RecentPaymentDetails :: Pending {
1737
+ payment_hash : * payment_hash,
1738
+ total_msat : * total_msat,
1739
+ } )
1740
+ } ,
1741
+ PendingOutboundPayment :: Abandoned { payment_hash, .. } => {
1742
+ Some ( RecentPaymentDetails :: Abandoned { payment_hash : * payment_hash } )
1743
+ } ,
1744
+ PendingOutboundPayment :: Fulfilled { payment_hash, .. } => {
1745
+ Some ( RecentPaymentDetails :: Fulfilled { payment_hash : * payment_hash } )
1746
+ } ,
1747
+ PendingOutboundPayment :: Legacy { .. } => None
1748
+ } )
1749
+ . collect ( )
1750
+ }
1751
+
1694
1752
/// Helper function that issues the channel close events
1695
1753
fn issue_channel_close_events ( & self , channel : & Channel < <SP :: Target as SignerProvider >:: Signer > , closure_reason : ClosureReason ) {
1696
1754
let mut pending_events_lock = self . pending_events . lock ( ) . unwrap ( ) ;
@@ -2415,9 +2473,14 @@ where
2415
2473
2416
2474
/// Sends a payment along a given route.
2417
2475
///
2418
- /// Value parameters are provided via the last hop in route, see documentation for RouteHop
2476
+ /// Value parameters are provided via the last hop in route, see documentation for [` RouteHop`]
2419
2477
/// fields for more info.
2420
2478
///
2479
+ /// May generate SendHTLCs message(s) event on success, which should be relayed (e.g. via
2480
+ /// [`PeerManager::process_events`]).
2481
+ ///
2482
+ /// # Avoiding Duplicate Payments
2483
+ ///
2421
2484
/// If a pending payment is currently in-flight with the same [`PaymentId`] provided, this
2422
2485
/// method will error with an [`APIError::InvalidRoute`]. Note, however, that once a payment
2423
2486
/// is no longer pending (either via [`ChannelManager::abandon_payment`], or handling of an
@@ -2430,12 +2493,16 @@ where
2430
2493
/// consider using the [`PaymentHash`] as the key for tracking payments. In that case, the
2431
2494
/// [`PaymentId`] should be a copy of the [`PaymentHash`] bytes.
2432
2495
///
2433
- /// May generate SendHTLCs message(s) event on success, which should be relayed (e.g. via
2434
- /// [`PeerManager::process_events`]).
2496
+ /// Additionally, in the scenario where we begin the process of sending a payment, but crash
2497
+ /// before `send_payment` returns (or prior to [`ChannelMonitorUpdate`] persistence if you're
2498
+ /// using [`ChannelMonitorUpdateStatus::InProgress`]), the payment may be lost on restart. See
2499
+ /// [`ChannelManager::list_recent_payments`] for more information.
2500
+ ///
2501
+ /// # Possible Error States on [`PaymentSendFailure`]
2435
2502
///
2436
2503
/// Each path may have a different return value, and PaymentSendValue may return a Vec with
2437
2504
/// each entry matching the corresponding-index entry in the route paths, see
2438
- /// PaymentSendFailure for more info.
2505
+ /// [` PaymentSendFailure`] for more info.
2439
2506
///
2440
2507
/// In general, a path may raise:
2441
2508
/// * [`APIError::InvalidRoute`] when an invalid route or forwarding parameter (cltv_delta, fee,
@@ -2450,18 +2517,21 @@ where
2450
2517
/// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
2451
2518
/// different route unless you intend to pay twice!
2452
2519
///
2453
- /// payment_secret is unrelated to payment_hash (or PaymentPreimage) and exists to authenticate
2454
- /// the sender to the recipient and prevent payment-probing (deanonymization) attacks. For
2455
- /// newer nodes, it will be provided to you in the invoice. If you do not have one, the Route
2456
- /// must not contain multiple paths as multi-path payments require a recipient-provided
2457
- /// payment_secret.
2520
+ /// # A caution on `payment_secret`
2521
+ ///
2522
+ /// `payment_secret` is unrelated to `payment_hash` (or [`PaymentPreimage`]) and exists to
2523
+ /// authenticate the sender to the recipient and prevent payment-probing (deanonymization)
2524
+ /// attacks. For newer nodes, it will be provided to you in the invoice. If you do not have one,
2525
+ /// the [`Route`] must not contain multiple paths as multi-path payments require a
2526
+ /// recipient-provided `payment_secret`.
2458
2527
///
2459
- /// If a payment_secret *is* provided, we assume that the invoice had the payment_secret feature
2460
- /// bit set (either as required or as available). If multiple paths are present in the Route,
2461
- /// we assume the invoice had the basic_mpp feature set.
2528
+ /// If a ` payment_secret` *is* provided, we assume that the invoice had the payment_secret
2529
+ /// feature bit set (either as required or as available). If multiple paths are present in the
2530
+ /// [`Route`], we assume the invoice had the basic_mpp feature set.
2462
2531
///
2463
2532
/// [`Event::PaymentSent`]: events::Event::PaymentSent
2464
2533
/// [`PeerManager::process_events`]: crate::ln::peer_handler::PeerManager::process_events
2534
+ /// [`ChannelMonitorUpdateStatus::InProgress`]: crate::chain::ChannelMonitorUpdateStatus::InProgress
2465
2535
pub fn send_payment ( & self , route : & Route , payment_hash : PaymentHash , payment_secret : & Option < PaymentSecret > , payment_id : PaymentId ) -> Result < ( ) , PaymentSendFailure > {
2466
2536
let best_block_height = self . best_block . read ( ) . unwrap ( ) . height ( ) ;
2467
2537
self . pending_outbound_payments
0 commit comments