@@ -485,6 +485,7 @@ impl PendingOutboundPayment {
485
485
_ => false ,
486
486
}
487
487
}
488
+
488
489
fn abandoned ( & self ) -> bool {
489
490
match self {
490
491
PendingOutboundPayment :: Abandoned { .. } => true ,
@@ -1203,6 +1204,36 @@ impl ChannelDetails {
1203
1204
}
1204
1205
}
1205
1206
1207
+ /// We store payments that are pending resolution as `PendingOutboundPayment` in `ChannelManager`,
1208
+ /// and they can take on either one of the following states as defined in this enum.
1209
+ #[ derive( Debug , PartialEq ) ]
1210
+ pub enum PendingPaymentStatus {
1211
+ /// When a payment is still being sent and awaiting successful delivery.
1212
+ Retryable ,
1213
+ /// When a pending payment is fulfilled, we continue tracking it until all pending HTLCs have
1214
+ /// been resolved. This ensures we don't look up pending payments in ChannelMonitors on restart
1215
+ /// and add a pending payment that was already fulfilled.
1216
+ Fulfilled ,
1217
+ /// When a payer gives up trying to retry a payment, they inform us, letting us generate a
1218
+ /// `PaymentFailed` event when all HTLCs have irrevocably failed. This avoids a number of race
1219
+ /// conditions in MPP-aware payment retriers (1), where the possibility of multiple
1220
+ /// `PaymentPathFailed` events with `all_paths_failed` can be pending at once, confusing a
1221
+ /// downstream event handler as to when a payment has actually failed.
1222
+ ///
1223
+ /// (1) https://github.com/lightningdevkit/rust-lightning/issues/1164
1224
+ Abandoned ,
1225
+ }
1226
+
1227
+ /// Details of a pending payment, as returned by [`ChannelManager::list_pending_payments`].
1228
+ pub struct PendingPaymentDetails {
1229
+ /// Current status of a payment that is pending resolution.
1230
+ pub status : PendingPaymentStatus ,
1231
+ /// Total amount (in msat) across all paths for this payment, not just the amount currently
1232
+ /// inflight. This field is `None` if the payment's status is either
1233
+ /// `PendingPaymentStatus::Fulfilled` or `PendingPaymentPaymentStatus::Abandoned`.
1234
+ pub total_msat : Option < u64 > ,
1235
+ }
1236
+
1206
1237
/// If a payment fails to send, it can be in one of several states. This enum is returned as the
1207
1238
/// Err() type describing which state the payment is in, see the description of individual enum
1208
1239
/// states for more.
@@ -1770,6 +1801,24 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
1770
1801
self . list_channels_with_filter ( |& ( _, ref channel) | channel. is_live ( ) )
1771
1802
}
1772
1803
1804
+ /// Gets a list of payments in ramdom order that are currently pending resolution.
1805
+ pub fn list_pending_payments ( & self ) -> Vec < PendingPaymentDetails > {
1806
+ self . pending_outbound_payments . lock ( ) . unwrap ( ) . iter ( )
1807
+ . filter_map ( |( _, pending_outbound_payment) | match pending_outbound_payment {
1808
+ PendingOutboundPayment :: Retryable { total_msat, .. } => {
1809
+ Some ( PendingPaymentDetails { status : PendingPaymentStatus :: Retryable , total_msat : Some ( * total_msat) } )
1810
+ } ,
1811
+ PendingOutboundPayment :: Abandoned { .. } => {
1812
+ Some ( PendingPaymentDetails { status : PendingPaymentStatus :: Abandoned , total_msat : None } )
1813
+ } ,
1814
+ PendingOutboundPayment :: Fulfilled { .. } => {
1815
+ Some ( PendingPaymentDetails { status : PendingPaymentStatus :: Fulfilled , total_msat : None } )
1816
+ } ,
1817
+ PendingOutboundPayment :: Legacy { .. } => None
1818
+ } )
1819
+ . collect ( )
1820
+ }
1821
+
1773
1822
/// Helper function that issues the channel close events
1774
1823
fn issue_channel_close_events ( & self , channel : & Channel < <K :: Target as KeysInterface >:: Signer > , closure_reason : ClosureReason ) {
1775
1824
let mut pending_events_lock = self . pending_events . lock ( ) . unwrap ( ) ;
0 commit comments