Skip to content

Commit 4f84f19

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 6ecacc4 commit 4f84f19

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

lightning/src/ln/channel.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3981,17 +3981,21 @@ where
39813981

39823982
fn get_dust_exposure_limiting_feerate<F: Deref>(
39833983
&self, fee_estimator: &LowerBoundedFeeEstimator<F>,
3984-
) -> u32
3984+
) -> Option<u32>
39853985
where
39863986
F::Target: FeeEstimator,
39873987
{
3988-
fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::MaximumFeeEstimate)
3988+
Some(fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::MaximumFeeEstimate))
39893989
}
39903990

3991-
pub fn get_max_dust_htlc_exposure_msat(&self, limiting_feerate_sat_per_kw: u32) -> u64 {
3991+
/// Returns the maximum configured dust exposure.
3992+
///
3993+
/// Uses a default of 1 sat/vbyte if `limiting_feerate_sat_per_kw` is `None` and the dust
3994+
/// exposure policy depends on fee rate.
3995+
pub fn get_max_dust_htlc_exposure_msat(&self, limiting_feerate_sat_per_kw: Option<u32>) -> u64 {
39923996
match self.config.options.max_dust_htlc_exposure {
39933997
MaxDustHTLCExposure::FeeRateMultiplier(multiplier) => {
3994-
(limiting_feerate_sat_per_kw as u64).saturating_mul(multiplier)
3998+
(limiting_feerate_sat_per_kw.unwrap_or(250) as u64).saturating_mul(multiplier)
39953999
},
39964000
MaxDustHTLCExposure::FixedLimitMsat(limit) => limit,
39974001
}
@@ -4338,7 +4342,7 @@ where
43384342
#[rustfmt::skip]
43394343
fn can_accept_incoming_htlc<L: Deref>(
43404344
&self, funding: &FundingScope, msg: &msgs::UpdateAddHTLC,
4341-
dust_exposure_limiting_feerate: u32, logger: &L,
4345+
dust_exposure_limiting_feerate: Option<u32>, logger: &L,
43424346
) -> Result<(), LocalHTLCFailureReason>
43434347
where
43444348
L::Target: Logger,
@@ -4678,7 +4682,7 @@ where
46784682
#[rustfmt::skip]
46794683
fn get_pending_htlc_stats(
46804684
&self, funding: &FundingScope, outbound_feerate_update: Option<u32>,
4681-
dust_exposure_limiting_feerate: u32,
4685+
dust_exposure_limiting_feerate: Option<u32>,
46824686
) -> HTLCStats {
46834687
let context = self;
46844688
let uses_0_htlc_fee_anchors = funding.get_channel_type().supports_anchors_zero_fee_htlc_tx();
@@ -4757,7 +4761,13 @@ where
47574761
let excess_feerate_opt = outbound_feerate_update
47584762
.or(self.pending_update_fee.map(|(fee, _)| fee))
47594763
.unwrap_or(self.feerate_per_kw)
4760-
.checked_sub(dust_exposure_limiting_feerate);
4764+
.checked_sub(dust_exposure_limiting_feerate.unwrap_or(0));
4765+
4766+
let is_zero_fee_comm = funding.get_channel_type().supports_anchor_zero_fee_commitments();
4767+
if is_zero_fee_comm {
4768+
debug_assert_eq!(excess_feerate_opt, Some(0));
4769+
}
4770+
47614771
let extra_nondust_htlc_on_counterparty_tx_dust_exposure_msat = excess_feerate_opt.map(|excess_feerate| {
47624772
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());
47634773
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
@@ -9941,7 +9941,7 @@ fn do_test_max_dust_htlc_exposure(
99419941
let chan = chan_lock.channel_by_id.get(&channel_id).unwrap();
99429942
(
99439943
chan.context().get_dust_buffer_feerate(None) as u64,
9944-
chan.context().get_max_dust_htlc_exposure_msat(253),
9944+
chan.context().get_max_dust_htlc_exposure_msat(Some(253)),
99459945
)
99469946
};
99479947
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)