Skip to content

Commit f0b3708

Browse files
committed
Update default dust exposure limit and the documentation thereof
Now that we're including excess counterparty commitment transaction fees in our dust calculation, we need to update the docs accordingly. We do so here, describing some of the considerations and risks that come with the new changes. We also take this opportunity to double the default value, as users have regularly complained that non-anchor channels fail to send HTLCs with the default settings with some feerates. Fixes lightningdevkit#2922
1 parent 51bf78d commit f0b3708

File tree

1 file changed

+52
-15
lines changed

1 file changed

+52
-15
lines changed

lightning/src/util/config.rs

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ impl Readable for ChannelHandshakeLimits {
360360
}
361361
}
362362

363-
/// Options for how to set the max dust HTLC exposure allowed on a channel. See
363+
/// Options for how to set the max dust exposure allowed on a channel. See
364364
/// [`ChannelConfig::max_dust_htlc_exposure`] for details.
365365
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
366366
pub enum MaxDustHTLCExposure {
@@ -374,19 +374,17 @@ pub enum MaxDustHTLCExposure {
374374
/// to this maximum the channel may be unable to send/receive HTLCs between the maximum dust
375375
/// exposure and the new minimum value for HTLCs to be economically viable to claim.
376376
FixedLimitMsat(u64),
377-
/// This sets a multiplier on the estimated high priority feerate (sats/KW, as obtained from
378-
/// [`FeeEstimator`]) to determine the maximum allowed dust exposure. If this variant is used
379-
/// then the maximum dust exposure in millisatoshis is calculated as:
380-
/// `high_priority_feerate_per_kw * value`. For example, with our default value
381-
/// `FeeRateMultiplier(5000)`:
377+
/// This sets a multiplier on the [`ConfirmationTarget::OnChainSweep`] feerate (in sats/KW) to
378+
/// determine the maximum allowed dust exposure. If this variant is used then the maximum dust
379+
/// exposure in millisatoshis is calculated as:
380+
/// `feerate_per_kw * value`. For example, with our default value
381+
/// `FeeRateMultiplier(10_000)`:
382382
///
383383
/// - For the minimum fee rate of 1 sat/vByte (250 sat/KW, although the minimum
384384
/// defaults to 253 sats/KW for rounding, see [`FeeEstimator`]), the max dust exposure would
385-
/// be 253 * 5000 = 1,265,000 msats.
385+
/// be 253 * 10_000 = 2,530,000 msats.
386386
/// - For a fee rate of 30 sat/vByte (7500 sat/KW), the max dust exposure would be
387-
/// 7500 * 5000 = 37,500,000 msats.
388-
///
389-
/// This allows the maximum dust exposure to automatically scale with fee rate changes.
387+
/// 7500 * 50_000 = 75,000,000 msats (0.00075 BTC).
390388
///
391389
/// Note, if you're using a third-party fee estimator, this may leave you more exposed to a
392390
/// fee griefing attack, where your fee estimator may purposely overestimate the fee rate,
@@ -401,6 +399,7 @@ pub enum MaxDustHTLCExposure {
401399
/// by default this will be set to a [`Self::FixedLimitMsat`] of 5,000,000 msat.
402400
///
403401
/// [`FeeEstimator`]: crate::chain::chaininterface::FeeEstimator
402+
/// [`ConfirmationTarget::OnChainSweep`]: crate::chain::chaininterface::ConfirmationTarget::OnChainSweep
404403
FeeRateMultiplier(u64),
405404
}
406405

@@ -453,13 +452,16 @@ pub struct ChannelConfig {
453452
///
454453
/// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
455454
pub cltv_expiry_delta: u16,
456-
/// Limit our total exposure to in-flight HTLCs which are burned to fees as they are too
457-
/// small to claim on-chain.
455+
/// Limit our total exposure to potential loss to on-chain fees on close, including in-flight
456+
/// HTLCs which are burned to fees as they are too small to claim on-chain and fees on
457+
/// commitment transaction(s) broadcasted by our counterparty in excess of our own fee estimate.
458+
///
459+
/// # HTLC-based Dust Exposure
458460
///
459461
/// When an HTLC present in one of our channels is below a "dust" threshold, the HTLC will
460462
/// not be claimable on-chain, instead being turned into additional miner fees if either
461463
/// party force-closes the channel. Because the threshold is per-HTLC, our total exposure
462-
/// to such payments may be sustantial if there are many dust HTLCs present when the
464+
/// to such payments may be substantial if there are many dust HTLCs present when the
463465
/// channel is force-closed.
464466
///
465467
/// The dust threshold for each HTLC is based on the `dust_limit_satoshis` for each party in a
@@ -473,7 +475,42 @@ pub struct ChannelConfig {
473475
/// The selected limit is applied for sent, forwarded, and received HTLCs and limits the total
474476
/// exposure across all three types per-channel.
475477
///
476-
/// Default value: [`MaxDustHTLCExposure::FeeRateMultiplier`] with a multiplier of 5000.
478+
/// # Transaction Fee Dust Exposure
479+
///
480+
/// Further, counterparties broadcasting a commitment transaction in a force-close may result
481+
/// in other balance being burned to fees, and thus all fees on commitment and HTLC
482+
/// transactions in excess of our local fee estimates are included in the dust calculation.
483+
///
484+
/// Because of this, another way to look at this limit is to divide it by 43,000 (or 218,750
485+
/// for non-anchor channels) and see it as the maximum feerate disagreement (in sats/vB) per
486+
/// non-dust HTLC we're allowed to have with our peers before risking a force-closure for
487+
/// inbound channels.
488+
// This works because, for anchor channels the on-chain cost is 172 weight (172+703 for
489+
// non-anchors with an HTLC-Success transaction), i.e.
490+
// dust_exposure_limit_msat / 1000 = 172 * feerate_in_sat_per_vb / 4 * HTLC count
491+
// dust_exposure_limit_msat = 43,000 * feerate_in_sat_per_vb * HTLC count
492+
// dust_exposure_limit_msat / HTLC count / 43,000 = feerate_in_sat_per_vb
493+
///
494+
/// Thus, for the default value of 10_000 * a current feerate estimate of 10 sat/vB (or 2,500
495+
/// sat/KW), we risk force-closure if we disagree with our peer by:
496+
/// * `10_000 * 2_500 / 43_000 / (483*2)` = 0.6 sat/vB for anchor channels with 483 HTLCs in
497+
/// both directions (the maximum),
498+
/// * `10_000 * 2_500 / 43_000 / (50*2)` = 5.8 sat/vB for anchor channels with 50 HTLCs in both
499+
/// directions (the LDK default max from [`ChannelHandshakeConfig::our_max_accepted_htlcs`])
500+
/// * `10_000 * 2_500 / 218_750 / (483*2)` = 0.1 sat/vB for non-anchor channels with 483 HTLCs
501+
/// in both directions (the maximum),
502+
/// * `10_000 * 2_500 / 218_750 / (50*2)` = 1.1 sat/vB for non-anchor channels with 50 HTLCs
503+
/// in both (the LDK default maximum from [`ChannelHandshakeConfig::our_max_accepted_htlcs`])
504+
///
505+
/// Note that when using [`MaxDustHTLCExposure::FeeRateMultiplier`] this maximum disagreement
506+
/// will scale linearly with increases (or decreases) in the our feerate estimates. Further,
507+
/// for anchor channels we expect our counterparty to use a relatively low feerate estimate
508+
/// while we use [`ConfirmationTarget::OnChainSweep`] (which should be relatively high) and
509+
/// feerate disagreement force-closures should only occur when theirs is higher than ours.
510+
///
511+
/// Default value: [`MaxDustHTLCExposure::FeeRateMultiplier`] with a multiplier of 10_000.
512+
///
513+
/// [`ConfirmationTarget::OnChainSweep`]: crate::chain::chaininterface::ConfirmationTarget::OnChainSweep
477514
pub max_dust_htlc_exposure: MaxDustHTLCExposure,
478515
/// The additional fee we're willing to pay to avoid waiting for the counterparty's
479516
/// `to_self_delay` to reclaim funds.
@@ -561,7 +598,7 @@ impl Default for ChannelConfig {
561598
forwarding_fee_proportional_millionths: 0,
562599
forwarding_fee_base_msat: 1000,
563600
cltv_expiry_delta: 6 * 12, // 6 blocks/hour * 12 hours
564-
max_dust_htlc_exposure: MaxDustHTLCExposure::FeeRateMultiplier(5000),
601+
max_dust_htlc_exposure: MaxDustHTLCExposure::FeeRateMultiplier(10000),
565602
force_close_avoidance_max_fee_satoshis: 1000,
566603
accept_underpaying_htlcs: false,
567604
}

0 commit comments

Comments
 (0)