Skip to content

Commit b1dea35

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 8046a3b commit b1dea35

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

lightning/src/ln/channel.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3833,17 +3833,21 @@ where
38333833

38343834
fn get_dust_exposure_limiting_feerate<F: Deref>(
38353835
&self, fee_estimator: &LowerBoundedFeeEstimator<F>,
3836-
) -> u32
3836+
) -> Option<u32>
38373837
where
38383838
F::Target: FeeEstimator,
38393839
{
3840-
fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::MaximumFeeEstimate)
3840+
Some(fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::MaximumFeeEstimate))
38413841
}
38423842

3843-
pub fn get_max_dust_htlc_exposure_msat(&self, limiting_feerate_sat_per_kw: u32) -> u64 {
3843+
/// Returns the maximum configured dust exposure.
3844+
///
3845+
/// Uses a default of 1 sat/vbyte if `limiting_feerate_sat_per_kw` is `None` and the dust
3846+
/// exposure policy depends on fee rate.
3847+
pub fn get_max_dust_htlc_exposure_msat(&self, limiting_feerate_sat_per_kw: Option<u32>) -> u64 {
38443848
match self.config.options.max_dust_htlc_exposure {
38453849
MaxDustHTLCExposure::FeeRateMultiplier(multiplier) => {
3846-
(limiting_feerate_sat_per_kw as u64).saturating_mul(multiplier)
3850+
(limiting_feerate_sat_per_kw.unwrap_or(250) as u64).saturating_mul(multiplier)
38473851
},
38483852
MaxDustHTLCExposure::FixedLimitMsat(limit) => limit,
38493853
}
@@ -4220,7 +4224,7 @@ where
42204224
#[rustfmt::skip]
42214225
fn can_accept_incoming_htlc<L: Deref>(
42224226
&self, funding: &FundingScope, msg: &msgs::UpdateAddHTLC,
4223-
dust_exposure_limiting_feerate: u32, logger: &L,
4227+
dust_exposure_limiting_feerate: Option<u32>, logger: &L,
42244228
) -> Result<(), LocalHTLCFailureReason>
42254229
where
42264230
L::Target: Logger,
@@ -4583,7 +4587,7 @@ where
45834587
#[rustfmt::skip]
45844588
fn get_pending_htlc_stats(
45854589
&self, funding: &FundingScope, outbound_feerate_update: Option<u32>,
4586-
dust_exposure_limiting_feerate: u32,
4590+
dust_exposure_limiting_feerate: Option<u32>,
45874591
) -> HTLCStats {
45884592
let context = self;
45894593
let uses_0_htlc_fee_anchors = funding.get_channel_type().supports_anchors_zero_fee_htlc_tx();
@@ -4662,7 +4666,11 @@ where
46624666
let excess_feerate_opt = outbound_feerate_update
46634667
.or(self.pending_update_fee.map(|(fee, _)| fee))
46644668
.unwrap_or(self.feerate_per_kw)
4665-
.checked_sub(dust_exposure_limiting_feerate);
4669+
.checked_sub(dust_exposure_limiting_feerate.unwrap_or(0));
4670+
4671+
if funding.get_channel_type().supports_anchor_zero_fee_commitments() {
4672+
debug_assert!(dust_exposure_limiting_feerate.is_none());
4673+
}
46664674
let extra_nondust_htlc_on_counterparty_tx_dust_exposure_msat = excess_feerate_opt.map(|excess_feerate| {
46674675
let extra_htlc_dust_exposure = on_counterparty_tx_dust_exposure_msat
46684676
+ chan_utils::commit_and_htlc_tx_fees_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs + 1, on_counterparty_tx_offered_nondust_htlcs, funding.get_channel_type()) * 1000;

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
@@ -438,12 +438,20 @@ pub enum MaxDustHTLCExposure {
438438
/// on HTLC outputs means your channel may be subject to more dust exposure in the event of
439439
/// increases in fee rate.
440440
///
441+
/// Note that because zero-commitment-fee anchor channels do not allow for feerate updates (and
442+
/// thus never experience dust exposure changes due to feerate shifts, resulting in no
443+
/// force-closes due to dust exposure limits), such channels will calculate their maximum
444+
/// dust exposure using a constant feerate of 250 sat/KW when using this variant.
445+
///
441446
/// # Backwards Compatibility
442447
/// This variant only became available in LDK 0.0.116, so if you downgrade to a prior version
443448
/// by default this will be set to a [`Self::FixedLimitMsat`] of 5,000,000 msat.
444449
///
445450
/// [`FeeEstimator`]: crate::chain::chaininterface::FeeEstimator
446451
/// [`ConfirmationTarget::MaximumFeeEstimate`]: crate::chain::chaininterface::ConfirmationTarget::MaximumFeeEstimate
452+
//
453+
// TODO: link ChannelHandshakeConfig::negotiate_anchor_zero_fee_commitment in zero fee
454+
// commitment doc once field is no longer behind cfg[test] flag.
447455
FeeRateMultiplier(u64),
448456
}
449457

0 commit comments

Comments
 (0)