Skip to content

Commit 63dc52b

Browse files
Set extra skimmed fee on intercepted forward
Receivers need to use this value to verify incoming payments if ChannelConfig::accept_underpaying_htlcs is set.
1 parent 15dd475 commit 63dc52b

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ pub(super) struct PendingHTLCInfo {
131131
/// may overshoot this in either case)
132132
pub(super) outgoing_amt_msat: u64,
133133
pub(super) outgoing_cltv_value: u32,
134+
/// The fee being skimmed off the top of this HTLC. If this is a forward, it'll be the fee we are
135+
/// skimming. If we're receiving this HTLC, it's the fee that our counterparty skimmed.
136+
pub(super) skimmed_fee_msat: Option<u64>,
134137
}
135138

136139
#[derive(Clone)] // See Channel::revoke_and_ack for why, tl;dr: Rust bug
@@ -2616,6 +2619,7 @@ where
26162619
incoming_amt_msat: Some(amt_msat),
26172620
outgoing_amt_msat: hop_data.amt_to_forward,
26182621
outgoing_cltv_value: hop_data.outgoing_cltv_value,
2622+
skimmed_fee_msat: None,
26192623
})
26202624
}
26212625

@@ -2883,6 +2887,7 @@ where
28832887
incoming_amt_msat: Some(msg.amount_msat),
28842888
outgoing_amt_msat: next_hop_data.amt_to_forward,
28852889
outgoing_cltv_value: next_hop_data.outgoing_cltv_value,
2890+
skimmed_fee_msat: None,
28862891
})
28872892
}
28882893
}
@@ -3523,7 +3528,10 @@ where
35233528
},
35243529
_ => unreachable!() // Only `PendingHTLCRouting::Forward`s are intercepted
35253530
};
3531+
let skimmed_fee_msat =
3532+
payment.forward_info.outgoing_amt_msat.saturating_sub(amt_to_forward_msat);
35263533
let pending_htlc_info = PendingHTLCInfo {
3534+
skimmed_fee_msat: if skimmed_fee_msat == 0 { None } else { Some(skimmed_fee_msat) },
35273535
outgoing_amt_msat: amt_to_forward_msat, routing, ..payment.forward_info
35283536
};
35293537

@@ -3593,7 +3601,7 @@ where
35933601
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id,
35943602
forward_info: PendingHTLCInfo {
35953603
routing, incoming_shared_secret, payment_hash, outgoing_amt_msat,
3596-
outgoing_cltv_value, incoming_amt_msat: _
3604+
outgoing_cltv_value, ..
35973605
}
35983606
}) => {
35993607
macro_rules! failure_handler {
@@ -3706,7 +3714,7 @@ where
37063714
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id: _,
37073715
forward_info: PendingHTLCInfo {
37083716
incoming_shared_secret, payment_hash, outgoing_amt_msat, outgoing_cltv_value,
3709-
routing: PendingHTLCRouting::Forward { onion_packet, .. }, incoming_amt_msat: _,
3717+
routing: PendingHTLCRouting::Forward { onion_packet, .. }, ..
37103718
},
37113719
}) => {
37123720
log_trace!(self.logger, "Adding HTLC from short id {} with payment_hash {} to channel with short id {} after delay", prev_short_channel_id, log_bytes!(payment_hash.0), short_chan_id);
@@ -7441,6 +7449,7 @@ impl_writeable_tlv_based!(PendingHTLCInfo, {
74417449
(6, outgoing_amt_msat, required),
74427450
(8, outgoing_cltv_value, required),
74437451
(9, incoming_amt_msat, option),
7452+
(10, skimmed_fee_msat, option),
74447453
});
74457454

74467455

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Backwards Compat
2+
3+
* Forwarding less than the expected amount in `ChannelManager::forward_intercepted_htlc` may break
4+
compatibility with versions of LDK prior to 0.0.116

0 commit comments

Comments
 (0)