Skip to content

Commit c248064

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 d4a1b0c commit c248064

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

lightning/src/ln/channel.rs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2971,8 +2971,13 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
29712971
// handling this case better and maybe fulfilling some of the HTLCs while attempting
29722972
// to rebalance channels.
29732973
match &htlc_update {
2974-
&HTLCUpdateAwaitingACK::AddHTLC {amount_msat, cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet, ..} => {
2975-
match self.send_htlc(amount_msat, *payment_hash, cltv_expiry, source.clone(), onion_routing_packet.clone(), false, logger) {
2974+
&HTLCUpdateAwaitingACK::AddHTLC {
2975+
amount_msat, cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet,
2976+
skimmed_fee_msat, ..
2977+
} => {
2978+
match self.send_htlc(amount_msat, *payment_hash, cltv_expiry, source.clone(),
2979+
onion_routing_packet.clone(), false, skimmed_fee_msat, logger)
2980+
{
29762981
Ok(update_add_msg_option) => update_add_htlcs.push(update_add_msg_option.unwrap()),
29772982
Err(e) => {
29782983
match e {
@@ -3614,7 +3619,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
36143619
payment_hash: htlc.payment_hash,
36153620
cltv_expiry: htlc.cltv_expiry,
36163621
onion_routing_packet: (**onion_packet).clone(),
3617-
skimmed_fee_msat: None,
3622+
skimmed_fee_msat: htlc.skimmed_fee_msat,
36183623
});
36193624
}
36203625
}
@@ -4962,11 +4967,13 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
49624967
/// commitment update.
49634968
///
49644969
/// `Err`s will only be [`ChannelError::Ignore`].
4965-
pub fn queue_add_htlc<L: Deref>(&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
4966-
onion_routing_packet: msgs::OnionPacket, logger: &L)
4967-
-> Result<(), ChannelError> where L::Target: Logger {
4970+
pub fn queue_add_htlc<L: Deref>(
4971+
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
4972+
onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>, logger: &L
4973+
) -> Result<(), ChannelError> where L::Target: Logger {
49684974
self
4969-
.send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, true, logger)
4975+
.send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, true,
4976+
skimmed_fee_msat, logger)
49704977
.map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
49714978
.map_err(|err| {
49724979
if let ChannelError::Ignore(_) = err { /* fine */ }
@@ -4991,9 +4998,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
49914998
/// on this [`Channel`] if `force_holding_cell` is false.
49924999
///
49935000
/// `Err`s will only be [`ChannelError::Ignore`].
4994-
fn send_htlc<L: Deref>(&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
4995-
onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool, logger: &L)
4996-
-> Result<Option<msgs::UpdateAddHTLC>, ChannelError> where L::Target: Logger {
5001+
fn send_htlc<L: Deref>(
5002+
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
5003+
onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
5004+
skimmed_fee_msat: Option<u64>, logger: &L
5005+
) -> Result<Option<msgs::UpdateAddHTLC>, ChannelError> where L::Target: Logger {
49975006
if (self.context.channel_state & (ChannelState::ChannelReady as u32 | BOTH_SIDES_SHUTDOWN_MASK)) != (ChannelState::ChannelReady as u32) {
49985007
return Err(ChannelError::Ignore("Cannot send HTLC until channel is fully established and we haven't started shutting down".to_owned()));
49995008
}
@@ -5045,7 +5054,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
50455054
cltv_expiry,
50465055
source,
50475056
onion_routing_packet,
5048-
skimmed_fee_msat: None,
5057+
skimmed_fee_msat,
50495058
});
50505059
return Ok(None);
50515060
}
@@ -5057,7 +5066,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
50575066
cltv_expiry,
50585067
state: OutboundHTLCState::LocalAnnounced(Box::new(onion_routing_packet.clone())),
50595068
source,
5060-
skimmed_fee_msat: None,
5069+
skimmed_fee_msat,
50615070
});
50625071

50635072
let res = msgs::UpdateAddHTLC {
@@ -5067,7 +5076,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
50675076
payment_hash,
50685077
cltv_expiry,
50695078
onion_routing_packet,
5070-
skimmed_fee_msat: None,
5079+
skimmed_fee_msat,
50715080
};
50725081
self.context.next_holder_htlc_id += 1;
50735082

@@ -5206,8 +5215,12 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
52065215
///
52075216
/// Shorthand for calling [`Self::send_htlc`] followed by a commitment update, see docs on
52085217
/// [`Self::send_htlc`] and [`Self::build_commitment_no_state_update`] for more info.
5209-
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 {
5210-
let send_res = self.send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, false, logger);
5218+
pub fn send_htlc_and_commit<L: Deref>(
5219+
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
5220+
onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>, logger: &L
5221+
) -> Result<Option<&ChannelMonitorUpdate>, ChannelError> where L::Target: Logger {
5222+
let send_res = self.send_htlc(amount_msat, payment_hash, cltv_expiry, source,
5223+
onion_routing_packet, false, skimmed_fee_msat, logger);
52115224
if let Err(e) = &send_res { if let ChannelError::Ignore(_) = e {} else { debug_assert!(false, "Sending cannot trigger channel failure"); } }
52125225
match send_res? {
52135226
Some(_) => {

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,7 +3029,7 @@ where
30293029
session_priv: session_priv.clone(),
30303030
first_hop_htlc_msat: htlc_msat,
30313031
payment_id,
3032-
}, onion_packet, &self.logger);
3032+
}, onion_packet, None, &self.logger);
30333033
match break_chan_entry!(self, send_res, chan) {
30343034
Some(monitor_update) => {
30353035
let update_id = monitor_update.update_id;
@@ -3727,7 +3727,7 @@ where
37273727
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id: _,
37283728
forward_info: PendingHTLCInfo {
37293729
incoming_shared_secret, payment_hash, outgoing_amt_msat, outgoing_cltv_value,
3730-
routing: PendingHTLCRouting::Forward { onion_packet, .. }, ..
3730+
routing: PendingHTLCRouting::Forward { onion_packet, .. }, skimmed_fee_msat, ..
37313731
},
37323732
}) => {
37333733
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);
@@ -3741,7 +3741,7 @@ where
37413741
});
37423742
if let Err(e) = chan.get_mut().queue_add_htlc(outgoing_amt_msat,
37433743
payment_hash, outgoing_cltv_value, htlc_source.clone(),
3744-
onion_packet, &self.logger)
3744+
onion_packet, skimmed_fee_msat, &self.logger)
37453745
{
37463746
if let ChannelError::Ignore(msg) = e {
37473747
log_trace!(self.logger, "Failed to forward HTLC with payment_hash {}: {}", log_bytes!(payment_hash.0), msg);

0 commit comments

Comments
 (0)