Skip to content

Commit 8631ab1

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.
1 parent 50c62dc commit 8631ab1

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
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,
@@ -2524,6 +2527,7 @@ where
25242527
routing: PendingHTLCRouting::Forward {
25252528
onion_packet: outgoing_packet,
25262529
short_channel_id,
2530+
skimmed_fee_msat: None,
25272531
},
25282532
payment_hash: msg.payment_hash.clone(),
25292533
incoming_shared_secret: shared_secret,
@@ -3275,8 +3279,16 @@ where
32753279
})?;
32763280

32773281
let routing = match payment.forward_info.routing {
3278-
PendingHTLCRouting::Forward { onion_packet, .. } => {
3279-
PendingHTLCRouting::Forward { onion_packet, short_channel_id: next_hop_scid }
3282+
PendingHTLCRouting::Forward { onion_packet, skimmed_fee_msat, .. } => {
3283+
debug_assert!(skimmed_fee_msat.is_none());
3284+
PendingHTLCRouting::Forward {
3285+
onion_packet,
3286+
short_channel_id: next_hop_scid,
3287+
skimmed_fee_msat:
3288+
// The minuend here must match the expected forward amount generated for the
3289+
// HTLCIntercepted event.
3290+
Some(payment.forward_info.outgoing_amt_msat.saturating_sub(amt_to_forward_msat)),
3291+
}
32803292
},
32813293
_ => unreachable!() // Only `PendingHTLCRouting::Forward`s are intercepted
32823294
};
@@ -7094,6 +7106,7 @@ impl_writeable_tlv_based!(PhantomRouteHints, {
70947106
impl_writeable_tlv_based_enum!(PendingHTLCRouting,
70957107
(0, Forward) => {
70967108
(0, onion_packet, required),
7109+
(1, skimmed_fee_msat, option),
70977110
(2, short_channel_id, required),
70987111
},
70997112
(1, Receive) => {

0 commit comments

Comments
 (0)