Skip to content

Commit 329acbf

Browse files
Add PaymentClaimable::counterparty_skimmed_fee_msat
See its docs
1 parent 16cd529 commit 329acbf

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

lightning/src/events/mod.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,24 @@ pub enum Event {
387387
///
388388
/// Payments received on LDK versions prior to 0.0.115 will have this field unset.
389389
onion_fields: Option<RecipientOnionFields>,
390-
/// The value, in thousandths of a satoshi, that this payment is for.
390+
/// The value, in thousandths of a satoshi, that this payment is claimable for.
391+
///
392+
/// May be less than the invoice amount if [`ChannelConfig::accept_underpaying_htlcs`] is set
393+
/// and the previous hop took an extra fee.
394+
///
395+
/// # Note
396+
/// If [`ChannelConfig::accept_underpaying_htlcs`] is set and you claim without verifying this
397+
/// field, you may lose money!
398+
///
399+
/// [`ChannelConfig::accept_underpaying_htlcs`]: crate::util::config::ChannelConfig::accept_underpaying_htlcs
391400
amount_msat: u64,
401+
/// The value, in thousands of a satoshi, that was skimmed off of this payment as an extra fee
402+
/// taken by our channel counterparty.
403+
///
404+
/// Will always be 0 unless [`ChannelConfig::accept_underpaying_htlcs`] is set.
405+
///
406+
/// [`ChannelConfig::accept_underpaying_htlcs`]: crate::util::config::ChannelConfig::accept_underpaying_htlcs
407+
counterparty_skimmed_fee_msat: u64,
392408
/// Information for claiming this received payment, based on whether the purpose of the
393409
/// payment is to pay an invoice or to send a spontaneous payment.
394410
purpose: PaymentPurpose,
@@ -832,8 +848,8 @@ impl Writeable for Event {
832848
// We never write out FundingGenerationReady events as, upon disconnection, peers
833849
// drop any channels which have not yet exchanged funding_signed.
834850
},
835-
&Event::PaymentClaimable { ref payment_hash, ref amount_msat, ref purpose,
836-
ref receiver_node_id, ref via_channel_id, ref via_user_channel_id,
851+
&Event::PaymentClaimable { ref payment_hash, ref amount_msat, ref counterparty_skimmed_fee_msat,
852+
ref purpose, ref receiver_node_id, ref via_channel_id, ref via_user_channel_id,
837853
ref claim_deadline, ref onion_fields
838854
} => {
839855
1u8.write(writer)?;
@@ -859,6 +875,7 @@ impl Writeable for Event {
859875
(7, claim_deadline, option),
860876
(8, payment_preimage, option),
861877
(9, onion_fields, option),
878+
(11, counterparty_skimmed_fee_msat, required),
862879
});
863880
},
864881
&Event::PaymentSent { ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat } => {
@@ -1058,6 +1075,7 @@ impl MaybeReadable for Event {
10581075
let mut payment_preimage = None;
10591076
let mut payment_secret = None;
10601077
let mut amount_msat = 0;
1078+
let mut counterparty_skimmed_fee_msat_opt = None;
10611079
let mut receiver_node_id = None;
10621080
let mut _user_payment_id = None::<u64>; // For compatibility with 0.0.103 and earlier
10631081
let mut via_channel_id = None;
@@ -1075,6 +1093,7 @@ impl MaybeReadable for Event {
10751093
(7, claim_deadline, option),
10761094
(8, payment_preimage, option),
10771095
(9, onion_fields, option),
1096+
(11, counterparty_skimmed_fee_msat_opt, option),
10781097
});
10791098
let purpose = match payment_secret {
10801099
Some(secret) => PaymentPurpose::InvoicePayment {
@@ -1088,6 +1107,7 @@ impl MaybeReadable for Event {
10881107
receiver_node_id,
10891108
payment_hash,
10901109
amount_msat,
1110+
counterparty_skimmed_fee_msat: counterparty_skimmed_fee_msat_opt.unwrap_or(0),
10911111
purpose,
10921112
via_channel_id,
10931113
via_user_channel_id,

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3624,6 +3624,7 @@ where
36243624
payment_hash,
36253625
purpose: purpose(),
36263626
amount_msat,
3627+
counterparty_skimmed_fee_msat: total_value.saturating_sub(amount_msat),
36273628
via_channel_id: Some(prev_channel_id),
36283629
via_user_channel_id: Some(prev_user_channel_id),
36293630
claim_deadline: Some(earliest_expiry - HTLC_FAIL_BACK_BUFFER),
@@ -3693,6 +3694,7 @@ where
36933694
receiver_node_id: Some(receiver_node_id),
36943695
payment_hash,
36953696
amount_msat,
3697+
counterparty_skimmed_fee_msat: 0,
36963698
purpose,
36973699
via_channel_id: Some(prev_channel_id),
36983700
via_user_channel_id: Some(prev_user_channel_id),

lightning/src/ln/functional_test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2102,7 +2102,7 @@ pub fn do_pass_along_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_p
21022102
match &events_2[0] {
21032103
Event::PaymentClaimable { ref payment_hash, ref purpose, amount_msat,
21042104
receiver_node_id, ref via_channel_id, ref via_user_channel_id,
2105-
claim_deadline, onion_fields,
2105+
claim_deadline, onion_fields, ..
21062106
} => {
21072107
assert_eq!(our_payment_hash, *payment_hash);
21082108
assert_eq!(node.node.get_our_node_id(), receiver_node_id.unwrap());

lightning/src/util/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,8 @@ pub struct ChannelConfig {
414414
/// # Note
415415
/// It's important for payee wallet software to verify that [`PaymentClaimable::amount_msat`] is
416416
/// as-expected if this feature is activated, otherwise they may lose money!
417+
/// [`PaymentClaimable::counterparty_skimmed_fee_msat`] provides the fee taken by the
418+
/// counterparty.
417419
///
418420
/// # Note
419421
/// Switching on this config flag may break compatibility with versions of LDK prior to 0.0.116.
@@ -425,6 +427,7 @@ pub struct ChannelConfig {
425427
/// [`HTLCIntercepted`]: crate::events::Event::HTLCIntercepted
426428
/// [`HTLCIntercepted::expected_outbound_amount_msat`]: crate::events::Event::HTLCIntercepted::expected_outbound_amount_msat
427429
/// [`PaymentClaimable::amount_msat`]: crate::events::Event::PaymentClaimable::amount_msat
430+
/// [`PaymentClaimable::counterparty_skimmed_fee_msat`]: crate::events::Event::PaymentClaimable::counterparty_skimmed_fee_msat
428431
// TODO: link to bLIP when it's merged
429432
pub accept_underpaying_htlcs: bool,
430433
}

0 commit comments

Comments
 (0)