Skip to content

Commit bfaedff

Browse files
authored
Merge pull request #4674 from randomlogin/expose-fees-in-payment-details
Add fees value for recent payment details
2 parents f731548 + af19ed5 commit bfaedff

3 files changed

Lines changed: 32 additions & 6 deletions

File tree

lightning/src/ln/channelmanager.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3307,9 +3307,13 @@ pub enum RecentPaymentDetails {
33073307
/// Hash of the payment that is currently being sent but has yet to be fulfilled or
33083308
/// abandoned.
33093309
payment_hash: PaymentHash,
3310-
/// Total amount (in msat, excluding fees) across all paths for this payment,
3310+
/// Total amount (excluding fees) across all paths for this payment,
33113311
/// not just the amount currently inflight.
33123312
total_msat: u64,
3313+
/// Total routing fees of the HTLCs currently in-flight for this payment.
3314+
///
3315+
/// `None` for payments serialized by LDK versions prior to 0.0.103.
3316+
pending_fee_msat: Option<u64>,
33133317
/// Whether this payment is a liquidity probe.
33143318
is_probe: bool,
33153319
},
@@ -3326,6 +3330,13 @@ pub enum RecentPaymentDetails {
33263330
/// Hash of the payment that was claimed. `None` for serializations of [`ChannelManager`]
33273331
/// made before LDK version 0.0.104.
33283332
payment_hash: Option<PaymentHash>,
3333+
/// Total routing fees paid for this payment, as also reported via the `fee_paid_msat`
3334+
/// field of [`Event::PaymentSent`].
3335+
///
3336+
/// `None` for payments serialized by LDK versions prior to 0.3.0.
3337+
///
3338+
/// [`Event::PaymentSent`]: events::Event::PaymentSent
3339+
fee_paid_msat: Option<u64>,
33293340
},
33303341
/// After a payment's retries are exhausted per the provided [`Retry`], or it is explicitly
33313342
/// abandoned via [`ChannelManager::abandon_payment`], it is marked as abandoned until all
@@ -4134,12 +4145,13 @@ impl<
41344145
PendingOutboundPayment::StaticInvoiceReceived { .. } => {
41354146
Some(RecentPaymentDetails::AwaitingInvoice { payment_id: *payment_id })
41364147
},
4137-
PendingOutboundPayment::Retryable { payment_hash, total_msat, .. } => {
4148+
PendingOutboundPayment::Retryable { payment_hash, total_msat, pending_fee_msat, .. } => {
41384149
let is_probe = outbound_payment::payment_is_probe(payment_hash, payment_id, self.probing_cookie_secret);
41394150
Some(RecentPaymentDetails::Pending {
41404151
payment_id: *payment_id,
41414152
payment_hash: *payment_hash,
41424153
total_msat: *total_msat,
4154+
pending_fee_msat: *pending_fee_msat,
41434155
is_probe,
41444156
})
41454157
},
@@ -4151,8 +4163,12 @@ impl<
41514163
is_probe,
41524164
})
41534165
},
4154-
PendingOutboundPayment::Fulfilled { payment_hash, .. } => {
4155-
Some(RecentPaymentDetails::Fulfilled { payment_id: *payment_id, payment_hash: *payment_hash })
4166+
PendingOutboundPayment::Fulfilled { payment_hash, fee_paid_msat, .. } => {
4167+
Some(RecentPaymentDetails::Fulfilled {
4168+
payment_id: *payment_id,
4169+
payment_hash: *payment_hash,
4170+
fee_paid_msat: *fee_paid_msat,
4171+
})
41564172
},
41574173
PendingOutboundPayment::Legacy { .. } => None
41584174
})

lightning/src/ln/outbound_payment.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ pub(crate) enum PendingOutboundPayment {
152152
timer_ticks_without_htlcs: u8,
153153
/// The total payment amount across all paths, used to be able to issue `PaymentSent`.
154154
total_msat: Option<u64>,
155+
/// Total routing fees paid, as reported in `PaymentSent::fee_paid_msat`.
156+
fee_paid_msat: Option<u64>,
155157
},
156158
/// When we've decided to give up retrying a payment, we mark it as abandoned so we can eventually
157159
/// generate a `PaymentFailed` event when all HTLCs have irrevocably failed.
@@ -260,6 +262,7 @@ impl PendingOutboundPayment {
260262
match self {
261263
PendingOutboundPayment::Retryable { pending_fee_msat, .. } => pending_fee_msat.clone(),
262264
PendingOutboundPayment::Abandoned { pending_fee_msat, .. } => pending_fee_msat.clone(),
265+
PendingOutboundPayment::Fulfilled { fee_paid_msat, .. } => fee_paid_msat.clone(),
263266
_ => None,
264267
}
265268
}
@@ -302,7 +305,8 @@ impl PendingOutboundPayment {
302305
});
303306
let payment_hash = self.payment_hash();
304307
let total_msat = self.total_msat();
305-
*self = PendingOutboundPayment::Fulfilled { session_privs, payment_hash, timer_ticks_without_htlcs: 0, total_msat };
308+
let fee_paid_msat = self.get_pending_fee_msat();
309+
*self = PendingOutboundPayment::Fulfilled { session_privs, payment_hash, timer_ticks_without_htlcs: 0, total_msat, fee_paid_msat };
306310
}
307311

308312
#[rustfmt::skip]
@@ -2747,6 +2751,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
27472751
(1, payment_hash, option),
27482752
(3, timer_ticks_without_htlcs, (default_value, 0)),
27492753
(5, total_msat, option),
2754+
(7, fee_paid_msat, option),
27502755
},
27512756
(2, Retryable) => {
27522757
(0, session_privs, required),

lightning/src/ln/payment_tests.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2343,7 +2343,11 @@ fn test_trivial_inflight_htlc_tracking() {
23432343
}
23442344
let pending_payments = nodes[0].node.list_recent_payments();
23452345
assert_eq!(pending_payments.len(), 1);
2346-
let details = RecentPaymentDetails::Fulfilled { payment_hash: Some(payment_hash), payment_id };
2346+
let details = RecentPaymentDetails::Fulfilled {
2347+
payment_hash: Some(payment_hash),
2348+
payment_id,
2349+
fee_paid_msat: Some(1000),
2350+
};
23472351
assert_eq!(pending_payments[0], details);
23482352

23492353
// Remove fulfilled payment
@@ -2389,6 +2393,7 @@ fn test_trivial_inflight_htlc_tracking() {
23892393
payment_id,
23902394
payment_hash,
23912395
total_msat: 500000,
2396+
pending_fee_msat: Some(1000),
23922397
is_probe: false,
23932398
};
23942399
assert_eq!(pending_payments[0], details);

0 commit comments

Comments
 (0)