+// When fuzzing, we want to allow the fuzzer to pick any configuration parameters. Thus, we
+// implement Readable here in a naive way (which is a bit easier for the fuzzer to handle). We
+// don't really want to ever expose this to users (if we did we'd want to use TLVs).
+#[cfg(fuzzing)]
+impl Readable for ChannelHandshakeLimits {
+ fn read<R: crate::io::Read>(reader: &mut R) -> Result<Self, crate::ln::msgs::DecodeError> {
+ Ok(Self {
+ min_funding_satoshis: Readable::read(reader)?,
+ max_funding_satoshis: Readable::read(reader)?,
+ max_htlc_minimum_msat: Readable::read(reader)?,
+ min_max_htlc_value_in_flight_msat: Readable::read(reader)?,
+ max_channel_reserve_satoshis: Readable::read(reader)?,
+ min_max_accepted_htlcs: Readable::read(reader)?,
+ trust_own_funding_0conf: Readable::read(reader)?,
+ max_minimum_depth: Readable::read(reader)?,
+ force_announced_channel_preference: Readable::read(reader)?,
+ their_to_self_delay: Readable::read(reader)?,
+ })
+ }
+}
+
+/// Options for how to set the max dust HTLC exposure allowed on a channel. See
+/// [`ChannelConfig::max_dust_htlc_exposure`] for details.
+#[derive(Copy, Clone, Debug, PartialEq, Eq)]
+pub enum MaxDustHTLCExposure {
+ /// This sets a fixed limit on the total dust exposure in millisatoshis. Setting this too low
+ /// may prevent the sending or receipt of low-value HTLCs on high-traffic nodes, however this
+ /// limit is very important to prevent stealing of large amounts of dust HTLCs by miners
+ /// through [fee griefing
+ /// attacks](https://lists.linuxfoundation.org/pipermail/lightning-dev/2020-May/002714.html).
+ ///
+ /// Note that if the feerate increases significantly, without a manual increase
+ /// to this maximum the channel may be unable to send/receive HTLCs between the maximum dust
+ /// exposure and the new minimum value for HTLCs to be economically viable to claim.
+ FixedLimitMsat(u64),
+ /// This sets a multiplier on the estimated high priority feerate (sats/KW, as obtained from
+ /// [`FeeEstimator`]) to determine the maximum allowed dust exposure. If this variant is used
+ /// then the maximum dust exposure in millisatoshis is calculated as:
+ /// `high_priority_feerate_per_kw * value`. For example, with our default value
+ /// `FeeRateMultiplier(5000)`:
+ ///
+ /// - For the minimum fee rate of 1 sat/vByte (250 sat/KW, although the minimum
+ /// defaults to 253 sats/KW for rounding, see [`FeeEstimator`]), the max dust exposure would
+ /// be 253 * 5000 = 1,265,000 msats.
+ /// - For a fee rate of 30 sat/vByte (7500 sat/KW), the max dust exposure would be
+ /// 7500 * 5000 = 37,500,000 msats.
+ ///
+ /// This allows the maximum dust exposure to automatically scale with fee rate changes.
+ ///
+ /// Note, if you're using a third-party fee estimator, this may leave you more exposed to a
+ /// fee griefing attack, where your fee estimator may purposely overestimate the fee rate,
+ /// causing you to accept more dust HTLCs than you would otherwise.
+ ///
+ /// This variant is primarily meant to serve pre-anchor channels, as HTLC fees being included
+ /// on HTLC outputs means your channel may be subject to more dust exposure in the event of
+ /// increases in fee rate.
+ ///
+ /// # Backwards Compatibility
+ /// This variant only became available in LDK 0.0.116, so if you downgrade to a prior version
+ /// by default this will be set to a [`Self::FixedLimitMsat`] of 5,000,000 msat.
+ ///
+ /// [`FeeEstimator`]: crate::chain::chaininterface::FeeEstimator
+ FeeRateMultiplier(u64),
+}
+
+impl_writeable_tlv_based_enum!(MaxDustHTLCExposure, ;
+ (1, FixedLimitMsat),
+ (3, FeeRateMultiplier),
+);
+