@@ -41,7 +41,7 @@ use crate::ln::chan_utils;
41
41
#[cfg(splicing)]
42
42
use crate::ln::chan_utils::FUNDING_TRANSACTION_WITNESS_WEIGHT;
43
43
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,
45
45
selected_commitment_sat_per_1000_weight, ChannelPublicKeys, ChannelTransactionParameters,
46
46
ClosingTransaction, CommitmentTransaction, CounterpartyChannelTransactionParameters,
47
47
CounterpartyCommitmentSecrets, HTLCOutputInCommitment, HolderCommitmentTransaction,
@@ -284,24 +284,6 @@ struct InboundHTLCOutput {
284
284
state: InboundHTLCState,
285
285
}
286
286
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
-
305
287
#[cfg_attr(test, derive(Clone, Debug, PartialEq))]
306
288
enum OutboundHTLCState {
307
289
/// Added by us and included in a commitment_signed (if we were AwaitingRemoteRevoke when we
@@ -427,24 +409,6 @@ struct OutboundHTLCOutput {
427
409
send_timestamp: Option<Duration>,
428
410
}
429
411
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
-
448
412
/// See AwaitingRemoteRevoke ChannelState for more info
449
413
#[cfg_attr(test, derive(Clone, Debug, PartialEq))]
450
414
enum HTLCUpdateAwaitingACK {
@@ -4358,11 +4322,8 @@ where
4358
4322
return Err(LocalHTLCFailureReason::DustLimitCounterparty)
4359
4323
}
4360
4324
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 {
4366
4327
let on_holder_tx_dust_htlc_exposure_msat = htlc_stats.on_holder_tx_dust_exposure_msat;
4367
4328
if on_holder_tx_dust_htlc_exposure_msat > max_dust_htlc_exposure_msat {
4368
4329
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
4451
4412
let mut value_to_remote_claimed_msat = 0;
4452
4413
4453
4414
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());
4454
4416
4455
4417
for htlc in self.pending_inbound_htlcs.iter() {
4456
4418
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 {
4458
4420
nondust_htlc_count += 1;
4459
4421
}
4460
4422
remote_htlc_total_msat += htlc.amount_msat;
@@ -4467,7 +4429,7 @@ where
4467
4429
4468
4430
for htlc in self.pending_outbound_htlcs.iter() {
4469
4431
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 {
4471
4433
nondust_htlc_count += 1;
4472
4434
}
4473
4435
local_htlc_total_msat += htlc.amount_msat;
@@ -4693,10 +4655,9 @@ where
4693
4655
) -> HTLCStats {
4694
4656
let context = self;
4695
4657
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());
4700
4661
4701
4662
let mut on_holder_tx_dust_exposure_msat = 0;
4702
4663
let mut on_counterparty_tx_dust_exposure_msat = 0;
@@ -4707,8 +4668,6 @@ where
4707
4668
let mut pending_inbound_htlcs_value_msat = 0;
4708
4669
4709
4670
{
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;
4712
4671
for htlc in context.pending_inbound_htlcs.iter() {
4713
4672
pending_inbound_htlcs_value_msat += htlc.amount_msat;
4714
4673
if htlc.amount_msat / 1000 < counterparty_dust_limit_timeout_sat {
@@ -4727,8 +4686,6 @@ where
4727
4686
let mut on_holder_tx_outbound_holding_cell_htlcs_count = 0;
4728
4687
let mut pending_outbound_htlcs = self.pending_outbound_htlcs.len();
4729
4688
{
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;
4732
4689
for htlc in context.pending_outbound_htlcs.iter() {
4733
4690
pending_outbound_htlcs_value_msat += htlc.amount_msat;
4734
4691
if htlc.amount_msat / 1000 < counterparty_dust_limit_success_sat {
@@ -4775,10 +4732,10 @@ where
4775
4732
4776
4733
let extra_nondust_htlc_on_counterparty_tx_dust_exposure_msat = excess_feerate_opt.map(|excess_feerate| {
4777
4734
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());
4779
4736
4780
4737
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());
4782
4739
4783
4740
let extra_htlc_dust_exposure = on_counterparty_tx_dust_exposure_msat + (extra_htlc_commit_tx_fee_sat + extra_htlc_htlc_tx_fees_sat) * 1000;
4784
4741
on_counterparty_tx_dust_exposure_msat += (commit_tx_fee_sat + htlc_tx_fees_sat) * 1000;
@@ -4829,10 +4786,7 @@ where
4829
4786
let mut inbound_details = Vec::new();
4830
4787
4831
4788
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());
4836
4790
for htlc in self.pending_inbound_htlcs.iter() {
4837
4791
if let Some(state_details) = (&htlc.state).into() {
4838
4792
inbound_details.push(InboundHTLCDetails{
@@ -4854,10 +4808,7 @@ where
4854
4808
let mut outbound_details = Vec::new();
4855
4809
4856
4810
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());
4861
4812
for htlc in self.pending_outbound_htlcs.iter() {
4862
4813
outbound_details.push(OutboundHTLCDetails{
4863
4814
htlc_id: Some(htlc.htlc_id),
@@ -4920,9 +4871,9 @@ where
4920
4871
funding.counterparty_selected_channel_reserve_satoshis.unwrap_or(0) * 1000);
4921
4872
4922
4873
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() );
4926
4877
4927
4878
if funding.is_outbound() {
4928
4879
// We should mind channel commit tx fee when computing how much of the available capacity
@@ -4938,7 +4889,6 @@ where
4938
4889
Some(())
4939
4890
};
4940
4891
4941
- let real_dust_limit_timeout_sat = real_htlc_timeout_tx_fee_sat + context.holder_dust_limit_satoshis;
4942
4892
let htlc_above_dust = HTLCCandidate::new(real_dust_limit_timeout_sat * 1000, HTLCInitiator::LocalOffered);
4943
4893
let mut max_reserved_commit_tx_fee_msat = context.next_local_commit_tx_fee_msat(&funding, htlc_above_dust, fee_spike_buffer_htlc);
4944
4894
let htlc_dust = HTLCCandidate::new(real_dust_limit_timeout_sat * 1000 - 1, HTLCInitiator::LocalOffered);
@@ -4966,7 +4916,6 @@ where
4966
4916
} else {
4967
4917
// If the channel is inbound (i.e. counterparty pays the fee), we need to make sure
4968
4918
// 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;
4970
4919
let htlc_above_dust = HTLCCandidate::new(real_dust_limit_success_sat * 1000, HTLCInitiator::LocalOffered);
4971
4920
let max_reserved_commit_tx_fee_msat = context.next_remote_commit_tx_fee_msat(funding, Some(htlc_above_dust), None);
4972
4921
@@ -4988,12 +4937,9 @@ where
4988
4937
let mut dust_exposure_dust_limit_msat = 0;
4989
4938
let max_dust_htlc_exposure_msat = context.get_max_dust_htlc_exposure_msat(dust_exposure_limiting_feerate);
4990
4939
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());
4997
4943
4998
4944
if let Some(extra_htlc_dust_exposure) = htlc_stats.extra_nondust_htlc_on_counterparty_tx_dust_exposure_msat {
4999
4945
if extra_htlc_dust_exposure > max_dust_htlc_exposure_msat {
@@ -5065,11 +5011,7 @@ where
5065
5011
return 0;
5066
5012
}
5067
5013
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());
5073
5015
5074
5016
let mut addl_htlcs = 0;
5075
5017
if fee_spike_buffer_htlc.is_some() { addl_htlcs += 1; }
@@ -5177,11 +5119,7 @@ where
5177
5119
5178
5120
debug_assert!(htlc.is_some() || fee_spike_buffer_htlc.is_some(), "At least one of the options must be set");
5179
5121
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());
5185
5123
5186
5124
let mut addl_htlcs = 0;
5187
5125
if fee_spike_buffer_htlc.is_some() { addl_htlcs += 1; }
0 commit comments