1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * Options for how to set the max dust HTLC exposure allowed on a channel. See
13 * [`ChannelConfig::max_dust_htlc_exposure`] for details.
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class MaxDustHTLCExposure extends CommonBase {
17 private MaxDustHTLCExposure(Object _dummy, long ptr) { super(ptr); }
18 @Override @SuppressWarnings("deprecation")
19 protected void finalize() throws Throwable {
21 if (ptr != 0) { bindings.MaxDustHTLCExposure_free(ptr); }
23 static MaxDustHTLCExposure constr_from_ptr(long ptr) {
24 bindings.LDKMaxDustHTLCExposure raw_val = bindings.LDKMaxDustHTLCExposure_ref_from_ptr(ptr);
25 if (raw_val.getClass() == bindings.LDKMaxDustHTLCExposure.FixedLimitMsat.class) {
26 return new FixedLimitMsat(ptr, (bindings.LDKMaxDustHTLCExposure.FixedLimitMsat)raw_val);
28 if (raw_val.getClass() == bindings.LDKMaxDustHTLCExposure.FeeRateMultiplier.class) {
29 return new FeeRateMultiplier(ptr, (bindings.LDKMaxDustHTLCExposure.FeeRateMultiplier)raw_val);
31 assert false; return null; // Unreachable without extending the (internal) bindings interface
35 * This sets a fixed limit on the total dust exposure in millisatoshis. Setting this too low
36 * may prevent the sending or receipt of low-value HTLCs on high-traffic nodes, however this
37 * limit is very important to prevent stealing of large amounts of dust HTLCs by miners
38 * through [fee griefing
39 * attacks](https://lists.linuxfoundation.org/pipermail/lightning-dev/2020-May/002714.html).
41 * Note that if the feerate increases significantly, without a manual increase
42 * to this maximum the channel may be unable to send/receive HTLCs between the maximum dust
43 * exposure and the new minimum value for HTLCs to be economically viable to claim.
45 public final static class FixedLimitMsat extends MaxDustHTLCExposure {
46 public final long fixed_limit_msat;
47 private FixedLimitMsat(long ptr, bindings.LDKMaxDustHTLCExposure.FixedLimitMsat obj) {
49 this.fixed_limit_msat = obj.fixed_limit_msat;
53 * This sets a multiplier on the estimated high priority feerate (sats/KW, as obtained from
54 * [`FeeEstimator`]) to determine the maximum allowed dust exposure. If this variant is used
55 * then the maximum dust exposure in millisatoshis is calculated as:
56 * `high_priority_feerate_per_kw * value`. For example, with our default value
57 * `FeeRateMultiplier(5000)`:
59 * - For the minimum fee rate of 1 sat/vByte (250 sat/KW, although the minimum
60 * defaults to 253 sats/KW for rounding, see [`FeeEstimator`]), the max dust exposure would
61 * be 253 * 5000 = 1,265,000 msats.
62 * - For a fee rate of 30 sat/vByte (7500 sat/KW), the max dust exposure would be
63 * 7500 * 5000 = 37,500,000 msats.
65 * This allows the maximum dust exposure to automatically scale with fee rate changes.
67 * Note, if you're using a third-party fee estimator, this may leave you more exposed to a
68 * fee griefing attack, where your fee estimator may purposely overestimate the fee rate,
69 * causing you to accept more dust HTLCs than you would otherwise.
71 * This variant is primarily meant to serve pre-anchor channels, as HTLC fees being included
72 * on HTLC outputs means your channel may be subject to more dust exposure in the event of
73 * increases in fee rate.
75 * # Backwards Compatibility
76 * This variant only became available in LDK 0.0.116, so if you downgrade to a prior version
77 * by default this will be set to a [`Self::FixedLimitMsat`] of 5,000,000 msat.
79 * [`FeeEstimator`]: crate::chain::chaininterface::FeeEstimator
81 public final static class FeeRateMultiplier extends MaxDustHTLCExposure {
82 public final long fee_rate_multiplier;
83 private FeeRateMultiplier(long ptr, bindings.LDKMaxDustHTLCExposure.FeeRateMultiplier obj) {
85 this.fee_rate_multiplier = obj.fee_rate_multiplier;
89 long ret = bindings.MaxDustHTLCExposure_clone_ptr(this.ptr);
90 Reference.reachabilityFence(this);
95 * Creates a copy of the MaxDustHTLCExposure
97 public MaxDustHTLCExposure clone() {
98 long ret = bindings.MaxDustHTLCExposure_clone(this.ptr);
99 Reference.reachabilityFence(this);
100 if (ret >= 0 && ret <= 4096) { return null; }
101 org.ldk.structs.MaxDustHTLCExposure ret_hu_conv = org.ldk.structs.MaxDustHTLCExposure.constr_from_ptr(ret);
102 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
107 * Utility method to constructs a new FixedLimitMsat-variant MaxDustHTLCExposure
109 public static MaxDustHTLCExposure fixed_limit_msat(long a) {
110 long ret = bindings.MaxDustHTLCExposure_fixed_limit_msat(a);
111 Reference.reachabilityFence(a);
112 if (ret >= 0 && ret <= 4096) { return null; }
113 org.ldk.structs.MaxDustHTLCExposure ret_hu_conv = org.ldk.structs.MaxDustHTLCExposure.constr_from_ptr(ret);
114 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
119 * Utility method to constructs a new FeeRateMultiplier-variant MaxDustHTLCExposure
121 public static MaxDustHTLCExposure fee_rate_multiplier(long a) {
122 long ret = bindings.MaxDustHTLCExposure_fee_rate_multiplier(a);
123 Reference.reachabilityFence(a);
124 if (ret >= 0 && ret <= 4096) { return null; }
125 org.ldk.structs.MaxDustHTLCExposure ret_hu_conv = org.ldk.structs.MaxDustHTLCExposure.constr_from_ptr(ret);
126 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
131 * Checks if two MaxDustHTLCExposures contain equal inner contents.
132 * This ignores pointers and is_owned flags and looks at the values in fields.
134 public boolean eq(org.ldk.structs.MaxDustHTLCExposure b) {
135 boolean ret = bindings.MaxDustHTLCExposure_eq(this.ptr, b == null ? 0 : b.ptr);
136 Reference.reachabilityFence(this);
137 Reference.reachabilityFence(b);
141 @Override public boolean equals(Object o) {
142 if (!(o instanceof MaxDustHTLCExposure)) return false;
143 return this.eq((MaxDustHTLCExposure)o);
146 * Serialize the MaxDustHTLCExposure object into a byte array which can be read by MaxDustHTLCExposure_read
148 public byte[] write() {
149 byte[] ret = bindings.MaxDustHTLCExposure_write(this.ptr);
150 Reference.reachabilityFence(this);
155 * Read a MaxDustHTLCExposure from a byte array, created by MaxDustHTLCExposure_write
157 public static Result_MaxDustHTLCExposureDecodeErrorZ read(byte[] ser) {
158 long ret = bindings.MaxDustHTLCExposure_read(ser);
159 Reference.reachabilityFence(ser);
160 if (ret >= 0 && ret <= 4096) { return null; }
161 Result_MaxDustHTLCExposureDecodeErrorZ ret_hu_conv = Result_MaxDustHTLCExposureDecodeErrorZ.constr_from_ptr(ret);