Skip to content

Commit af19ed5

Browse files
committed
Add fees value for recent payments
Introduce fields `pending_fee_msat` for `RecentPaymentDetails::Pending` and `fee_paid_msat` for `RecentPaymentDetails::Fulfilled`.
1 parent c9260ee commit af19ed5

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
@@ -3291,9 +3291,13 @@ pub enum RecentPaymentDetails {
32913291
/// Hash of the payment that is currently being sent but has yet to be fulfilled or
32923292
/// abandoned.
32933293
payment_hash: PaymentHash,
3294-
/// Total amount (in msat, excluding fees) across all paths for this payment,
3294+
/// Total amount (excluding fees) across all paths for this payment,
32953295
/// not just the amount currently inflight.
32963296
total_msat: u64,
3297+
/// Total routing fees of the HTLCs currently in-flight for this payment.
3298+
///
3299+
/// `None` for payments serialized by LDK versions prior to 0.0.103.
3300+
pending_fee_msat: Option<u64>,
32973301
/// Whether this payment is a liquidity probe.
32983302
is_probe: bool,
32993303
},
@@ -3310,6 +3314,13 @@ pub enum RecentPaymentDetails {
33103314
/// Hash of the payment that was claimed. `None` for serializations of [`ChannelManager`]
33113315
/// made before LDK version 0.0.104.
33123316
payment_hash: Option<PaymentHash>,
3317+
/// Total routing fees paid for this payment, as also reported via the `fee_paid_msat`
3318+
/// field of [`Event::PaymentSent`].
3319+
///
3320+
/// `None` for payments serialized by LDK versions prior to 0.3.0.
3321+
///
3322+
/// [`Event::PaymentSent`]: events::Event::PaymentSent
3323+
fee_paid_msat: Option<u64>,
33133324
},
33143325
/// After a payment's retries are exhausted per the provided [`Retry`], or it is explicitly
33153326
/// abandoned via [`ChannelManager::abandon_payment`], it is marked as abandoned until all
@@ -4118,12 +4129,13 @@ impl<
41184129
PendingOutboundPayment::StaticInvoiceReceived { .. } => {
41194130
Some(RecentPaymentDetails::AwaitingInvoice { payment_id: *payment_id })
41204131
},
4121-
PendingOutboundPayment::Retryable { payment_hash, total_msat, .. } => {
4132+
PendingOutboundPayment::Retryable { payment_hash, total_msat, pending_fee_msat, .. } => {
41224133
let is_probe = outbound_payment::payment_is_probe(payment_hash, payment_id, self.probing_cookie_secret);
41234134
Some(RecentPaymentDetails::Pending {
41244135
payment_id: *payment_id,
41254136
payment_hash: *payment_hash,
41264137
total_msat: *total_msat,
4138+
pending_fee_msat: *pending_fee_msat,
41274139
is_probe,
41284140
})
41294141
},
@@ -4135,8 +4147,12 @@ impl<
41354147
is_probe,
41364148
})
41374149
},
4138-
PendingOutboundPayment::Fulfilled { payment_hash, .. } => {
4139-
Some(RecentPaymentDetails::Fulfilled { payment_id: *payment_id, payment_hash: *payment_hash })
4150+
PendingOutboundPayment::Fulfilled { payment_hash, fee_paid_msat, .. } => {
4151+
Some(RecentPaymentDetails::Fulfilled {
4152+
payment_id: *payment_id,
4153+
payment_hash: *payment_hash,
4154+
fee_paid_msat: *fee_paid_msat,
4155+
})
41404156
},
41414157
PendingOutboundPayment::Legacy { .. } => None
41424158
})

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.
@@ -256,6 +258,7 @@ impl PendingOutboundPayment {
256258
match self {
257259
PendingOutboundPayment::Retryable { pending_fee_msat, .. } => pending_fee_msat.clone(),
258260
PendingOutboundPayment::Abandoned { pending_fee_msat, .. } => pending_fee_msat.clone(),
261+
PendingOutboundPayment::Fulfilled { fee_paid_msat, .. } => fee_paid_msat.clone(),
259262
_ => None,
260263
}
261264
}
@@ -298,7 +301,8 @@ impl PendingOutboundPayment {
298301
});
299302
let payment_hash = self.payment_hash();
300303
let total_msat = self.total_msat();
301-
*self = PendingOutboundPayment::Fulfilled { session_privs, payment_hash, timer_ticks_without_htlcs: 0, total_msat };
304+
let fee_paid_msat = self.get_pending_fee_msat();
305+
*self = PendingOutboundPayment::Fulfilled { session_privs, payment_hash, timer_ticks_without_htlcs: 0, total_msat, fee_paid_msat };
302306
}
303307

304308
#[rustfmt::skip]
@@ -2743,6 +2747,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
27432747
(1, payment_hash, option),
27442748
(3, timer_ticks_without_htlcs, (default_value, 0)),
27452749
(5, total_msat, option),
2750+
(7, fee_paid_msat, option),
27462751
},
27472752
(2, Retryable) => {
27482753
(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)