Skip to content

Commit fb0b1af

Browse files
committed
Resolve comments, make PendingPaymentDetails enum instead
1 parent aff6659 commit fb0b1af

File tree

2 files changed

+19
-30
lines changed

2 files changed

+19
-30
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,36 +1204,26 @@ impl ChannelDetails {
12041204
}
12051205
}
12061206

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.
1207+
/// Used to express the status of payments that are currently pending resolution.
12091208
#[derive(Debug, PartialEq)]
1210-
pub enum PendingPaymentStatus {
1209+
pub enum PendingPaymentDetails {
12111210
/// When a payment is still being sent and awaiting successful delivery.
1212-
Retryable,
1211+
Retryable {
1212+
/// Total amount (in msat) across all paths for this payment, not just the amount currently
1213+
/// inflight.
1214+
total_msat: u64
1215+
},
12131216
/// 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.
1217+
/// been resolved. These payments will only cease being tracked upon receiving or handling
1218+
/// [`Event::PaymentSent`].
12161219
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
1220+
/// After a payment is explicitly abandoned by calling [`ChannelManager::abandon_payment`], they
1221+
/// are marked as abandoned until an [`Event::PaymentFailed`] event is generated. A payment
1222+
/// could also be marked as abandoned if pathfinding fails repeatedly and we will no longer
1223+
/// retry sending.
12241224
Abandoned,
12251225
}
12261226

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-
12371227
/// If a payment fails to send, it can be in one of several states. This enum is returned as the
12381228
/// Err() type describing which state the payment is in, see the description of individual enum
12391229
/// states for more.
@@ -1806,13 +1796,13 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
18061796
self.pending_outbound_payments.lock().unwrap().iter()
18071797
.filter_map(|(_, pending_outbound_payment)| match pending_outbound_payment {
18081798
PendingOutboundPayment::Retryable { total_msat, .. } => {
1809-
Some(PendingPaymentDetails { status: PendingPaymentStatus::Retryable, total_msat: Some(*total_msat) })
1799+
Some(PendingPaymentDetails::Retryable { total_msat: *total_msat })
18101800
},
18111801
PendingOutboundPayment::Abandoned { .. } => {
1812-
Some(PendingPaymentDetails { status: PendingPaymentStatus::Abandoned, total_msat: None })
1802+
Some(PendingPaymentDetails::Abandoned)
18131803
},
18141804
PendingOutboundPayment::Fulfilled { .. } => {
1815-
Some(PendingPaymentDetails { status: PendingPaymentStatus::Fulfilled, total_msat: None })
1805+
Some(PendingPaymentDetails::Fulfilled)
18161806
},
18171807
PendingOutboundPayment::Legacy { .. } => None
18181808
})

lightning/src/ln/payment_tests.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::chain::channelmonitor::{ANTI_REORG_DELAY, LATENCY_GRACE_PERIOD_BLOCKS
1616
use crate::chain::transaction::OutPoint;
1717
use crate::chain::keysinterface::KeysInterface;
1818
use crate::ln::channel::EXPIRE_PREV_CONFIG_TICKS;
19-
use crate::ln::channelmanager::{self, BREAKDOWN_TIMEOUT, ChannelManager, MPP_TIMEOUT_TICKS, MIN_CLTV_EXPIRY_DELTA, PaymentId, PendingPaymentStatus, PaymentSendFailure, IDEMPOTENCY_TIMEOUT_TICKS};
19+
use crate::ln::channelmanager::{self, BREAKDOWN_TIMEOUT, ChannelManager, MPP_TIMEOUT_TICKS, MIN_CLTV_EXPIRY_DELTA, PaymentId, PaymentSendFailure, IDEMPOTENCY_TIMEOUT_TICKS, PendingPaymentDetails};
2020
use crate::ln::msgs;
2121
use crate::ln::msgs::ChannelMessageHandler;
2222
use crate::routing::router::{PaymentParameters, get_route};
@@ -1282,7 +1282,7 @@ fn test_trivial_inflight_htlc_tracking(){
12821282

12831283
let pending_payments = nodes[0].node.list_pending_payments();
12841284
assert_eq!(pending_payments.len(), 1);
1285-
assert_eq!(pending_payments[0].status, PendingPaymentStatus::Fulfilled);
1285+
assert_eq!(pending_payments[0], PendingPaymentDetails::Fulfilled);
12861286
}
12871287

12881288
// Remove fulfilled payment
@@ -1317,8 +1317,7 @@ fn test_trivial_inflight_htlc_tracking(){
13171317

13181318
let pending_payments = nodes[0].node.list_pending_payments();
13191319
assert_eq!(pending_payments.len(), 1);
1320-
assert_eq!(pending_payments[0].status, PendingPaymentStatus::Retryable);
1321-
assert_eq!(pending_payments[0].total_msat, Some(500000));
1320+
assert_eq!(pending_payments[0], PendingPaymentDetails::Retryable { total_msat: 500000 });
13221321
}
13231322

13241323
// Now, let's claim the payment. This should result in the used liquidity to return `None`.

0 commit comments

Comments
 (0)