Skip to content

Commit 489c6f6

Browse files
committed
ln: return Option for dust_exposure_limiting_feerate
This fee rate is currently used in two scenarios: - To count any fees above what we consider to be a sane estimate towards our dust exposure. - To get a maximum dust exposure (when using MaxDustHTLCExposure::FeeEstimator strategy). When we have zero fee commitments: - Commitments are zero fee, so we don't need to count fees towards dust exposure. - The amount of dust we have is not dependent on fees, as everything is zero fee. - We still want to limit our total dust exposure. This commit updates get_dust_exposure_limiting_feerate to allow a None value to prepare for support for zero fee commitments. This clearly allows us to indicate when we don't care about fee rates for dust considerations. In get_max_dust_htlc_exposure_msat, we simply hardcode a value of 1 sat/vbyte if a feerate dependent strategy is being used.
1 parent 1b70e6d commit 489c6f6

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

lightning/src/ln/channel.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3999,17 +3999,21 @@ where
39993999

40004000
fn get_dust_exposure_limiting_feerate<F: Deref>(
40014001
&self, fee_estimator: &LowerBoundedFeeEstimator<F>,
4002-
) -> u32
4002+
) -> Option<u32>
40034003
where
40044004
F::Target: FeeEstimator,
40054005
{
4006-
fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::MaximumFeeEstimate)
4006+
Some(fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::MaximumFeeEstimate))
40074007
}
40084008

4009-
pub fn get_max_dust_htlc_exposure_msat(&self, limiting_feerate_sat_per_kw: u32) -> u64 {
4009+
/// Returns the maximum configured dust exposure.
4010+
///
4011+
/// Uses a default of 1 sat/vbyte if `limiting_feerate_sat_per_kw` is `None` and the dust
4012+
/// exposure policy depends on fee rate.
4013+
pub fn get_max_dust_htlc_exposure_msat(&self, limiting_feerate_sat_per_kw: Option<u32>) -> u64 {
40104014
match self.config.options.max_dust_htlc_exposure {
40114015
MaxDustHTLCExposure::FeeRateMultiplier(multiplier) => {
4012-
(limiting_feerate_sat_per_kw as u64).saturating_mul(multiplier)
4016+
(limiting_feerate_sat_per_kw.unwrap_or(250) as u64).saturating_mul(multiplier)
40134017
},
40144018
MaxDustHTLCExposure::FixedLimitMsat(limit) => limit,
40154019
}
@@ -4356,7 +4360,7 @@ where
43564360
#[rustfmt::skip]
43574361
fn can_accept_incoming_htlc<L: Deref>(
43584362
&self, funding: &FundingScope, msg: &msgs::UpdateAddHTLC,
4359-
dust_exposure_limiting_feerate: u32, logger: &L,
4363+
dust_exposure_limiting_feerate: Option<u32>, logger: &L,
43604364
) -> Result<(), LocalHTLCFailureReason>
43614365
where
43624366
L::Target: Logger,
@@ -4696,7 +4700,7 @@ where
46964700
#[rustfmt::skip]
46974701
fn get_pending_htlc_stats(
46984702
&self, funding: &FundingScope, outbound_feerate_update: Option<u32>,
4699-
dust_exposure_limiting_feerate: u32,
4703+
dust_exposure_limiting_feerate: Option<u32>,
47004704
) -> HTLCStats {
47014705
let context = self;
47024706
let uses_0_htlc_fee_anchors = funding.get_channel_type().supports_anchors_zero_fee_htlc_tx();
@@ -4775,7 +4779,8 @@ where
47754779
let excess_feerate_opt = outbound_feerate_update
47764780
.or(self.pending_update_fee.map(|(fee, _)| fee))
47774781
.unwrap_or(self.feerate_per_kw)
4778-
.checked_sub(dust_exposure_limiting_feerate);
4782+
.checked_sub(dust_exposure_limiting_feerate.unwrap_or(0));
4783+
47794784
let extra_nondust_htlc_on_counterparty_tx_dust_exposure_msat = excess_feerate_opt.map(|excess_feerate| {
47804785
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());
47814786
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());

lightning/src/ln/functional_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9953,7 +9953,7 @@ fn do_test_max_dust_htlc_exposure(
99539953
let chan = chan_lock.channel_by_id.get(&channel_id).unwrap();
99549954
(
99559955
chan.context().get_dust_buffer_feerate(None) as u64,
9956-
chan.context().get_max_dust_htlc_exposure_msat(253),
9956+
chan.context().get_max_dust_htlc_exposure_msat(Some(253)),
99579957
)
99589958
};
99599959
assert_eq!(dust_buffer_feerate, expected_dust_buffer_feerate as u64);

lightning/src/util/config.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,20 @@ pub enum MaxDustHTLCExposure {
442442
/// on HTLC outputs means your channel may be subject to more dust exposure in the event of
443443
/// increases in fee rate.
444444
///
445+
/// Note that because zero-commitment-fee anchor channels do not allow for feerate updates (and
446+
/// thus never experience dust exposure changes due to feerate shifts, resulting in no
447+
/// force-closes due to dust exposure limits), such channels will calculate their maximum
448+
/// dust exposure using a constant feerate of 250 sat/KW when using this variant.
449+
///
445450
/// # Backwards Compatibility
446451
/// This variant only became available in LDK 0.0.116, so if you downgrade to a prior version
447452
/// by default this will be set to a [`Self::FixedLimitMsat`] of 5,000,000 msat.
448453
///
449454
/// [`FeeEstimator`]: crate::chain::chaininterface::FeeEstimator
450455
/// [`ConfirmationTarget::MaximumFeeEstimate`]: crate::chain::chaininterface::ConfirmationTarget::MaximumFeeEstimate
456+
//
457+
// TODO: link ChannelHandshakeConfig::negotiate_anchor_zero_fee_commitment in zero fee
458+
// commitment doc once field is no longer behind cfg[test] flag.
451459
FeeRateMultiplier(u64),
452460
}
453461

0 commit comments

Comments
 (0)