Skip to content

Commit f8d9780

Browse files
Store our skimmed fee in PendingHTLCRouting
Receivers need to use this value to verify incoming payments if ChannelConfig::accept_underpaying_htlcs is set. This breaks compatibility with LDK versions prior to 0.0.116 due to the way the field is serialized in the outgoing Channel on forward.
1 parent ca3c3b5 commit f8d9780

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ pub(super) enum PendingHTLCRouting {
104104
/// The SCID from the onion that we should forward to. This could be a real SCID or a fake one
105105
/// generated using `get_fake_scid` from the scid_utils::fake_scid module.
106106
short_channel_id: u64, // This should be NonZero<u64> eventually when we bump MSRV
107+
/// The fee we're skimming off the top of this HTLC. See
108+
/// [`ChannelConfig::accept_underpaying_htlcs`].
109+
skimmed_fee_msat: Option<u64>,
107110
},
108111
Receive {
109112
payment_data: msgs::FinalOnionHopData,
@@ -2764,6 +2767,7 @@ where
27642767
routing: PendingHTLCRouting::Forward {
27652768
onion_packet: outgoing_packet,
27662769
short_channel_id,
2770+
skimmed_fee_msat: None,
27672771
},
27682772
payment_hash: msg.payment_hash.clone(),
27692773
incoming_shared_secret: shared_secret,
@@ -3402,8 +3406,16 @@ where
34023406
})?;
34033407

34043408
let routing = match payment.forward_info.routing {
3405-
PendingHTLCRouting::Forward { onion_packet, .. } => {
3406-
PendingHTLCRouting::Forward { onion_packet, short_channel_id: next_hop_scid }
3409+
PendingHTLCRouting::Forward { onion_packet, skimmed_fee_msat, .. } => {
3410+
debug_assert!(skimmed_fee_msat.is_none());
3411+
PendingHTLCRouting::Forward {
3412+
onion_packet,
3413+
short_channel_id: next_hop_scid,
3414+
skimmed_fee_msat:
3415+
// The minuend here must match the expected forward amount generated for the
3416+
// HTLCIntercepted event.
3417+
Some(payment.forward_info.outgoing_amt_msat.saturating_sub(amt_to_forward_msat)),
3418+
}
34073419
},
34083420
_ => unreachable!() // Only `PendingHTLCRouting::Forward`s are intercepted
34093421
};
@@ -7311,6 +7323,7 @@ impl_writeable_tlv_based!(PhantomRouteHints, {
73117323
impl_writeable_tlv_based_enum!(PendingHTLCRouting,
73127324
(0, Forward) => {
73137325
(0, onion_packet, required),
7326+
(1, skimmed_fee_msat, option),
73147327
(2, short_channel_id, required),
73157328
},
73167329
(1, Receive) => {

lightning/src/util/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ pub struct UserConfig {
636636
/// fake short channel ids generated via [`ChannelManager::get_intercept_scid`]. Upon HTLC
637637
/// intercept, LDK will generate an [`Event::HTLCIntercepted`] which MUST be handled by the user.
638638
///
639-
/// Setting this to true may break backwards compatibility with LDK versions < 0.0.113.
639+
/// Setting this to true may break backwards compatibility with LDK versions < 0.0.116.
640640
///
641641
/// Default value: false.
642642
///
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Backwards Compat
2+
3+
* Once upgraded, users with `UserConfig::accept_intercept_htlcs` set may not be able to downgrade to
4+
LDK versions prior to 0.0.116.

0 commit comments

Comments
 (0)