1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
11 * Options which apply on a per-channel basis and may change at runtime or based on negotiation
12 * with our counterparty.
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class ChannelConfig extends CommonBase {
16 ChannelConfig(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.ChannelConfig_free(ptr); }
24 * Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
26 * This may be allowed to change at runtime in a later update, however doing so must result in
27 * update messages sent to notify all nodes of our updated relay fee.
31 public int get_forwarding_fee_proportional_millionths() {
32 int ret = bindings.ChannelConfig_get_forwarding_fee_proportional_millionths(this.ptr);
37 * Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
39 * This may be allowed to change at runtime in a later update, however doing so must result in
40 * update messages sent to notify all nodes of our updated relay fee.
44 public void set_forwarding_fee_proportional_millionths(int val) {
45 bindings.ChannelConfig_set_forwarding_fee_proportional_millionths(this.ptr, val);
49 * Amount (in milli-satoshi) charged for payments forwarded outbound over the channel, in
50 * excess of [`forwarding_fee_proportional_millionths`].
51 * This may be allowed to change at runtime in a later update, however doing so must result in
52 * update messages sent to notify all nodes of our updated relay fee.
54 * The default value of a single satoshi roughly matches the market rate on many routing nodes
55 * as of July 2021. Adjusting it upwards or downwards may change whether nodes route through
58 * Default value: 1000.
60 * [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
62 public int get_forwarding_fee_base_msat() {
63 int ret = bindings.ChannelConfig_get_forwarding_fee_base_msat(this.ptr);
68 * Amount (in milli-satoshi) charged for payments forwarded outbound over the channel, in
69 * excess of [`forwarding_fee_proportional_millionths`].
70 * This may be allowed to change at runtime in a later update, however doing so must result in
71 * update messages sent to notify all nodes of our updated relay fee.
73 * The default value of a single satoshi roughly matches the market rate on many routing nodes
74 * as of July 2021. Adjusting it upwards or downwards may change whether nodes route through
77 * Default value: 1000.
79 * [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
81 public void set_forwarding_fee_base_msat(int val) {
82 bindings.ChannelConfig_set_forwarding_fee_base_msat(this.ptr, val);
86 * The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
87 * the channel this config applies to.
89 * This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
90 * HTLC balance when a channel appears on-chain whereas
91 * [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
92 * (non-HTLC-encumbered) balance.
94 * Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
95 * we (or one of our watchtowers) MUST be online to check for broadcast of the current
96 * commitment transaction at least once per this many blocks (minus some margin to allow us
97 * enough time to broadcast and confirm a transaction, possibly with time in between to RBF
98 * the spending transaction).
100 * Default value: 72 (12 hours at an average of 6 blocks/hour).
101 * Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
102 * [`MIN_CLTV_EXPIRY_DELTA`] instead.
104 * [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
106 public short get_cltv_expiry_delta() {
107 short ret = bindings.ChannelConfig_get_cltv_expiry_delta(this.ptr);
112 * The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
113 * the channel this config applies to.
115 * This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
116 * HTLC balance when a channel appears on-chain whereas
117 * [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
118 * (non-HTLC-encumbered) balance.
120 * Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
121 * we (or one of our watchtowers) MUST be online to check for broadcast of the current
122 * commitment transaction at least once per this many blocks (minus some margin to allow us
123 * enough time to broadcast and confirm a transaction, possibly with time in between to RBF
124 * the spending transaction).
126 * Default value: 72 (12 hours at an average of 6 blocks/hour).
127 * Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
128 * [`MIN_CLTV_EXPIRY_DELTA`] instead.
130 * [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
132 public void set_cltv_expiry_delta(short val) {
133 bindings.ChannelConfig_set_cltv_expiry_delta(this.ptr, val);
137 * Set to announce the channel publicly and notify all nodes that they can route via this
140 * This should only be set to true for nodes which expect to be online reliably.
142 * As the node which funds a channel picks this value this will only apply for new outbound
143 * channels unless [`ChannelHandshakeLimits::force_announced_channel_preference`] is set.
145 * This cannot be changed after the initial channel handshake.
147 * Default value: false.
149 public boolean get_announced_channel() {
150 boolean ret = bindings.ChannelConfig_get_announced_channel(this.ptr);
155 * Set to announce the channel publicly and notify all nodes that they can route via this
158 * This should only be set to true for nodes which expect to be online reliably.
160 * As the node which funds a channel picks this value this will only apply for new outbound
161 * channels unless [`ChannelHandshakeLimits::force_announced_channel_preference`] is set.
163 * This cannot be changed after the initial channel handshake.
165 * Default value: false.
167 public void set_announced_channel(boolean val) {
168 bindings.ChannelConfig_set_announced_channel(this.ptr, val);
172 * When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
173 * supports it, they will then enforce the mutual-close output to us matches what we provided
174 * at intialization, preventing us from closing to an alternate pubkey.
176 * This is set to true by default to provide a slight increase in security, though ultimately
177 * any attacker who is able to take control of a channel can just as easily send the funds via
178 * lightning payments, so we never require that our counterparties support this option.
180 * This cannot be changed after a channel has been initialized.
182 * Default value: true.
184 public boolean get_commit_upfront_shutdown_pubkey() {
185 boolean ret = bindings.ChannelConfig_get_commit_upfront_shutdown_pubkey(this.ptr);
190 * When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
191 * supports it, they will then enforce the mutual-close output to us matches what we provided
192 * at intialization, preventing us from closing to an alternate pubkey.
194 * This is set to true by default to provide a slight increase in security, though ultimately
195 * any attacker who is able to take control of a channel can just as easily send the funds via
196 * lightning payments, so we never require that our counterparties support this option.
198 * This cannot be changed after a channel has been initialized.
200 * Default value: true.
202 public void set_commit_upfront_shutdown_pubkey(boolean val) {
203 bindings.ChannelConfig_set_commit_upfront_shutdown_pubkey(this.ptr, val);
207 * Limit our total exposure to in-flight HTLCs which are burned to fees as they are too
208 * small to claim on-chain.
210 * When an HTLC present in one of our channels is below a \"dust\" threshold, the HTLC will
211 * not be claimable on-chain, instead being turned into additional miner fees if either
212 * party force-closes the channel. Because the threshold is per-HTLC, our total exposure
213 * to such payments may be sustantial if there are many dust HTLCs present when the
214 * channel is force-closed.
216 * This limit is applied for sent, forwarded, and received HTLCs and limits the total
217 * exposure across all three types per-channel. Setting this too low may prevent the
218 * sending or receipt of low-value HTLCs on high-traffic nodes, and this limit is very
219 * important to prevent stealing of dust HTLCs by miners.
221 * Default value: 5_000_000 msat.
223 public long get_max_dust_htlc_exposure_msat() {
224 long ret = bindings.ChannelConfig_get_max_dust_htlc_exposure_msat(this.ptr);
229 * Limit our total exposure to in-flight HTLCs which are burned to fees as they are too
230 * small to claim on-chain.
232 * When an HTLC present in one of our channels is below a \"dust\" threshold, the HTLC will
233 * not be claimable on-chain, instead being turned into additional miner fees if either
234 * party force-closes the channel. Because the threshold is per-HTLC, our total exposure
235 * to such payments may be sustantial if there are many dust HTLCs present when the
236 * channel is force-closed.
238 * This limit is applied for sent, forwarded, and received HTLCs and limits the total
239 * exposure across all three types per-channel. Setting this too low may prevent the
240 * sending or receipt of low-value HTLCs on high-traffic nodes, and this limit is very
241 * important to prevent stealing of dust HTLCs by miners.
243 * Default value: 5_000_000 msat.
245 public void set_max_dust_htlc_exposure_msat(long val) {
246 bindings.ChannelConfig_set_max_dust_htlc_exposure_msat(this.ptr, val);
250 * The additional fee we're willing to pay to avoid waiting for the counterparty's
251 * `to_self_delay` to reclaim funds.
253 * When we close a channel cooperatively with our counterparty, we negotiate a fee for the
254 * closing transaction which both sides find acceptable, ultimately paid by the channel
257 * When we are the funder, because we have to pay the channel closing fee, we bound the
258 * acceptable fee by our [`Background`] and [`Normal`] fees, with the upper bound increased by
259 * this value. Because the on-chain fee we'd pay to force-close the channel is kept near our
260 * [`Normal`] feerate during normal operation, this value represents the additional fee we're
261 * willing to pay in order to avoid waiting for our counterparty's to_self_delay to reclaim our
264 * When we are not the funder, we require the closing transaction fee pay at least our
265 * [`Background`] fee estimate, but allow our counterparty to pay as much fee as they like.
266 * Thus, this value is ignored when we are not the funder.
268 * Default value: 1000 satoshis.
270 * [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
271 * [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
273 public long get_force_close_avoidance_max_fee_satoshis() {
274 long ret = bindings.ChannelConfig_get_force_close_avoidance_max_fee_satoshis(this.ptr);
279 * The additional fee we're willing to pay to avoid waiting for the counterparty's
280 * `to_self_delay` to reclaim funds.
282 * When we close a channel cooperatively with our counterparty, we negotiate a fee for the
283 * closing transaction which both sides find acceptable, ultimately paid by the channel
286 * When we are the funder, because we have to pay the channel closing fee, we bound the
287 * acceptable fee by our [`Background`] and [`Normal`] fees, with the upper bound increased by
288 * this value. Because the on-chain fee we'd pay to force-close the channel is kept near our
289 * [`Normal`] feerate during normal operation, this value represents the additional fee we're
290 * willing to pay in order to avoid waiting for our counterparty's to_self_delay to reclaim our
293 * When we are not the funder, we require the closing transaction fee pay at least our
294 * [`Background`] fee estimate, but allow our counterparty to pay as much fee as they like.
295 * Thus, this value is ignored when we are not the funder.
297 * Default value: 1000 satoshis.
299 * [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
300 * [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
302 public void set_force_close_avoidance_max_fee_satoshis(long val) {
303 bindings.ChannelConfig_set_force_close_avoidance_max_fee_satoshis(this.ptr, val);
307 * Constructs a new ChannelConfig given each field
309 public static ChannelConfig of(int forwarding_fee_proportional_millionths_arg, int forwarding_fee_base_msat_arg, short cltv_expiry_delta_arg, boolean announced_channel_arg, boolean commit_upfront_shutdown_pubkey_arg, long max_dust_htlc_exposure_msat_arg, long force_close_avoidance_max_fee_satoshis_arg) {
310 long ret = bindings.ChannelConfig_new(forwarding_fee_proportional_millionths_arg, forwarding_fee_base_msat_arg, cltv_expiry_delta_arg, announced_channel_arg, commit_upfront_shutdown_pubkey_arg, max_dust_htlc_exposure_msat_arg, force_close_avoidance_max_fee_satoshis_arg);
311 if (ret < 1024) { return null; }
312 ChannelConfig ret_hu_conv = new ChannelConfig(null, ret);
313 ret_hu_conv.ptrs_to.add(ret_hu_conv);
318 * Creates a copy of the ChannelConfig
320 public ChannelConfig clone() {
321 long ret = bindings.ChannelConfig_clone(this.ptr);
322 if (ret < 1024) { return null; }
323 ChannelConfig ret_hu_conv = new ChannelConfig(null, ret);
324 ret_hu_conv.ptrs_to.add(this);
329 * Creates a "default" ChannelConfig. See struct and individual field documentaiton for details on which values are used.
331 public static ChannelConfig with_default() {
332 long ret = bindings.ChannelConfig_default();
333 if (ret < 1024) { return null; }
334 ChannelConfig ret_hu_conv = new ChannelConfig(null, ret);
335 ret_hu_conv.ptrs_to.add(ret_hu_conv);
340 * Serialize the ChannelConfig object into a byte array which can be read by ChannelConfig_read
342 public byte[] write() {
343 byte[] ret = bindings.ChannelConfig_write(this.ptr);
348 * Read a ChannelConfig from a byte array, created by ChannelConfig_write
350 public static Result_ChannelConfigDecodeErrorZ read(byte[] ser) {
351 long ret = bindings.ChannelConfig_read(ser);
352 if (ret < 1024) { return null; }
353 Result_ChannelConfigDecodeErrorZ ret_hu_conv = Result_ChannelConfigDecodeErrorZ.constr_from_ptr(ret);