@@ -46,7 +46,7 @@ use crate::ln::chan_utils::{
46
46
HolderCommitmentTransaction, ChannelTransactionParameters,
47
47
CounterpartyChannelTransactionParameters, MAX_HTLCS,
48
48
get_commitment_transaction_number_obscure_factor,
49
- ClosingTransaction, commit_tx_fee_sat, per_outbound_htlc_counterparty_commit_tx_fee_msat,
49
+ ClosingTransaction, commit_tx_fee_sat,
50
50
};
51
51
use crate::ln::chan_utils;
52
52
use crate::ln::onion_utils::HTLCFailReason;
@@ -834,6 +834,10 @@ struct HTLCStats {
834
834
pending_inbound_htlcs_value_msat: u64,
835
835
pending_outbound_htlcs_value_msat: u64,
836
836
on_counterparty_tx_dust_exposure_msat: u64,
837
+ // If the counterparty sets a feerate on the channel in excess of our dust_exposure_limiting_feerate,
838
+ // this will be set to the dust exposure that would result from us adding an additional nondust outbound
839
+ // htlc on the counterparty's commitment transaction.
840
+ extra_nondust_htlc_on_counterparty_tx_dust_exposure_msat: Option<u64>,
837
841
on_holder_tx_dust_exposure_msat: u64,
838
842
outbound_holding_cell_msat: u64,
839
843
on_holder_tx_outbound_holding_cell_htlcs_count: u32, // dust HTLCs *non*-included
@@ -3705,27 +3709,21 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3705
3709
.or(self.pending_update_fee.map(|(fee, _)| fee))
3706
3710
.unwrap_or(self.feerate_per_kw)
3707
3711
.checked_sub(dust_exposure_limiting_feerate);
3708
- if let Some(excess_feerate) = excess_feerate_opt {
3709
- let on_counterparty_tx_nondust_htlcs =
3710
- on_counterparty_tx_accepted_nondust_htlcs + on_counterparty_tx_offered_nondust_htlcs;
3711
- on_counterparty_tx_dust_exposure_msat +=
3712
- commit_tx_fee_sat(excess_feerate, on_counterparty_tx_nondust_htlcs, &self.channel_type) * 1000;
3713
- if !self.channel_type.supports_anchors_zero_fee_htlc_tx() {
3714
- on_counterparty_tx_dust_exposure_msat +=
3715
- on_counterparty_tx_accepted_nondust_htlcs as u64 * htlc_success_tx_weight(&self.channel_type)
3716
- * excess_feerate as u64 / 1000;
3717
- on_counterparty_tx_dust_exposure_msat +=
3718
- on_counterparty_tx_offered_nondust_htlcs as u64 * htlc_timeout_tx_weight(&self.channel_type)
3719
- * excess_feerate as u64 / 1000;
3720
- }
3721
- }
3712
+ let extra_nondust_htlc_on_counterparty_tx_dust_exposure_msat = excess_feerate_opt.map(|excess_feerate| {
3713
+ let extra_htlc_dust_exposure = on_counterparty_tx_dust_exposure_msat
3714
+ + chan_utils::commit_and_htlc_tx_fees_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs + 1, on_counterparty_tx_offered_nondust_htlcs, &self.channel_type) * 1000;
3715
+ on_counterparty_tx_dust_exposure_msat
3716
+ += chan_utils::commit_and_htlc_tx_fees_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs, on_counterparty_tx_offered_nondust_htlcs, &self.channel_type) * 1000;
3717
+ extra_htlc_dust_exposure
3718
+ });
3722
3719
3723
3720
HTLCStats {
3724
3721
pending_inbound_htlcs: self.pending_inbound_htlcs.len(),
3725
3722
pending_outbound_htlcs,
3726
3723
pending_inbound_htlcs_value_msat,
3727
3724
pending_outbound_htlcs_value_msat,
3728
3725
on_counterparty_tx_dust_exposure_msat,
3726
+ extra_nondust_htlc_on_counterparty_tx_dust_exposure_msat,
3729
3727
on_holder_tx_dust_exposure_msat,
3730
3728
outbound_holding_cell_msat,
3731
3729
on_holder_tx_outbound_holding_cell_htlcs_count,
@@ -3930,13 +3928,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3930
3928
context.holder_dust_limit_satoshis + dust_buffer_feerate * htlc_timeout_tx_weight(context.get_channel_type()) / 1000)
3931
3929
};
3932
3930
3933
- let excess_feerate_opt = self.feerate_per_kw.checked_sub(dust_exposure_limiting_feerate);
3934
- if let Some(excess_feerate) = excess_feerate_opt {
3935
- let htlc_dust_exposure_msat =
3936
- per_outbound_htlc_counterparty_commit_tx_fee_msat(excess_feerate, &context.channel_type);
3937
- let nondust_htlc_counterparty_tx_dust_exposure =
3938
- htlc_stats.on_counterparty_tx_dust_exposure_msat.saturating_add(htlc_dust_exposure_msat);
3939
- if nondust_htlc_counterparty_tx_dust_exposure > max_dust_htlc_exposure_msat {
3931
+ if let Some(extra_htlc_dust_exposure) = htlc_stats.extra_nondust_htlc_on_counterparty_tx_dust_exposure_msat {
3932
+ if extra_htlc_dust_exposure > max_dust_htlc_exposure_msat {
3940
3933
// If adding an extra HTLC would put us over the dust limit in total fees, we cannot
3941
3934
// send any non-dust HTLCs.
3942
3935
available_capacity_msat = cmp::min(available_capacity_msat, htlc_success_dust_limit * 1000);
0 commit comments