Skip to content

Commit 0b1f09d

Browse files
Set UpdateAddHTLC::skimmed_fee_msat on forward
So the receiver can verify it and approve underpaying HTLCs (see ChannelConfig::accept_underpaying_htlcs).
1 parent 8de9530 commit 0b1f09d

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

lightning/src/ln/channel.rs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3383,8 +3383,13 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
33833383
// handling this case better and maybe fulfilling some of the HTLCs while attempting
33843384
// to rebalance channels.
33853385
match &htlc_update {
3386-
&HTLCUpdateAwaitingACK::AddHTLC {amount_msat, cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet, ..} => {
3387-
match self.send_htlc(amount_msat, *payment_hash, cltv_expiry, source.clone(), onion_routing_packet.clone(), false, logger) {
3386+
&HTLCUpdateAwaitingACK::AddHTLC {
3387+
amount_msat, cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet,
3388+
skimmed_fee_msat, ..
3389+
} => {
3390+
match self.send_htlc(amount_msat, *payment_hash, cltv_expiry, source.clone(),
3391+
onion_routing_packet.clone(), false, skimmed_fee_msat, logger)
3392+
{
33883393
Ok(update_add_msg_option) => update_add_htlcs.push(update_add_msg_option.unwrap()),
33893394
Err(e) => {
33903395
match e {
@@ -4022,7 +4027,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
40224027
payment_hash: htlc.payment_hash,
40234028
cltv_expiry: htlc.cltv_expiry,
40244029
onion_routing_packet: (**onion_packet).clone(),
4025-
skimmed_fee_msat: None,
4030+
skimmed_fee_msat: htlc.skimmed_fee_msat,
40264031
});
40274032
}
40284033
}
@@ -5793,11 +5798,13 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
57935798
/// commitment update.
57945799
///
57955800
/// `Err`s will only be [`ChannelError::Ignore`].
5796-
pub fn queue_add_htlc<L: Deref>(&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
5797-
onion_routing_packet: msgs::OnionPacket, logger: &L)
5798-
-> Result<(), ChannelError> where L::Target: Logger {
5801+
pub fn queue_add_htlc<L: Deref>(
5802+
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
5803+
onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>, logger: &L
5804+
) -> Result<(), ChannelError> where L::Target: Logger {
57995805
self
5800-
.send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, true, logger)
5806+
.send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, true,
5807+
skimmed_fee_msat, logger)
58015808
.map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
58025809
.map_err(|err| {
58035810
if let ChannelError::Ignore(_) = err { /* fine */ }
@@ -5822,9 +5829,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
58225829
/// on this [`Channel`] if `force_holding_cell` is false.
58235830
///
58245831
/// `Err`s will only be [`ChannelError::Ignore`].
5825-
fn send_htlc<L: Deref>(&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
5826-
onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool, logger: &L)
5827-
-> Result<Option<msgs::UpdateAddHTLC>, ChannelError> where L::Target: Logger {
5832+
fn send_htlc<L: Deref>(
5833+
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
5834+
onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
5835+
skimmed_fee_msat: Option<u64>, logger: &L
5836+
) -> Result<Option<msgs::UpdateAddHTLC>, ChannelError> where L::Target: Logger {
58285837
if (self.channel_state & (ChannelState::ChannelReady as u32 | BOTH_SIDES_SHUTDOWN_MASK)) != (ChannelState::ChannelReady as u32) {
58295838
return Err(ChannelError::Ignore("Cannot send HTLC until channel is fully established and we haven't started shutting down".to_owned()));
58305839
}
@@ -5931,7 +5940,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
59315940
cltv_expiry,
59325941
source,
59335942
onion_routing_packet,
5934-
skimmed_fee_msat: None,
5943+
skimmed_fee_msat,
59355944
});
59365945
return Ok(None);
59375946
}
@@ -5943,7 +5952,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
59435952
cltv_expiry,
59445953
state: OutboundHTLCState::LocalAnnounced(Box::new(onion_routing_packet.clone())),
59455954
source,
5946-
skimmed_fee_msat: None,
5955+
skimmed_fee_msat,
59475956
});
59485957

59495958
let res = msgs::UpdateAddHTLC {
@@ -5953,7 +5962,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
59535962
payment_hash,
59545963
cltv_expiry,
59555964
onion_routing_packet,
5956-
skimmed_fee_msat: None,
5965+
skimmed_fee_msat,
59575966
};
59585967
self.next_holder_htlc_id += 1;
59595968

@@ -6092,8 +6101,12 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
60926101
///
60936102
/// Shorthand for calling [`Self::send_htlc`] followed by a commitment update, see docs on
60946103
/// [`Self::send_htlc`] and [`Self::build_commitment_no_state_update`] for more info.
6095-
pub fn send_htlc_and_commit<L: Deref>(&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource, onion_routing_packet: msgs::OnionPacket, logger: &L) -> Result<Option<&ChannelMonitorUpdate>, ChannelError> where L::Target: Logger {
6096-
let send_res = self.send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, false, logger);
6104+
pub fn send_htlc_and_commit<L: Deref>(
6105+
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
6106+
onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>, logger: &L
6107+
) -> Result<Option<&ChannelMonitorUpdate>, ChannelError> where L::Target: Logger {
6108+
let send_res = self.send_htlc(amount_msat, payment_hash, cltv_expiry, source,
6109+
onion_routing_packet, false, skimmed_fee_msat, logger);
60976110
if let Err(e) = &send_res { if let ChannelError::Ignore(_) = e {} else { debug_assert!(false, "Sending cannot trigger channel failure"); } }
60986111
match send_res? {
60996112
Some(_) => {

lightning/src/ln/channelmanager.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2802,7 +2802,7 @@ where
28022802
session_priv: session_priv.clone(),
28032803
first_hop_htlc_msat: htlc_msat,
28042804
payment_id,
2805-
}, onion_packet, &self.logger);
2805+
}, onion_packet, None, &self.logger);
28062806
match break_chan_entry!(self, send_res, chan) {
28072807
Some(monitor_update) => {
28082808
let update_id = monitor_update.update_id;
@@ -3479,7 +3479,9 @@ where
34793479
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id: _,
34803480
forward_info: PendingHTLCInfo {
34813481
incoming_shared_secret, payment_hash, outgoing_amt_msat, outgoing_cltv_value,
3482-
routing: PendingHTLCRouting::Forward { onion_packet, .. }, incoming_amt_msat: _,
3482+
routing: PendingHTLCRouting::Forward {
3483+
onion_packet, skimmed_fee_msat, ..
3484+
}, incoming_amt_msat: _,
34833485
},
34843486
}) => {
34853487
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);
@@ -3493,7 +3495,7 @@ where
34933495
});
34943496
if let Err(e) = chan.get_mut().queue_add_htlc(outgoing_amt_msat,
34953497
payment_hash, outgoing_cltv_value, htlc_source.clone(),
3496-
onion_packet, &self.logger)
3498+
onion_packet, skimmed_fee_msat, &self.logger)
34973499
{
34983500
if let ChannelError::Ignore(msg) = e {
34993501
log_trace!(self.logger, "Failed to forward HTLC with payment_hash {}: {}", log_bytes!(payment_hash.0), msg);

0 commit comments

Comments
 (0)