Skip to content

Commit

Permalink
Store our skimmed fee in PendingHTLCRouting
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
valentinewallace committed Jun 8, 2023
1 parent ca3c3b5 commit f8d9780
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
17 changes: 15 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ pub(super) enum PendingHTLCRouting {
/// The SCID from the onion that we should forward to. This could be a real SCID or a fake one
/// generated using `get_fake_scid` from the scid_utils::fake_scid module.
short_channel_id: u64, // This should be NonZero<u64> eventually when we bump MSRV
/// The fee we're skimming off the top of this HTLC. See
/// [`ChannelConfig::accept_underpaying_htlcs`].
skimmed_fee_msat: Option<u64>,
},
Receive {
payment_data: msgs::FinalOnionHopData,
Expand Down Expand Up @@ -2764,6 +2767,7 @@ where
routing: PendingHTLCRouting::Forward {
onion_packet: outgoing_packet,
short_channel_id,
skimmed_fee_msat: None,
},
payment_hash: msg.payment_hash.clone(),
incoming_shared_secret: shared_secret,
Expand Down Expand Up @@ -3402,8 +3406,16 @@ where
})?;

let routing = match payment.forward_info.routing {
PendingHTLCRouting::Forward { onion_packet, .. } => {
PendingHTLCRouting::Forward { onion_packet, short_channel_id: next_hop_scid }
PendingHTLCRouting::Forward { onion_packet, skimmed_fee_msat, .. } => {
debug_assert!(skimmed_fee_msat.is_none());
PendingHTLCRouting::Forward {
onion_packet,
short_channel_id: next_hop_scid,
skimmed_fee_msat:
// The minuend here must match the expected forward amount generated for the
// HTLCIntercepted event.
Some(payment.forward_info.outgoing_amt_msat.saturating_sub(amt_to_forward_msat)),
}
},
_ => unreachable!() // Only `PendingHTLCRouting::Forward`s are intercepted
};
Expand Down Expand Up @@ -7311,6 +7323,7 @@ impl_writeable_tlv_based!(PhantomRouteHints, {
impl_writeable_tlv_based_enum!(PendingHTLCRouting,
(0, Forward) => {
(0, onion_packet, required),
(1, skimmed_fee_msat, option),
(2, short_channel_id, required),
},
(1, Receive) => {
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ pub struct UserConfig {
/// fake short channel ids generated via [`ChannelManager::get_intercept_scid`]. Upon HTLC
/// intercept, LDK will generate an [`Event::HTLCIntercepted`] which MUST be handled by the user.
///
/// Setting this to true may break backwards compatibility with LDK versions < 0.0.113.
/// Setting this to true may break backwards compatibility with LDK versions < 0.0.116.
///
/// Default value: false.
///
Expand Down
4 changes: 4 additions & 0 deletions pending_changelog/forward-underpaying-htlc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Backwards Compat

* Once upgraded, users with `UserConfig::accept_intercept_htlcs` set may not be able to downgrade to
LDK versions prior to 0.0.116.

0 comments on commit f8d9780

Please sign in to comment.