Skip to content

Commit 1eb1c9e

Browse files
committed
Let TxBuilder set the HTLC dust limit
Channel now sorts dust and nondust HTLCs according to the dust limit set by `TxBuilder`. We also let `TxBuilder` set the total endogenous fees spent on a set of HTLC transactions via `htlc_txs_endogenous_fees_sat`. Both of these changes abstract the weight of HTLC transactions away from channel.
1 parent eac01d0 commit 1eb1c9e

File tree

3 files changed

+54
-101
lines changed

3 files changed

+54
-101
lines changed

lightning/src/ln/chan_utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ pub(crate) fn commit_tx_fee_sat(feerate_per_kw: u32, num_htlcs: usize, channel_t
236236
}
237237

238238
/// Returns the fees for success and timeout second stage HTLC transactions.
239-
pub(super) fn second_stage_tx_fees_sat(
239+
pub(crate) fn second_stage_tx_fees_sat(
240240
channel_type: &ChannelTypeFeatures, feerate_sat_per_1000_weight: u32,
241241
) -> (u64, u64) {
242242
if channel_type.supports_anchors_zero_fee_htlc_tx()
@@ -245,6 +245,7 @@ pub(super) fn second_stage_tx_fees_sat(
245245
(0, 0)
246246
} else {
247247
(
248+
// As required by the spec, round down
248249
feerate_sat_per_1000_weight as u64 * htlc_success_tx_weight(channel_type) / 1000,
249250
feerate_sat_per_1000_weight as u64 * htlc_timeout_tx_weight(channel_type) / 1000,
250251
)

lightning/src/ln/channel.rs

Lines changed: 21 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use crate::ln::chan_utils;
4141
#[cfg(splicing)]
4242
use crate::ln::chan_utils::FUNDING_TRANSACTION_WITNESS_WEIGHT;
4343
use crate::ln::chan_utils::{
44-
get_commitment_transaction_number_obscure_factor, max_htlcs, second_stage_tx_fees_sat,
44+
get_commitment_transaction_number_obscure_factor, max_htlcs,
4545
selected_commitment_sat_per_1000_weight, ChannelPublicKeys, ChannelTransactionParameters,
4646
ClosingTransaction, CommitmentTransaction, CounterpartyChannelTransactionParameters,
4747
CounterpartyCommitmentSecrets, HTLCOutputInCommitment, HolderCommitmentTransaction,
@@ -284,24 +284,6 @@ struct InboundHTLCOutput {
284284
state: InboundHTLCState,
285285
}
286286

287-
impl InboundHTLCOutput {
288-
fn is_dust(
289-
&self, local: bool, feerate_per_kw: u32, broadcaster_dust_limit_sat: u64,
290-
features: &ChannelTypeFeatures,
291-
) -> bool {
292-
let (htlc_success_tx_fee_sat, htlc_timeout_tx_fee_sat) =
293-
second_stage_tx_fees_sat(features, feerate_per_kw);
294-
295-
let htlc_tx_fee_sat = if !local {
296-
// This is an offered HTLC.
297-
htlc_timeout_tx_fee_sat
298-
} else {
299-
htlc_success_tx_fee_sat
300-
};
301-
self.amount_msat / 1000 < broadcaster_dust_limit_sat + htlc_tx_fee_sat
302-
}
303-
}
304-
305287
#[cfg_attr(test, derive(Clone, Debug, PartialEq))]
306288
enum OutboundHTLCState {
307289
/// Added by us and included in a commitment_signed (if we were AwaitingRemoteRevoke when we
@@ -427,24 +409,6 @@ struct OutboundHTLCOutput {
427409
send_timestamp: Option<Duration>,
428410
}
429411

430-
impl OutboundHTLCOutput {
431-
fn is_dust(
432-
&self, local: bool, feerate_per_kw: u32, broadcaster_dust_limit_sat: u64,
433-
features: &ChannelTypeFeatures,
434-
) -> bool {
435-
let (htlc_success_tx_fee_sat, htlc_timeout_tx_fee_sat) =
436-
second_stage_tx_fees_sat(features, feerate_per_kw);
437-
438-
let htlc_tx_fee_sat = if local {
439-
// This is an offered HTLC.
440-
htlc_timeout_tx_fee_sat
441-
} else {
442-
htlc_success_tx_fee_sat
443-
};
444-
self.amount_msat / 1000 < broadcaster_dust_limit_sat + htlc_tx_fee_sat
445-
}
446-
}
447-
448412
/// See AwaitingRemoteRevoke ChannelState for more info
449413
#[cfg_attr(test, derive(Clone, Debug, PartialEq))]
450414
enum HTLCUpdateAwaitingACK {
@@ -4358,11 +4322,8 @@ where
43584322
return Err(LocalHTLCFailureReason::DustLimitCounterparty)
43594323
}
43604324
let dust_buffer_feerate = self.get_dust_buffer_feerate(None);
4361-
let (htlc_success_tx_fee_sat, _) = second_stage_tx_fees_sat(
4362-
&funding.get_channel_type(), dust_buffer_feerate,
4363-
);
4364-
let exposure_dust_limit_success_sats = htlc_success_tx_fee_sat + self.holder_dust_limit_satoshis;
4365-
if msg.amount_msat / 1000 < exposure_dust_limit_success_sats {
4325+
let (exposure_dust_limit_success_sat, _) = SpecTxBuilder {}.htlc_success_timeout_dust_limits(dust_buffer_feerate, self.holder_dust_limit_satoshis, funding.get_channel_type());
4326+
if msg.amount_msat / 1000 < exposure_dust_limit_success_sat {
43664327
let on_holder_tx_dust_htlc_exposure_msat = htlc_stats.on_holder_tx_dust_exposure_msat;
43674328
if on_holder_tx_dust_htlc_exposure_msat > max_dust_htlc_exposure_msat {
43684329
log_info!(logger, "Cannot accept value that would put our exposure to dust HTLCs at {} over the limit {} on holder commitment tx",
@@ -4451,10 +4412,11 @@ where
44514412
let mut value_to_remote_claimed_msat = 0;
44524413

44534414
let feerate_per_kw = feerate_per_kw.unwrap_or_else(|| self.get_commitment_feerate(funding, generated_by_local));
4415+
let (dust_limit_success_sat, dust_limit_timeout_sat) = SpecTxBuilder {}.htlc_success_timeout_dust_limits(feerate_per_kw, broadcaster_dust_limit_sat, funding.get_channel_type());
44544416

44554417
for htlc in self.pending_inbound_htlcs.iter() {
44564418
if htlc.state.included_in_commitment(generated_by_local) {
4457-
if !htlc.is_dust(local, feerate_per_kw, broadcaster_dust_limit_sat, funding.get_channel_type()) {
4419+
if htlc.amount_msat >= if local { dust_limit_success_sat } else { dust_limit_timeout_sat } * 1000 {
44584420
nondust_htlc_count += 1;
44594421
}
44604422
remote_htlc_total_msat += htlc.amount_msat;
@@ -4467,7 +4429,7 @@ where
44674429

44684430
for htlc in self.pending_outbound_htlcs.iter() {
44694431
if htlc.state.included_in_commitment(generated_by_local) {
4470-
if !htlc.is_dust(local, feerate_per_kw, broadcaster_dust_limit_sat, funding.get_channel_type()) {
4432+
if htlc.amount_msat >= if local { dust_limit_timeout_sat } else { dust_limit_success_sat } * 1000 {
44714433
nondust_htlc_count += 1;
44724434
}
44734435
local_htlc_total_msat += htlc.amount_msat;
@@ -4693,10 +4655,9 @@ where
46934655
) -> HTLCStats {
46944656
let context = self;
46954657

4696-
let dust_buffer_feerate = self.get_dust_buffer_feerate(outbound_feerate_update);
4697-
let (htlc_success_tx_fee_sat, htlc_timeout_tx_fee_sat) = second_stage_tx_fees_sat(
4698-
funding.get_channel_type(), dust_buffer_feerate,
4699-
);
4658+
let dust_buffer_feerate = context.get_dust_buffer_feerate(outbound_feerate_update);
4659+
let (counterparty_dust_limit_success_sat, counterparty_dust_limit_timeout_sat) = SpecTxBuilder {}.htlc_success_timeout_dust_limits(dust_buffer_feerate, context.counterparty_dust_limit_satoshis, funding.get_channel_type());
4660+
let (holder_dust_limit_success_sat, holder_dust_limit_timeout_sat) = SpecTxBuilder {}.htlc_success_timeout_dust_limits(dust_buffer_feerate, context.holder_dust_limit_satoshis, funding.get_channel_type());
47004661

47014662
let mut on_holder_tx_dust_exposure_msat = 0;
47024663
let mut on_counterparty_tx_dust_exposure_msat = 0;
@@ -4707,8 +4668,6 @@ where
47074668
let mut pending_inbound_htlcs_value_msat = 0;
47084669

47094670
{
4710-
let counterparty_dust_limit_timeout_sat = htlc_timeout_tx_fee_sat + context.counterparty_dust_limit_satoshis;
4711-
let holder_dust_limit_success_sat = htlc_success_tx_fee_sat + context.holder_dust_limit_satoshis;
47124671
for htlc in context.pending_inbound_htlcs.iter() {
47134672
pending_inbound_htlcs_value_msat += htlc.amount_msat;
47144673
if htlc.amount_msat / 1000 < counterparty_dust_limit_timeout_sat {
@@ -4727,8 +4686,6 @@ where
47274686
let mut on_holder_tx_outbound_holding_cell_htlcs_count = 0;
47284687
let mut pending_outbound_htlcs = self.pending_outbound_htlcs.len();
47294688
{
4730-
let counterparty_dust_limit_success_sat = htlc_success_tx_fee_sat + context.counterparty_dust_limit_satoshis;
4731-
let holder_dust_limit_timeout_sat = htlc_timeout_tx_fee_sat + context.holder_dust_limit_satoshis;
47324689
for htlc in context.pending_outbound_htlcs.iter() {
47334690
pending_outbound_htlcs_value_msat += htlc.amount_msat;
47344691
if htlc.amount_msat / 1000 < counterparty_dust_limit_success_sat {
@@ -4775,10 +4732,10 @@ where
47754732

47764733
let extra_nondust_htlc_on_counterparty_tx_dust_exposure_msat = excess_feerate_opt.map(|excess_feerate| {
47774734
let extra_htlc_commit_tx_fee_sat = SpecTxBuilder {}.commit_tx_fee_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs + 1 + on_counterparty_tx_offered_nondust_htlcs, funding.get_channel_type());
4778-
let extra_htlc_htlc_tx_fees_sat = chan_utils::htlc_tx_fees_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs + 1, on_counterparty_tx_offered_nondust_htlcs, funding.get_channel_type());
4735+
let extra_htlc_htlc_tx_fees_sat = SpecTxBuilder {}.htlc_txs_endogenous_fees_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs + 1, on_counterparty_tx_offered_nondust_htlcs, funding.get_channel_type());
47794736

47804737
let commit_tx_fee_sat = SpecTxBuilder {}.commit_tx_fee_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs + on_counterparty_tx_offered_nondust_htlcs, funding.get_channel_type());
4781-
let htlc_tx_fees_sat = chan_utils::htlc_tx_fees_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs, on_counterparty_tx_offered_nondust_htlcs, funding.get_channel_type());
4738+
let htlc_tx_fees_sat = SpecTxBuilder {}.htlc_txs_endogenous_fees_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs, on_counterparty_tx_offered_nondust_htlcs, funding.get_channel_type());
47824739

47834740
let extra_htlc_dust_exposure = on_counterparty_tx_dust_exposure_msat + (extra_htlc_commit_tx_fee_sat + extra_htlc_htlc_tx_fees_sat) * 1000;
47844741
on_counterparty_tx_dust_exposure_msat += (commit_tx_fee_sat + htlc_tx_fees_sat) * 1000;
@@ -4829,10 +4786,7 @@ where
48294786
let mut inbound_details = Vec::new();
48304787

48314788
let dust_buffer_feerate = self.get_dust_buffer_feerate(None);
4832-
let (htlc_success_tx_fee_sat, _) = second_stage_tx_fees_sat(
4833-
funding.get_channel_type(), dust_buffer_feerate,
4834-
);
4835-
let holder_dust_limit_success_sat = htlc_success_tx_fee_sat + self.holder_dust_limit_satoshis;
4789+
let (holder_dust_limit_success_sat, _) = SpecTxBuilder {}.htlc_success_timeout_dust_limits(dust_buffer_feerate, self.holder_dust_limit_satoshis, funding.get_channel_type());
48364790
for htlc in self.pending_inbound_htlcs.iter() {
48374791
if let Some(state_details) = (&htlc.state).into() {
48384792
inbound_details.push(InboundHTLCDetails{
@@ -4854,10 +4808,7 @@ where
48544808
let mut outbound_details = Vec::new();
48554809

48564810
let dust_buffer_feerate = self.get_dust_buffer_feerate(None);
4857-
let (_, htlc_timeout_tx_fee_sat) = second_stage_tx_fees_sat(
4858-
funding.get_channel_type(), dust_buffer_feerate,
4859-
);
4860-
let holder_dust_limit_timeout_sat = htlc_timeout_tx_fee_sat + self.holder_dust_limit_satoshis;
4811+
let (_, holder_dust_limit_timeout_sat) = SpecTxBuilder {}.htlc_success_timeout_dust_limits(dust_buffer_feerate, self.holder_dust_limit_satoshis, funding.get_channel_type());
48614812
for htlc in self.pending_outbound_htlcs.iter() {
48624813
outbound_details.push(OutboundHTLCDetails{
48634814
htlc_id: Some(htlc.htlc_id),
@@ -4920,9 +4871,9 @@ where
49204871
funding.counterparty_selected_channel_reserve_satoshis.unwrap_or(0) * 1000);
49214872

49224873
let mut available_capacity_msat = outbound_capacity_msat;
4923-
let (real_htlc_success_tx_fee_sat, real_htlc_timeout_tx_fee_sat) = second_stage_tx_fees_sat(
4924-
funding.get_channel_type(), context.feerate_per_kw,
4925-
);
4874+
4875+
let (real_dust_limit_success_sat, _) = SpecTxBuilder {}.htlc_success_timeout_dust_limits(context.feerate_per_kw, context.counterparty_dust_limit_satoshis, funding.get_channel_type());
4876+
let (_, real_dust_limit_timeout_sat) = SpecTxBuilder {}.htlc_success_timeout_dust_limits(context.feerate_per_kw, context.holder_dust_limit_satoshis, funding.get_channel_type());
49264877

49274878
if funding.is_outbound() {
49284879
// We should mind channel commit tx fee when computing how much of the available capacity
@@ -4938,7 +4889,6 @@ where
49384889
Some(())
49394890
};
49404891

4941-
let real_dust_limit_timeout_sat = real_htlc_timeout_tx_fee_sat + context.holder_dust_limit_satoshis;
49424892
let htlc_above_dust = HTLCCandidate::new(real_dust_limit_timeout_sat * 1000, HTLCInitiator::LocalOffered);
49434893
let mut max_reserved_commit_tx_fee_msat = context.next_local_commit_tx_fee_msat(&funding, htlc_above_dust, fee_spike_buffer_htlc);
49444894
let htlc_dust = HTLCCandidate::new(real_dust_limit_timeout_sat * 1000 - 1, HTLCInitiator::LocalOffered);
@@ -4966,7 +4916,6 @@ where
49664916
} else {
49674917
// If the channel is inbound (i.e. counterparty pays the fee), we need to make sure
49684918
// sending a new HTLC won't reduce their balance below our reserve threshold.
4969-
let real_dust_limit_success_sat = real_htlc_success_tx_fee_sat + context.counterparty_dust_limit_satoshis;
49704919
let htlc_above_dust = HTLCCandidate::new(real_dust_limit_success_sat * 1000, HTLCInitiator::LocalOffered);
49714920
let max_reserved_commit_tx_fee_msat = context.next_remote_commit_tx_fee_msat(funding, Some(htlc_above_dust), None);
49724921

@@ -4988,12 +4937,9 @@ where
49884937
let mut dust_exposure_dust_limit_msat = 0;
49894938
let max_dust_htlc_exposure_msat = context.get_max_dust_htlc_exposure_msat(dust_exposure_limiting_feerate);
49904939

4991-
let dust_buffer_feerate = self.get_dust_buffer_feerate(None);
4992-
let (buffer_htlc_success_tx_fee_sat, buffer_htlc_timeout_tx_fee_sat) = second_stage_tx_fees_sat(
4993-
funding.get_channel_type(), dust_buffer_feerate,
4994-
);
4995-
let buffer_dust_limit_success_sat = buffer_htlc_success_tx_fee_sat + context.counterparty_dust_limit_satoshis;
4996-
let buffer_dust_limit_timeout_sat = buffer_htlc_timeout_tx_fee_sat + context.holder_dust_limit_satoshis;
4940+
let dust_buffer_feerate = context.get_dust_buffer_feerate(None);
4941+
let (buffer_dust_limit_success_sat, _) = SpecTxBuilder {}.htlc_success_timeout_dust_limits(dust_buffer_feerate, context.counterparty_dust_limit_satoshis, funding.get_channel_type());
4942+
let (_, buffer_dust_limit_timeout_sat) = SpecTxBuilder {}.htlc_success_timeout_dust_limits(dust_buffer_feerate, context.holder_dust_limit_satoshis, funding.get_channel_type());
49974943

49984944
if let Some(extra_htlc_dust_exposure) = htlc_stats.extra_nondust_htlc_on_counterparty_tx_dust_exposure_msat {
49994945
if extra_htlc_dust_exposure > max_dust_htlc_exposure_msat {
@@ -5065,11 +5011,7 @@ where
50655011
return 0;
50665012
}
50675013

5068-
let (htlc_success_tx_fee_sat, htlc_timeout_tx_fee_sat) = second_stage_tx_fees_sat(
5069-
funding.get_channel_type(), context.feerate_per_kw,
5070-
);
5071-
let real_dust_limit_success_sat = htlc_success_tx_fee_sat + context.holder_dust_limit_satoshis;
5072-
let real_dust_limit_timeout_sat = htlc_timeout_tx_fee_sat + context.holder_dust_limit_satoshis;
5014+
let (real_dust_limit_success_sat, real_dust_limit_timeout_sat) = SpecTxBuilder {}.htlc_success_timeout_dust_limits(context.feerate_per_kw, context.holder_dust_limit_satoshis, funding.get_channel_type());
50735015

50745016
let mut addl_htlcs = 0;
50755017
if fee_spike_buffer_htlc.is_some() { addl_htlcs += 1; }
@@ -5177,11 +5119,7 @@ where
51775119

51785120
debug_assert!(htlc.is_some() || fee_spike_buffer_htlc.is_some(), "At least one of the options must be set");
51795121

5180-
let (htlc_success_tx_fee_sat, htlc_timeout_tx_fee_sat) = second_stage_tx_fees_sat(
5181-
funding.get_channel_type(), context.feerate_per_kw,
5182-
);
5183-
let real_dust_limit_success_sat = htlc_success_tx_fee_sat + context.counterparty_dust_limit_satoshis;
5184-
let real_dust_limit_timeout_sat = htlc_timeout_tx_fee_sat + context.counterparty_dust_limit_satoshis;
5122+
let (real_dust_limit_success_sat, real_dust_limit_timeout_sat) = SpecTxBuilder {}.htlc_success_timeout_dust_limits(context.feerate_per_kw, context.counterparty_dust_limit_satoshis, funding.get_channel_type());
51855123

51865124
let mut addl_htlcs = 0;
51875125
if fee_spike_buffer_htlc.is_some() { addl_htlcs += 1; }

lightning/src/sign/tx_builder.rs

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,26 @@ use core::ops::Deref;
55
use bitcoin::secp256k1::{self, PublicKey, Secp256k1};
66

77
use crate::ln::chan_utils::{
8-
commit_tx_fee_sat, htlc_success_tx_weight, htlc_timeout_tx_weight,
9-
ChannelTransactionParameters, CommitmentTransaction, HTLCOutputInCommitment,
8+
commit_tx_fee_sat, htlc_tx_fees_sat, second_stage_tx_fees_sat, ChannelTransactionParameters,
9+
CommitmentTransaction, HTLCOutputInCommitment,
1010
};
1111
use crate::ln::channel::{CommitmentStats, ANCHOR_OUTPUT_VALUE_SATOSHI};
1212
use crate::prelude::*;
1313
use crate::types::features::ChannelTypeFeatures;
1414
use crate::util::logger::Logger;
1515

1616
pub(crate) trait TxBuilder {
17+
fn htlc_success_timeout_dust_limits(
18+
&self, feerate_per_kw: u32, broadcaster_dust_limit_sat: u64,
19+
channel_type: &ChannelTypeFeatures,
20+
) -> (u64, u64);
1721
fn commit_tx_fee_sat(
1822
&self, feerate_per_kw: u32, nondust_htlc_count: usize, channel_type: &ChannelTypeFeatures,
1923
) -> u64;
24+
fn htlc_txs_endogenous_fees_sat(
25+
&self, feerate_per_kw: u32, num_accepted_htlcs: usize, num_offered_htlcs: usize,
26+
channel_type_features: &ChannelTypeFeatures,
27+
) -> u64;
2028
fn subtract_non_htlc_outputs(
2129
&self, is_outbound_from_holder: bool, value_to_self_after_htlcs: u64,
2230
value_to_remote_after_htlcs: u64, channel_type: &ChannelTypeFeatures,
@@ -34,11 +42,28 @@ pub(crate) trait TxBuilder {
3442
pub(crate) struct SpecTxBuilder {}
3543

3644
impl TxBuilder for SpecTxBuilder {
45+
fn htlc_success_timeout_dust_limits(
46+
&self, feerate_per_kw: u32, broadcaster_dust_limit_sat: u64,
47+
channel_type: &ChannelTypeFeatures,
48+
) -> (u64, u64) {
49+
let (htlc_success_tx_fee_sat, htlc_timeout_tx_fee_sat) =
50+
second_stage_tx_fees_sat(channel_type, feerate_per_kw);
51+
(
52+
broadcaster_dust_limit_sat + htlc_success_tx_fee_sat,
53+
broadcaster_dust_limit_sat + htlc_timeout_tx_fee_sat,
54+
)
55+
}
3756
fn commit_tx_fee_sat(
3857
&self, feerate_per_kw: u32, nondust_htlc_count: usize, channel_type: &ChannelTypeFeatures,
3958
) -> u64 {
4059
commit_tx_fee_sat(feerate_per_kw, nondust_htlc_count, channel_type)
4160
}
61+
fn htlc_txs_endogenous_fees_sat(
62+
&self, feerate_per_kw: u32, num_accepted_htlcs: usize, num_offered_htlcs: usize,
63+
channel_type: &ChannelTypeFeatures,
64+
) -> u64 {
65+
htlc_tx_fees_sat(feerate_per_kw, num_accepted_htlcs, num_offered_htlcs, channel_type)
66+
}
4267
fn subtract_non_htlc_outputs(
4368
&self, is_outbound_from_holder: bool, value_to_self_after_htlcs: u64,
4469
value_to_remote_after_htlcs: u64, channel_type: &ChannelTypeFeatures,
@@ -81,21 +106,10 @@ impl TxBuilder for SpecTxBuilder {
81106
{
82107
let mut local_htlc_total_msat = 0;
83108
let mut remote_htlc_total_msat = 0;
84-
let channel_type = &channel_parameters.channel_type_features;
85109

86-
let is_dust = |offered: bool, amount_msat: u64| -> bool {
87-
let htlc_tx_fee_sat = if channel_type.supports_anchors_zero_fee_htlc_tx() {
88-
0
89-
} else {
90-
let htlc_tx_weight = if offered {
91-
htlc_timeout_tx_weight(channel_type)
92-
} else {
93-
htlc_success_tx_weight(channel_type)
94-
};
95-
// As required by the spec, round down
96-
feerate_per_kw as u64 * htlc_tx_weight / 1000
97-
};
98-
amount_msat / 1000 < broadcaster_dust_limit_sat + htlc_tx_fee_sat
110+
let (dust_limit_success_sat, dust_limit_timeout_sat) = self.htlc_success_timeout_dust_limits(feerate_per_kw, broadcaster_dust_limit_sat, &channel_parameters.channel_type_features);
111+
let is_dust = |htlc: &HTLCOutputInCommitment| -> bool {
112+
htlc.amount_msat / 1000 < if htlc.offered { dust_limit_timeout_sat } else { dust_limit_success_sat }
99113
};
100114

101115
// Trim dust htlcs
@@ -106,7 +120,7 @@ impl TxBuilder for SpecTxBuilder {
106120
} else {
107121
remote_htlc_total_msat += htlc.amount_msat;
108122
}
109-
if is_dust(htlc.offered, htlc.amount_msat) {
123+
if is_dust(htlc) {
110124
log_trace!(logger, " ...trimming {} HTLC with value {}sat, hash {}, due to dust limit {}", if htlc.offered == local { "outbound" } else { "inbound" }, htlc.amount_msat / 1000, htlc.payment_hash, broadcaster_dust_limit_sat);
111125
false
112126
} else {

0 commit comments

Comments
 (0)