+/// Options for how to set the max dust HTLC exposure allowed on a channel. See
+/// [`ChannelConfig::max_dust_htlc_exposure`] for details.
+#[derive(Clone)]
+#[must_use]
+#[repr(C)]
+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),
+}
+use lightning::util::config::MaxDustHTLCExposure as MaxDustHTLCExposureImport;
+pub(crate) type nativeMaxDustHTLCExposure = MaxDustHTLCExposureImport;
+
+impl MaxDustHTLCExposure {
+ #[allow(unused)]
+ pub(crate) fn to_native(&self) -> nativeMaxDustHTLCExposure {
+ match self {
+ MaxDustHTLCExposure::FixedLimitMsat (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeMaxDustHTLCExposure::FixedLimitMsat (
+ a_nonref,
+ )
+ },
+ MaxDustHTLCExposure::FeeRateMultiplier (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeMaxDustHTLCExposure::FeeRateMultiplier (
+ a_nonref,
+ )
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn into_native(self) -> nativeMaxDustHTLCExposure {
+ match self {
+ MaxDustHTLCExposure::FixedLimitMsat (mut a, ) => {
+ nativeMaxDustHTLCExposure::FixedLimitMsat (
+ a,
+ )
+ },
+ MaxDustHTLCExposure::FeeRateMultiplier (mut a, ) => {
+ nativeMaxDustHTLCExposure::FeeRateMultiplier (
+ a,
+ )
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn from_native(native: &nativeMaxDustHTLCExposure) -> Self {
+ match native {
+ nativeMaxDustHTLCExposure::FixedLimitMsat (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ MaxDustHTLCExposure::FixedLimitMsat (
+ a_nonref,
+ )
+ },
+ nativeMaxDustHTLCExposure::FeeRateMultiplier (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ MaxDustHTLCExposure::FeeRateMultiplier (
+ a_nonref,
+ )
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn native_into(native: nativeMaxDustHTLCExposure) -> Self {
+ match native {
+ nativeMaxDustHTLCExposure::FixedLimitMsat (mut a, ) => {
+ MaxDustHTLCExposure::FixedLimitMsat (
+ a,
+ )
+ },
+ nativeMaxDustHTLCExposure::FeeRateMultiplier (mut a, ) => {
+ MaxDustHTLCExposure::FeeRateMultiplier (
+ a,
+ )
+ },
+ }
+ }
+}
+/// Frees any resources used by the MaxDustHTLCExposure
+#[no_mangle]
+pub extern "C" fn MaxDustHTLCExposure_free(this_ptr: MaxDustHTLCExposure) { }
+/// Creates a copy of the MaxDustHTLCExposure
+#[no_mangle]
+pub extern "C" fn MaxDustHTLCExposure_clone(orig: &MaxDustHTLCExposure) -> MaxDustHTLCExposure {
+ orig.clone()
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn MaxDustHTLCExposure_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const MaxDustHTLCExposure)).clone() })) as *mut c_void
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn MaxDustHTLCExposure_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut MaxDustHTLCExposure) };
+}
+#[no_mangle]
+/// Utility method to constructs a new FixedLimitMsat-variant MaxDustHTLCExposure
+pub extern "C" fn MaxDustHTLCExposure_fixed_limit_msat(a: u64) -> MaxDustHTLCExposure {
+ MaxDustHTLCExposure::FixedLimitMsat(a, )
+}
+#[no_mangle]
+/// Utility method to constructs a new FeeRateMultiplier-variant MaxDustHTLCExposure
+pub extern "C" fn MaxDustHTLCExposure_fee_rate_multiplier(a: u64) -> MaxDustHTLCExposure {
+ MaxDustHTLCExposure::FeeRateMultiplier(a, )
+}
+/// Checks if two MaxDustHTLCExposures contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn MaxDustHTLCExposure_eq(a: &MaxDustHTLCExposure, b: &MaxDustHTLCExposure) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}
+#[no_mangle]
+/// Serialize the MaxDustHTLCExposure object into a byte array which can be read by MaxDustHTLCExposure_read
+pub extern "C" fn MaxDustHTLCExposure_write(obj: &crate::lightning::util::config::MaxDustHTLCExposure) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
+}
+#[allow(unused)]
+pub(crate) extern "C" fn MaxDustHTLCExposure_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
+ MaxDustHTLCExposure_write(unsafe { &*(obj as *const MaxDustHTLCExposure) })
+}
+#[no_mangle]
+/// Read a MaxDustHTLCExposure from a byte array, created by MaxDustHTLCExposure_write
+pub extern "C" fn MaxDustHTLCExposure_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_MaxDustHTLCExposureDecodeErrorZ {
+ let res: Result<lightning::util::config::MaxDustHTLCExposure, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
+ let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::util::config::MaxDustHTLCExposure::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
+ local_res
+}