Pin compiler_builtins to 0.1.109 when building std
[ldk-c-bindings] / lightning-c-bindings / src / lightning / util / config.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
8
9 //! Various user-configurable channel limits and settings which ChannelManager
10 //! applies for you.
11
12 use alloc::str::FromStr;
13 use alloc::string::String;
14 use core::ffi::c_void;
15 use core::convert::Infallible;
16 use bitcoin::hashes::Hash;
17 use crate::c_types::*;
18 #[cfg(feature="no-std")]
19 use alloc::{vec::Vec, boxed::Box};
20
21
22 use lightning::util::config::ChannelHandshakeConfig as nativeChannelHandshakeConfigImport;
23 pub(crate) type nativeChannelHandshakeConfig = nativeChannelHandshakeConfigImport;
24
25 /// Configuration we set when applicable.
26 ///
27 /// Default::default() provides sane defaults.
28 #[must_use]
29 #[repr(C)]
30 pub struct ChannelHandshakeConfig {
31         /// A pointer to the opaque Rust object.
32
33         /// Nearly everywhere, inner must be non-null, however in places where
34         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
35         pub inner: *mut nativeChannelHandshakeConfig,
36         /// Indicates that this is the only struct which contains the same pointer.
37
38         /// Rust functions which take ownership of an object provided via an argument require
39         /// this to be true and invalidate the object pointed to by inner.
40         pub is_owned: bool,
41 }
42
43 impl Drop for ChannelHandshakeConfig {
44         fn drop(&mut self) {
45                 if self.is_owned && !<*mut nativeChannelHandshakeConfig>::is_null(self.inner) {
46                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
47                 }
48         }
49 }
50 /// Frees any resources used by the ChannelHandshakeConfig, if is_owned is set and inner is non-NULL.
51 #[no_mangle]
52 pub extern "C" fn ChannelHandshakeConfig_free(this_obj: ChannelHandshakeConfig) { }
53 #[allow(unused)]
54 /// Used only if an object of this type is returned as a trait impl by a method
55 pub(crate) extern "C" fn ChannelHandshakeConfig_free_void(this_ptr: *mut c_void) {
56         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelHandshakeConfig) };
57 }
58 #[allow(unused)]
59 impl ChannelHandshakeConfig {
60         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelHandshakeConfig {
61                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
62         }
63         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelHandshakeConfig {
64                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
65         }
66         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
67         pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeConfig {
68                 assert!(self.is_owned);
69                 let ret = ObjOps::untweak_ptr(self.inner);
70                 self.inner = core::ptr::null_mut();
71                 ret
72         }
73 }
74 /// Confirmations we will wait for before considering the channel locked in.
75 /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
76 /// equivalent limit applied to outbound channels).
77 ///
78 /// A lower-bound of 1 is applied, requiring all channels to have a confirmed commitment
79 /// transaction before operation. If you wish to accept channels with zero confirmations, see
80 /// [`UserConfig::manually_accept_inbound_channels`] and
81 /// [`ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`].
82 ///
83 /// Default value: 6.
84 ///
85 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
86 /// [`ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel_from_trusted_peer_0conf
87 #[no_mangle]
88 pub extern "C" fn ChannelHandshakeConfig_get_minimum_depth(this_ptr: &ChannelHandshakeConfig) -> u32 {
89         let mut inner_val = &mut this_ptr.get_native_mut_ref().minimum_depth;
90         *inner_val
91 }
92 /// Confirmations we will wait for before considering the channel locked in.
93 /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
94 /// equivalent limit applied to outbound channels).
95 ///
96 /// A lower-bound of 1 is applied, requiring all channels to have a confirmed commitment
97 /// transaction before operation. If you wish to accept channels with zero confirmations, see
98 /// [`UserConfig::manually_accept_inbound_channels`] and
99 /// [`ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`].
100 ///
101 /// Default value: 6.
102 ///
103 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
104 /// [`ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel_from_trusted_peer_0conf
105 #[no_mangle]
106 pub extern "C" fn ChannelHandshakeConfig_set_minimum_depth(this_ptr: &mut ChannelHandshakeConfig, mut val: u32) {
107         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.minimum_depth = val;
108 }
109 /// Set to the number of blocks we require our counterparty to wait to claim their money (ie
110 /// the number of blocks we have to punish our counterparty if they broadcast a revoked
111 /// transaction).
112 ///
113 /// This is one of the main parameters of our security model. We (or one of our watchtowers) MUST
114 /// be online to check for revoked transactions on-chain at least once every our_to_self_delay
115 /// blocks (minus some margin to allow us enough time to broadcast and confirm a transaction,
116 /// possibly with time in between to RBF the spending transaction).
117 ///
118 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
119 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
120 /// our channel.
121 ///
122 /// Default value: [`BREAKDOWN_TIMEOUT`], we enforce it as a minimum at channel opening so you
123 /// can tweak config to ask for more security, not less.
124 #[no_mangle]
125 pub extern "C" fn ChannelHandshakeConfig_get_our_to_self_delay(this_ptr: &ChannelHandshakeConfig) -> u16 {
126         let mut inner_val = &mut this_ptr.get_native_mut_ref().our_to_self_delay;
127         *inner_val
128 }
129 /// Set to the number of blocks we require our counterparty to wait to claim their money (ie
130 /// the number of blocks we have to punish our counterparty if they broadcast a revoked
131 /// transaction).
132 ///
133 /// This is one of the main parameters of our security model. We (or one of our watchtowers) MUST
134 /// be online to check for revoked transactions on-chain at least once every our_to_self_delay
135 /// blocks (minus some margin to allow us enough time to broadcast and confirm a transaction,
136 /// possibly with time in between to RBF the spending transaction).
137 ///
138 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
139 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
140 /// our channel.
141 ///
142 /// Default value: [`BREAKDOWN_TIMEOUT`], we enforce it as a minimum at channel opening so you
143 /// can tweak config to ask for more security, not less.
144 #[no_mangle]
145 pub extern "C" fn ChannelHandshakeConfig_set_our_to_self_delay(this_ptr: &mut ChannelHandshakeConfig, mut val: u16) {
146         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.our_to_self_delay = val;
147 }
148 /// Set to the smallest value HTLC we will accept to process.
149 ///
150 /// This value is sent to our counterparty on channel-open and we close the channel any time
151 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
152 ///
153 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
154 /// by the protocol.
155 #[no_mangle]
156 pub extern "C" fn ChannelHandshakeConfig_get_our_htlc_minimum_msat(this_ptr: &ChannelHandshakeConfig) -> u64 {
157         let mut inner_val = &mut this_ptr.get_native_mut_ref().our_htlc_minimum_msat;
158         *inner_val
159 }
160 /// Set to the smallest value HTLC we will accept to process.
161 ///
162 /// This value is sent to our counterparty on channel-open and we close the channel any time
163 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
164 ///
165 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
166 /// by the protocol.
167 #[no_mangle]
168 pub extern "C" fn ChannelHandshakeConfig_set_our_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeConfig, mut val: u64) {
169         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.our_htlc_minimum_msat = val;
170 }
171 /// Sets the percentage of the channel value we will cap the total value of outstanding inbound
172 /// HTLCs to.
173 ///
174 /// This can be set to a value between 1-100, where the value corresponds to the percent of the
175 /// channel value in whole percentages.
176 ///
177 /// Note that:
178 /// * If configured to another value than the default value 10, any new channels created with
179 /// the non default value will cause versions of LDK prior to 0.0.104 to refuse to read the
180 /// `ChannelManager`.
181 ///
182 /// * This caps the total value for inbound HTLCs in-flight only, and there's currently
183 /// no way to configure the cap for the total value of outbound HTLCs in-flight.
184 ///
185 /// * The requirements for your node being online to ensure the safety of HTLC-encumbered funds
186 /// are different from the non-HTLC-encumbered funds. This makes this an important knob to
187 /// restrict exposure to loss due to being offline for too long.
188 /// See [`ChannelHandshakeConfig::our_to_self_delay`] and [`ChannelConfig::cltv_expiry_delta`]
189 /// for more information.
190 ///
191 /// Default value: 10.
192 /// Minimum value: 1, any values less than 1 will be treated as 1 instead.
193 /// Maximum value: 100, any values larger than 100 will be treated as 100 instead.
194 #[no_mangle]
195 pub extern "C" fn ChannelHandshakeConfig_get_max_inbound_htlc_value_in_flight_percent_of_channel(this_ptr: &ChannelHandshakeConfig) -> u8 {
196         let mut inner_val = &mut this_ptr.get_native_mut_ref().max_inbound_htlc_value_in_flight_percent_of_channel;
197         *inner_val
198 }
199 /// Sets the percentage of the channel value we will cap the total value of outstanding inbound
200 /// HTLCs to.
201 ///
202 /// This can be set to a value between 1-100, where the value corresponds to the percent of the
203 /// channel value in whole percentages.
204 ///
205 /// Note that:
206 /// * If configured to another value than the default value 10, any new channels created with
207 /// the non default value will cause versions of LDK prior to 0.0.104 to refuse to read the
208 /// `ChannelManager`.
209 ///
210 /// * This caps the total value for inbound HTLCs in-flight only, and there's currently
211 /// no way to configure the cap for the total value of outbound HTLCs in-flight.
212 ///
213 /// * The requirements for your node being online to ensure the safety of HTLC-encumbered funds
214 /// are different from the non-HTLC-encumbered funds. This makes this an important knob to
215 /// restrict exposure to loss due to being offline for too long.
216 /// See [`ChannelHandshakeConfig::our_to_self_delay`] and [`ChannelConfig::cltv_expiry_delta`]
217 /// for more information.
218 ///
219 /// Default value: 10.
220 /// Minimum value: 1, any values less than 1 will be treated as 1 instead.
221 /// Maximum value: 100, any values larger than 100 will be treated as 100 instead.
222 #[no_mangle]
223 pub extern "C" fn ChannelHandshakeConfig_set_max_inbound_htlc_value_in_flight_percent_of_channel(this_ptr: &mut ChannelHandshakeConfig, mut val: u8) {
224         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_inbound_htlc_value_in_flight_percent_of_channel = val;
225 }
226 /// If set, we attempt to negotiate the `scid_privacy` (referred to as `scid_alias` in the
227 /// BOLTs) option for outbound private channels. This provides better privacy by not including
228 /// our real on-chain channel UTXO in each invoice and requiring that our counterparty only
229 /// relay HTLCs to us using the channel's SCID alias.
230 ///
231 /// If this option is set, channels may be created that will not be readable by LDK versions
232 /// prior to 0.0.106, causing [`ChannelManager`]'s read method to return a
233 /// [`DecodeError::InvalidValue`].
234 ///
235 /// Note that setting this to true does *not* prevent us from opening channels with
236 /// counterparties that do not support the `scid_alias` option; we will simply fall back to a
237 /// private channel without that option.
238 ///
239 /// Ignored if the channel is negotiated to be announced, see
240 /// [`ChannelHandshakeConfig::announced_channel`] and
241 /// [`ChannelHandshakeLimits::force_announced_channel_preference`] for more.
242 ///
243 /// Default value: false. This value is likely to change to true in the future.
244 ///
245 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
246 /// [`DecodeError::InvalidValue`]: crate::ln::msgs::DecodeError::InvalidValue
247 #[no_mangle]
248 pub extern "C" fn ChannelHandshakeConfig_get_negotiate_scid_privacy(this_ptr: &ChannelHandshakeConfig) -> bool {
249         let mut inner_val = &mut this_ptr.get_native_mut_ref().negotiate_scid_privacy;
250         *inner_val
251 }
252 /// If set, we attempt to negotiate the `scid_privacy` (referred to as `scid_alias` in the
253 /// BOLTs) option for outbound private channels. This provides better privacy by not including
254 /// our real on-chain channel UTXO in each invoice and requiring that our counterparty only
255 /// relay HTLCs to us using the channel's SCID alias.
256 ///
257 /// If this option is set, channels may be created that will not be readable by LDK versions
258 /// prior to 0.0.106, causing [`ChannelManager`]'s read method to return a
259 /// [`DecodeError::InvalidValue`].
260 ///
261 /// Note that setting this to true does *not* prevent us from opening channels with
262 /// counterparties that do not support the `scid_alias` option; we will simply fall back to a
263 /// private channel without that option.
264 ///
265 /// Ignored if the channel is negotiated to be announced, see
266 /// [`ChannelHandshakeConfig::announced_channel`] and
267 /// [`ChannelHandshakeLimits::force_announced_channel_preference`] for more.
268 ///
269 /// Default value: false. This value is likely to change to true in the future.
270 ///
271 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
272 /// [`DecodeError::InvalidValue`]: crate::ln::msgs::DecodeError::InvalidValue
273 #[no_mangle]
274 pub extern "C" fn ChannelHandshakeConfig_set_negotiate_scid_privacy(this_ptr: &mut ChannelHandshakeConfig, mut val: bool) {
275         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.negotiate_scid_privacy = val;
276 }
277 /// Set to announce the channel publicly and notify all nodes that they can route via this
278 /// channel.
279 ///
280 /// This should only be set to true for nodes which expect to be online reliably.
281 ///
282 /// As the node which funds a channel picks this value this will only apply for new outbound
283 /// channels unless [`ChannelHandshakeLimits::force_announced_channel_preference`] is set.
284 ///
285 /// Default value: false.
286 #[no_mangle]
287 pub extern "C" fn ChannelHandshakeConfig_get_announced_channel(this_ptr: &ChannelHandshakeConfig) -> bool {
288         let mut inner_val = &mut this_ptr.get_native_mut_ref().announced_channel;
289         *inner_val
290 }
291 /// Set to announce the channel publicly and notify all nodes that they can route via this
292 /// channel.
293 ///
294 /// This should only be set to true for nodes which expect to be online reliably.
295 ///
296 /// As the node which funds a channel picks this value this will only apply for new outbound
297 /// channels unless [`ChannelHandshakeLimits::force_announced_channel_preference`] is set.
298 ///
299 /// Default value: false.
300 #[no_mangle]
301 pub extern "C" fn ChannelHandshakeConfig_set_announced_channel(this_ptr: &mut ChannelHandshakeConfig, mut val: bool) {
302         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announced_channel = val;
303 }
304 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
305 /// supports it, they will then enforce the mutual-close output to us matches what we provided
306 /// at intialization, preventing us from closing to an alternate pubkey.
307 ///
308 /// This is set to true by default to provide a slight increase in security, though ultimately
309 /// any attacker who is able to take control of a channel can just as easily send the funds via
310 /// lightning payments, so we never require that our counterparties support this option.
311 ///
312 /// The upfront key committed is provided from [`SignerProvider::get_shutdown_scriptpubkey`].
313 ///
314 /// Default value: true.
315 ///
316 /// [`SignerProvider::get_shutdown_scriptpubkey`]: crate::sign::SignerProvider::get_shutdown_scriptpubkey
317 #[no_mangle]
318 pub extern "C" fn ChannelHandshakeConfig_get_commit_upfront_shutdown_pubkey(this_ptr: &ChannelHandshakeConfig) -> bool {
319         let mut inner_val = &mut this_ptr.get_native_mut_ref().commit_upfront_shutdown_pubkey;
320         *inner_val
321 }
322 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
323 /// supports it, they will then enforce the mutual-close output to us matches what we provided
324 /// at intialization, preventing us from closing to an alternate pubkey.
325 ///
326 /// This is set to true by default to provide a slight increase in security, though ultimately
327 /// any attacker who is able to take control of a channel can just as easily send the funds via
328 /// lightning payments, so we never require that our counterparties support this option.
329 ///
330 /// The upfront key committed is provided from [`SignerProvider::get_shutdown_scriptpubkey`].
331 ///
332 /// Default value: true.
333 ///
334 /// [`SignerProvider::get_shutdown_scriptpubkey`]: crate::sign::SignerProvider::get_shutdown_scriptpubkey
335 #[no_mangle]
336 pub extern "C" fn ChannelHandshakeConfig_set_commit_upfront_shutdown_pubkey(this_ptr: &mut ChannelHandshakeConfig, mut val: bool) {
337         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.commit_upfront_shutdown_pubkey = val;
338 }
339 /// The Proportion of the channel value to configure as counterparty's channel reserve,
340 /// i.e., `their_channel_reserve_satoshis` for both outbound and inbound channels.
341 ///
342 /// `their_channel_reserve_satoshis` is the minimum balance that the other node has to maintain
343 /// on their side, at all times.
344 /// This ensures that if our counterparty broadcasts a revoked state, we can punish them by
345 /// claiming at least this value on chain.
346 ///
347 /// Channel reserve values greater than 30% could be considered highly unreasonable, since that
348 /// amount can never be used for payments.
349 /// Also, if our selected channel reserve for counterparty and counterparty's selected
350 /// channel reserve for us sum up to equal or greater than channel value, channel negotiations
351 /// will fail.
352 ///
353 /// Note: Versions of LDK earlier than v0.0.104 will fail to read channels with any channel reserve
354 /// other than the default value.
355 ///
356 /// Default value: 1% of channel value, i.e., configured as 10,000 millionths.
357 /// Minimum value: If the calculated proportional value is less than 1000 sats, it will be treated
358 ///                as 1000 sats instead, which is a safe implementation-specific lower bound.
359 /// Maximum value: 1,000,000, any values larger than 1 Million will be treated as 1 Million (or 100%)
360 ///                instead, although channel negotiations will fail in that case.
361 #[no_mangle]
362 pub extern "C" fn ChannelHandshakeConfig_get_their_channel_reserve_proportional_millionths(this_ptr: &ChannelHandshakeConfig) -> u32 {
363         let mut inner_val = &mut this_ptr.get_native_mut_ref().their_channel_reserve_proportional_millionths;
364         *inner_val
365 }
366 /// The Proportion of the channel value to configure as counterparty's channel reserve,
367 /// i.e., `their_channel_reserve_satoshis` for both outbound and inbound channels.
368 ///
369 /// `their_channel_reserve_satoshis` is the minimum balance that the other node has to maintain
370 /// on their side, at all times.
371 /// This ensures that if our counterparty broadcasts a revoked state, we can punish them by
372 /// claiming at least this value on chain.
373 ///
374 /// Channel reserve values greater than 30% could be considered highly unreasonable, since that
375 /// amount can never be used for payments.
376 /// Also, if our selected channel reserve for counterparty and counterparty's selected
377 /// channel reserve for us sum up to equal or greater than channel value, channel negotiations
378 /// will fail.
379 ///
380 /// Note: Versions of LDK earlier than v0.0.104 will fail to read channels with any channel reserve
381 /// other than the default value.
382 ///
383 /// Default value: 1% of channel value, i.e., configured as 10,000 millionths.
384 /// Minimum value: If the calculated proportional value is less than 1000 sats, it will be treated
385 ///                as 1000 sats instead, which is a safe implementation-specific lower bound.
386 /// Maximum value: 1,000,000, any values larger than 1 Million will be treated as 1 Million (or 100%)
387 ///                instead, although channel negotiations will fail in that case.
388 #[no_mangle]
389 pub extern "C" fn ChannelHandshakeConfig_set_their_channel_reserve_proportional_millionths(this_ptr: &mut ChannelHandshakeConfig, mut val: u32) {
390         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.their_channel_reserve_proportional_millionths = val;
391 }
392 /// If set, we attempt to negotiate the `anchors_zero_fee_htlc_tx`option for all future
393 /// channels. This feature requires having a reserve of onchain funds readily available to bump
394 /// transactions in the event of a channel force close to avoid the possibility of losing funds.
395 ///
396 /// Note that if you wish accept inbound channels with anchor outputs, you must enable
397 /// [`UserConfig::manually_accept_inbound_channels`] and manually accept them with
398 /// [`ChannelManager::accept_inbound_channel`]. This is done to give you the chance to check
399 /// whether your reserve of onchain funds is enough to cover the fees for all existing and new
400 /// channels featuring anchor outputs in the event of a force close.
401 ///
402 /// If this option is set, channels may be created that will not be readable by LDK versions
403 /// prior to 0.0.116, causing [`ChannelManager`]'s read method to return a
404 /// [`DecodeError::InvalidValue`].
405 ///
406 /// Note that setting this to true does *not* prevent us from opening channels with
407 /// counterparties that do not support the `anchors_zero_fee_htlc_tx` option; we will simply
408 /// fall back to a `static_remote_key` channel.
409 ///
410 /// LDK will not support the legacy `option_anchors` commitment version due to a discovered
411 /// vulnerability after its deployment. For more context, see the [`SIGHASH_SINGLE + update_fee
412 /// Considered Harmful`] mailing list post.
413 ///
414 /// Default value: false. This value is likely to change to true in the future.
415 ///
416 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
417 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
418 /// [`DecodeError::InvalidValue`]: crate::ln::msgs::DecodeError::InvalidValue
419 /// [`SIGHASH_SINGLE + update_fee Considered Harmful`]: https://lists.linuxfoundation.org/pipermail/lightning-dev/2020-September/002796.html
420 #[no_mangle]
421 pub extern "C" fn ChannelHandshakeConfig_get_negotiate_anchors_zero_fee_htlc_tx(this_ptr: &ChannelHandshakeConfig) -> bool {
422         let mut inner_val = &mut this_ptr.get_native_mut_ref().negotiate_anchors_zero_fee_htlc_tx;
423         *inner_val
424 }
425 /// If set, we attempt to negotiate the `anchors_zero_fee_htlc_tx`option for all future
426 /// channels. This feature requires having a reserve of onchain funds readily available to bump
427 /// transactions in the event of a channel force close to avoid the possibility of losing funds.
428 ///
429 /// Note that if you wish accept inbound channels with anchor outputs, you must enable
430 /// [`UserConfig::manually_accept_inbound_channels`] and manually accept them with
431 /// [`ChannelManager::accept_inbound_channel`]. This is done to give you the chance to check
432 /// whether your reserve of onchain funds is enough to cover the fees for all existing and new
433 /// channels featuring anchor outputs in the event of a force close.
434 ///
435 /// If this option is set, channels may be created that will not be readable by LDK versions
436 /// prior to 0.0.116, causing [`ChannelManager`]'s read method to return a
437 /// [`DecodeError::InvalidValue`].
438 ///
439 /// Note that setting this to true does *not* prevent us from opening channels with
440 /// counterparties that do not support the `anchors_zero_fee_htlc_tx` option; we will simply
441 /// fall back to a `static_remote_key` channel.
442 ///
443 /// LDK will not support the legacy `option_anchors` commitment version due to a discovered
444 /// vulnerability after its deployment. For more context, see the [`SIGHASH_SINGLE + update_fee
445 /// Considered Harmful`] mailing list post.
446 ///
447 /// Default value: false. This value is likely to change to true in the future.
448 ///
449 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
450 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
451 /// [`DecodeError::InvalidValue`]: crate::ln::msgs::DecodeError::InvalidValue
452 /// [`SIGHASH_SINGLE + update_fee Considered Harmful`]: https://lists.linuxfoundation.org/pipermail/lightning-dev/2020-September/002796.html
453 #[no_mangle]
454 pub extern "C" fn ChannelHandshakeConfig_set_negotiate_anchors_zero_fee_htlc_tx(this_ptr: &mut ChannelHandshakeConfig, mut val: bool) {
455         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.negotiate_anchors_zero_fee_htlc_tx = val;
456 }
457 /// The maximum number of HTLCs in-flight from our counterparty towards us at the same time.
458 ///
459 /// Increasing the value can help improve liquidity and stability in
460 /// routing at the cost of higher long term disk / DB usage.
461 ///
462 /// Note: Versions of LDK earlier than v0.0.115 will fail to read channels with a configuration
463 /// other than the default value.
464 ///
465 /// Default value: 50
466 /// Maximum value: 483, any values larger will be treated as 483.
467 ///                     This is the BOLT #2 spec limit on `max_accepted_htlcs`.
468 #[no_mangle]
469 pub extern "C" fn ChannelHandshakeConfig_get_our_max_accepted_htlcs(this_ptr: &ChannelHandshakeConfig) -> u16 {
470         let mut inner_val = &mut this_ptr.get_native_mut_ref().our_max_accepted_htlcs;
471         *inner_val
472 }
473 /// The maximum number of HTLCs in-flight from our counterparty towards us at the same time.
474 ///
475 /// Increasing the value can help improve liquidity and stability in
476 /// routing at the cost of higher long term disk / DB usage.
477 ///
478 /// Note: Versions of LDK earlier than v0.0.115 will fail to read channels with a configuration
479 /// other than the default value.
480 ///
481 /// Default value: 50
482 /// Maximum value: 483, any values larger will be treated as 483.
483 ///                     This is the BOLT #2 spec limit on `max_accepted_htlcs`.
484 #[no_mangle]
485 pub extern "C" fn ChannelHandshakeConfig_set_our_max_accepted_htlcs(this_ptr: &mut ChannelHandshakeConfig, mut val: u16) {
486         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.our_max_accepted_htlcs = val;
487 }
488 /// Constructs a new ChannelHandshakeConfig given each field
489 #[must_use]
490 #[no_mangle]
491 pub extern "C" fn ChannelHandshakeConfig_new(mut minimum_depth_arg: u32, mut our_to_self_delay_arg: u16, mut our_htlc_minimum_msat_arg: u64, mut max_inbound_htlc_value_in_flight_percent_of_channel_arg: u8, mut negotiate_scid_privacy_arg: bool, mut announced_channel_arg: bool, mut commit_upfront_shutdown_pubkey_arg: bool, mut their_channel_reserve_proportional_millionths_arg: u32, mut negotiate_anchors_zero_fee_htlc_tx_arg: bool, mut our_max_accepted_htlcs_arg: u16) -> ChannelHandshakeConfig {
492         ChannelHandshakeConfig { inner: ObjOps::heap_alloc(nativeChannelHandshakeConfig {
493                 minimum_depth: minimum_depth_arg,
494                 our_to_self_delay: our_to_self_delay_arg,
495                 our_htlc_minimum_msat: our_htlc_minimum_msat_arg,
496                 max_inbound_htlc_value_in_flight_percent_of_channel: max_inbound_htlc_value_in_flight_percent_of_channel_arg,
497                 negotiate_scid_privacy: negotiate_scid_privacy_arg,
498                 announced_channel: announced_channel_arg,
499                 commit_upfront_shutdown_pubkey: commit_upfront_shutdown_pubkey_arg,
500                 their_channel_reserve_proportional_millionths: their_channel_reserve_proportional_millionths_arg,
501                 negotiate_anchors_zero_fee_htlc_tx: negotiate_anchors_zero_fee_htlc_tx_arg,
502                 our_max_accepted_htlcs: our_max_accepted_htlcs_arg,
503         }), is_owned: true }
504 }
505 impl Clone for ChannelHandshakeConfig {
506         fn clone(&self) -> Self {
507                 Self {
508                         inner: if <*mut nativeChannelHandshakeConfig>::is_null(self.inner) { core::ptr::null_mut() } else {
509                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
510                         is_owned: true,
511                 }
512         }
513 }
514 #[allow(unused)]
515 /// Used only if an object of this type is returned as a trait impl by a method
516 pub(crate) extern "C" fn ChannelHandshakeConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
517         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelHandshakeConfig)).clone() })) as *mut c_void
518 }
519 #[no_mangle]
520 /// Creates a copy of the ChannelHandshakeConfig
521 pub extern "C" fn ChannelHandshakeConfig_clone(orig: &ChannelHandshakeConfig) -> ChannelHandshakeConfig {
522         orig.clone()
523 }
524 /// Get a string which allows debug introspection of a ChannelHandshakeConfig object
525 pub extern "C" fn ChannelHandshakeConfig_debug_str_void(o: *const c_void) -> Str {
526         alloc::format!("{:?}", unsafe { o as *const crate::lightning::util::config::ChannelHandshakeConfig }).into()}
527 /// Creates a "default" ChannelHandshakeConfig. See struct and individual field documentaiton for details on which values are used.
528 #[must_use]
529 #[no_mangle]
530 pub extern "C" fn ChannelHandshakeConfig_default() -> ChannelHandshakeConfig {
531         ChannelHandshakeConfig { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
532 }
533
534 use lightning::util::config::ChannelHandshakeLimits as nativeChannelHandshakeLimitsImport;
535 pub(crate) type nativeChannelHandshakeLimits = nativeChannelHandshakeLimitsImport;
536
537 /// Optional channel limits which are applied during channel creation.
538 ///
539 /// These limits are only applied to our counterparty's limits, not our own.
540 ///
541 /// Use 0/`<type>::max_value()` as appropriate to skip checking.
542 ///
543 /// Provides sane defaults for most configurations.
544 ///
545 /// Most additional limits are disabled except those with which specify a default in individual
546 /// field documentation. Note that this may result in barely-usable channels, but since they
547 /// are applied mostly only to incoming channels that's not much of a problem.
548 #[must_use]
549 #[repr(C)]
550 pub struct ChannelHandshakeLimits {
551         /// A pointer to the opaque Rust object.
552
553         /// Nearly everywhere, inner must be non-null, however in places where
554         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
555         pub inner: *mut nativeChannelHandshakeLimits,
556         /// Indicates that this is the only struct which contains the same pointer.
557
558         /// Rust functions which take ownership of an object provided via an argument require
559         /// this to be true and invalidate the object pointed to by inner.
560         pub is_owned: bool,
561 }
562
563 impl Drop for ChannelHandshakeLimits {
564         fn drop(&mut self) {
565                 if self.is_owned && !<*mut nativeChannelHandshakeLimits>::is_null(self.inner) {
566                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
567                 }
568         }
569 }
570 /// Frees any resources used by the ChannelHandshakeLimits, if is_owned is set and inner is non-NULL.
571 #[no_mangle]
572 pub extern "C" fn ChannelHandshakeLimits_free(this_obj: ChannelHandshakeLimits) { }
573 #[allow(unused)]
574 /// Used only if an object of this type is returned as a trait impl by a method
575 pub(crate) extern "C" fn ChannelHandshakeLimits_free_void(this_ptr: *mut c_void) {
576         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelHandshakeLimits) };
577 }
578 #[allow(unused)]
579 impl ChannelHandshakeLimits {
580         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelHandshakeLimits {
581                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
582         }
583         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelHandshakeLimits {
584                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
585         }
586         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
587         pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeLimits {
588                 assert!(self.is_owned);
589                 let ret = ObjOps::untweak_ptr(self.inner);
590                 self.inner = core::ptr::null_mut();
591                 ret
592         }
593 }
594 /// Minimum allowed satoshis when a channel is funded. This is supplied by the sender and so
595 /// only applies to inbound channels.
596 ///
597 /// Default value: 0.
598 #[no_mangle]
599 pub extern "C" fn ChannelHandshakeLimits_get_min_funding_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
600         let mut inner_val = &mut this_ptr.get_native_mut_ref().min_funding_satoshis;
601         *inner_val
602 }
603 /// Minimum allowed satoshis when a channel is funded. This is supplied by the sender and so
604 /// only applies to inbound channels.
605 ///
606 /// Default value: 0.
607 #[no_mangle]
608 pub extern "C" fn ChannelHandshakeLimits_set_min_funding_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
609         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.min_funding_satoshis = val;
610 }
611 /// Maximum allowed satoshis when a channel is funded. This is supplied by the sender and so
612 /// only applies to inbound channels.
613 ///
614 /// Default value: 2^24 - 1.
615 #[no_mangle]
616 pub extern "C" fn ChannelHandshakeLimits_get_max_funding_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
617         let mut inner_val = &mut this_ptr.get_native_mut_ref().max_funding_satoshis;
618         *inner_val
619 }
620 /// Maximum allowed satoshis when a channel is funded. This is supplied by the sender and so
621 /// only applies to inbound channels.
622 ///
623 /// Default value: 2^24 - 1.
624 #[no_mangle]
625 pub extern "C" fn ChannelHandshakeLimits_set_max_funding_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
626         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_funding_satoshis = val;
627 }
628 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
629 /// you to limit the maximum minimum-size they can require.
630 ///
631 /// Default value: u64::max_value.
632 #[no_mangle]
633 pub extern "C" fn ChannelHandshakeLimits_get_max_htlc_minimum_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
634         let mut inner_val = &mut this_ptr.get_native_mut_ref().max_htlc_minimum_msat;
635         *inner_val
636 }
637 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
638 /// you to limit the maximum minimum-size they can require.
639 ///
640 /// Default value: u64::max_value.
641 #[no_mangle]
642 pub extern "C" fn ChannelHandshakeLimits_set_max_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
643         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_htlc_minimum_msat = val;
644 }
645 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
646 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
647 ///
648 /// Default value: 0.
649 #[no_mangle]
650 pub extern "C" fn ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
651         let mut inner_val = &mut this_ptr.get_native_mut_ref().min_max_htlc_value_in_flight_msat;
652         *inner_val
653 }
654 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
655 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
656 ///
657 /// Default value: 0.
658 #[no_mangle]
659 pub extern "C" fn ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
660         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.min_max_htlc_value_in_flight_msat = val;
661 }
662 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
663 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
664 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
665 ///
666 /// Default value: u64::max_value.
667 #[no_mangle]
668 pub extern "C" fn ChannelHandshakeLimits_get_max_channel_reserve_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
669         let mut inner_val = &mut this_ptr.get_native_mut_ref().max_channel_reserve_satoshis;
670         *inner_val
671 }
672 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
673 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
674 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
675 ///
676 /// Default value: u64::max_value.
677 #[no_mangle]
678 pub extern "C" fn ChannelHandshakeLimits_set_max_channel_reserve_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
679         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_channel_reserve_satoshis = val;
680 }
681 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
682 /// time. This allows you to set a minimum such value.
683 ///
684 /// Default value: 0.
685 #[no_mangle]
686 pub extern "C" fn ChannelHandshakeLimits_get_min_max_accepted_htlcs(this_ptr: &ChannelHandshakeLimits) -> u16 {
687         let mut inner_val = &mut this_ptr.get_native_mut_ref().min_max_accepted_htlcs;
688         *inner_val
689 }
690 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
691 /// time. This allows you to set a minimum such value.
692 ///
693 /// Default value: 0.
694 #[no_mangle]
695 pub extern "C" fn ChannelHandshakeLimits_set_min_max_accepted_htlcs(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
696         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.min_max_accepted_htlcs = val;
697 }
698 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
699 /// certain number of blocks, specified by the node which is not the funder (as the funder can
700 /// assume they aren't going to double-spend themselves).
701 /// This config allows you to set a limit on the maximum amount of time to wait.
702 ///
703 /// Default value: 144, or roughly one day and only applies to outbound channels.
704 #[no_mangle]
705 pub extern "C" fn ChannelHandshakeLimits_get_max_minimum_depth(this_ptr: &ChannelHandshakeLimits) -> u32 {
706         let mut inner_val = &mut this_ptr.get_native_mut_ref().max_minimum_depth;
707         *inner_val
708 }
709 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
710 /// certain number of blocks, specified by the node which is not the funder (as the funder can
711 /// assume they aren't going to double-spend themselves).
712 /// This config allows you to set a limit on the maximum amount of time to wait.
713 ///
714 /// Default value: 144, or roughly one day and only applies to outbound channels.
715 #[no_mangle]
716 pub extern "C" fn ChannelHandshakeLimits_set_max_minimum_depth(this_ptr: &mut ChannelHandshakeLimits, mut val: u32) {
717         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_minimum_depth = val;
718 }
719 /// Whether we implicitly trust funding transactions generated by us for our own outbound
720 /// channels to not be double-spent.
721 ///
722 /// If this is set, we assume that our own funding transactions are *never* double-spent, and
723 /// thus we can trust them without any confirmations. This is generally a reasonable
724 /// assumption, given we're the only ones who could ever double-spend it (assuming we have sole
725 /// control of the signing keys).
726 ///
727 /// You may wish to un-set this if you allow the user to (or do in an automated fashion)
728 /// double-spend the funding transaction to RBF with an alternative channel open.
729 ///
730 /// This only applies if our counterparty set their confirmations-required value to 0, and we
731 /// always trust our own funding transaction at 1 confirmation irrespective of this value.
732 /// Thus, this effectively acts as a `min_minimum_depth`, with the only possible values being
733 /// `true` (0) and `false` (1).
734 ///
735 /// Default value: true
736 #[no_mangle]
737 pub extern "C" fn ChannelHandshakeLimits_get_trust_own_funding_0conf(this_ptr: &ChannelHandshakeLimits) -> bool {
738         let mut inner_val = &mut this_ptr.get_native_mut_ref().trust_own_funding_0conf;
739         *inner_val
740 }
741 /// Whether we implicitly trust funding transactions generated by us for our own outbound
742 /// channels to not be double-spent.
743 ///
744 /// If this is set, we assume that our own funding transactions are *never* double-spent, and
745 /// thus we can trust them without any confirmations. This is generally a reasonable
746 /// assumption, given we're the only ones who could ever double-spend it (assuming we have sole
747 /// control of the signing keys).
748 ///
749 /// You may wish to un-set this if you allow the user to (or do in an automated fashion)
750 /// double-spend the funding transaction to RBF with an alternative channel open.
751 ///
752 /// This only applies if our counterparty set their confirmations-required value to 0, and we
753 /// always trust our own funding transaction at 1 confirmation irrespective of this value.
754 /// Thus, this effectively acts as a `min_minimum_depth`, with the only possible values being
755 /// `true` (0) and `false` (1).
756 ///
757 /// Default value: true
758 #[no_mangle]
759 pub extern "C" fn ChannelHandshakeLimits_set_trust_own_funding_0conf(this_ptr: &mut ChannelHandshakeLimits, mut val: bool) {
760         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.trust_own_funding_0conf = val;
761 }
762 /// Set to force an incoming channel to match our announced channel preference in
763 /// [`ChannelHandshakeConfig::announced_channel`].
764 ///
765 /// For a node which is not online reliably, this should be set to true and
766 /// [`ChannelHandshakeConfig::announced_channel`] set to false, ensuring that no announced (aka public)
767 /// channels will ever be opened.
768 ///
769 /// Default value: true.
770 #[no_mangle]
771 pub extern "C" fn ChannelHandshakeLimits_get_force_announced_channel_preference(this_ptr: &ChannelHandshakeLimits) -> bool {
772         let mut inner_val = &mut this_ptr.get_native_mut_ref().force_announced_channel_preference;
773         *inner_val
774 }
775 /// Set to force an incoming channel to match our announced channel preference in
776 /// [`ChannelHandshakeConfig::announced_channel`].
777 ///
778 /// For a node which is not online reliably, this should be set to true and
779 /// [`ChannelHandshakeConfig::announced_channel`] set to false, ensuring that no announced (aka public)
780 /// channels will ever be opened.
781 ///
782 /// Default value: true.
783 #[no_mangle]
784 pub extern "C" fn ChannelHandshakeLimits_set_force_announced_channel_preference(this_ptr: &mut ChannelHandshakeLimits, mut val: bool) {
785         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.force_announced_channel_preference = val;
786 }
787 /// Set to the amount of time we're willing to wait to claim money back to us.
788 ///
789 /// Not checking this value would be a security issue, as our peer would be able to set it to
790 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
791 ///
792 /// Default value: 2016, which we also enforce as a maximum value so you can tweak config to
793 /// reduce the loss of having useless locked funds (if your peer accepts)
794 #[no_mangle]
795 pub extern "C" fn ChannelHandshakeLimits_get_their_to_self_delay(this_ptr: &ChannelHandshakeLimits) -> u16 {
796         let mut inner_val = &mut this_ptr.get_native_mut_ref().their_to_self_delay;
797         *inner_val
798 }
799 /// Set to the amount of time we're willing to wait to claim money back to us.
800 ///
801 /// Not checking this value would be a security issue, as our peer would be able to set it to
802 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
803 ///
804 /// Default value: 2016, which we also enforce as a maximum value so you can tweak config to
805 /// reduce the loss of having useless locked funds (if your peer accepts)
806 #[no_mangle]
807 pub extern "C" fn ChannelHandshakeLimits_set_their_to_self_delay(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
808         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.their_to_self_delay = val;
809 }
810 /// Constructs a new ChannelHandshakeLimits given each field
811 #[must_use]
812 #[no_mangle]
813 pub extern "C" fn ChannelHandshakeLimits_new(mut min_funding_satoshis_arg: u64, mut max_funding_satoshis_arg: u64, mut max_htlc_minimum_msat_arg: u64, mut min_max_htlc_value_in_flight_msat_arg: u64, mut max_channel_reserve_satoshis_arg: u64, mut min_max_accepted_htlcs_arg: u16, mut max_minimum_depth_arg: u32, mut trust_own_funding_0conf_arg: bool, mut force_announced_channel_preference_arg: bool, mut their_to_self_delay_arg: u16) -> ChannelHandshakeLimits {
814         ChannelHandshakeLimits { inner: ObjOps::heap_alloc(nativeChannelHandshakeLimits {
815                 min_funding_satoshis: min_funding_satoshis_arg,
816                 max_funding_satoshis: max_funding_satoshis_arg,
817                 max_htlc_minimum_msat: max_htlc_minimum_msat_arg,
818                 min_max_htlc_value_in_flight_msat: min_max_htlc_value_in_flight_msat_arg,
819                 max_channel_reserve_satoshis: max_channel_reserve_satoshis_arg,
820                 min_max_accepted_htlcs: min_max_accepted_htlcs_arg,
821                 max_minimum_depth: max_minimum_depth_arg,
822                 trust_own_funding_0conf: trust_own_funding_0conf_arg,
823                 force_announced_channel_preference: force_announced_channel_preference_arg,
824                 their_to_self_delay: their_to_self_delay_arg,
825         }), is_owned: true }
826 }
827 impl Clone for ChannelHandshakeLimits {
828         fn clone(&self) -> Self {
829                 Self {
830                         inner: if <*mut nativeChannelHandshakeLimits>::is_null(self.inner) { core::ptr::null_mut() } else {
831                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
832                         is_owned: true,
833                 }
834         }
835 }
836 #[allow(unused)]
837 /// Used only if an object of this type is returned as a trait impl by a method
838 pub(crate) extern "C" fn ChannelHandshakeLimits_clone_void(this_ptr: *const c_void) -> *mut c_void {
839         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelHandshakeLimits)).clone() })) as *mut c_void
840 }
841 #[no_mangle]
842 /// Creates a copy of the ChannelHandshakeLimits
843 pub extern "C" fn ChannelHandshakeLimits_clone(orig: &ChannelHandshakeLimits) -> ChannelHandshakeLimits {
844         orig.clone()
845 }
846 /// Get a string which allows debug introspection of a ChannelHandshakeLimits object
847 pub extern "C" fn ChannelHandshakeLimits_debug_str_void(o: *const c_void) -> Str {
848         alloc::format!("{:?}", unsafe { o as *const crate::lightning::util::config::ChannelHandshakeLimits }).into()}
849 /// Creates a "default" ChannelHandshakeLimits. See struct and individual field documentaiton for details on which values are used.
850 #[must_use]
851 #[no_mangle]
852 pub extern "C" fn ChannelHandshakeLimits_default() -> ChannelHandshakeLimits {
853         ChannelHandshakeLimits { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
854 }
855 /// Options for how to set the max dust exposure allowed on a channel. See
856 /// [`ChannelConfig::max_dust_htlc_exposure`] for details.
857 #[derive(Clone)]
858 #[must_use]
859 #[repr(C)]
860 pub enum MaxDustHTLCExposure {
861         /// This sets a fixed limit on the total dust exposure in millisatoshis. Setting this too low
862         /// may prevent the sending or receipt of low-value HTLCs on high-traffic nodes, however this
863         /// limit is very important to prevent stealing of large amounts of dust HTLCs by miners
864         /// through [fee griefing
865         /// attacks](https://lists.linuxfoundation.org/pipermail/lightning-dev/2020-May/002714.html).
866         ///
867         /// Note that if the feerate increases significantly, without a manual increase
868         /// to this maximum the channel may be unable to send/receive HTLCs between the maximum dust
869         /// exposure and the new minimum value for HTLCs to be economically viable to claim.
870         FixedLimitMsat(
871                 u64),
872         /// This sets a multiplier on the [`ConfirmationTarget::OnChainSweep`] feerate (in sats/KW) to
873         /// determine the maximum allowed dust exposure. If this variant is used then the maximum dust
874         /// exposure in millisatoshis is calculated as:
875         /// `feerate_per_kw * value`. For example, with our default value
876         /// `FeeRateMultiplier(10_000)`:
877         ///
878         /// - For the minimum fee rate of 1 sat/vByte (250 sat/KW, although the minimum
879         /// defaults to 253 sats/KW for rounding, see [`FeeEstimator`]), the max dust exposure would
880         /// be 253 * 10_000 = 2,530,000 msats.
881         /// - For a fee rate of 30 sat/vByte (7500 sat/KW), the max dust exposure would be
882         /// 7500 * 50_000 = 75,000,000 msats (0.00075 BTC).
883         ///
884         /// Note, if you're using a third-party fee estimator, this may leave you more exposed to a
885         /// fee griefing attack, where your fee estimator may purposely overestimate the fee rate,
886         /// causing you to accept more dust HTLCs than you would otherwise.
887         ///
888         /// This variant is primarily meant to serve pre-anchor channels, as HTLC fees being included
889         /// on HTLC outputs means your channel may be subject to more dust exposure in the event of
890         /// increases in fee rate.
891         ///
892         /// # Backwards Compatibility
893         /// This variant only became available in LDK 0.0.116, so if you downgrade to a prior version
894         /// by default this will be set to a [`Self::FixedLimitMsat`] of 5,000,000 msat.
895         ///
896         /// [`FeeEstimator`]: crate::chain::chaininterface::FeeEstimator
897         /// [`ConfirmationTarget::OnChainSweep`]: crate::chain::chaininterface::ConfirmationTarget::OnChainSweep
898         FeeRateMultiplier(
899                 u64),
900 }
901 use lightning::util::config::MaxDustHTLCExposure as MaxDustHTLCExposureImport;
902 pub(crate) type nativeMaxDustHTLCExposure = MaxDustHTLCExposureImport;
903
904 impl MaxDustHTLCExposure {
905         #[allow(unused)]
906         pub(crate) fn to_native(&self) -> nativeMaxDustHTLCExposure {
907                 match self {
908                         MaxDustHTLCExposure::FixedLimitMsat (ref a, ) => {
909                                 let mut a_nonref = Clone::clone(a);
910                                 nativeMaxDustHTLCExposure::FixedLimitMsat (
911                                         a_nonref,
912                                 )
913                         },
914                         MaxDustHTLCExposure::FeeRateMultiplier (ref a, ) => {
915                                 let mut a_nonref = Clone::clone(a);
916                                 nativeMaxDustHTLCExposure::FeeRateMultiplier (
917                                         a_nonref,
918                                 )
919                         },
920                 }
921         }
922         #[allow(unused)]
923         pub(crate) fn into_native(self) -> nativeMaxDustHTLCExposure {
924                 match self {
925                         MaxDustHTLCExposure::FixedLimitMsat (mut a, ) => {
926                                 nativeMaxDustHTLCExposure::FixedLimitMsat (
927                                         a,
928                                 )
929                         },
930                         MaxDustHTLCExposure::FeeRateMultiplier (mut a, ) => {
931                                 nativeMaxDustHTLCExposure::FeeRateMultiplier (
932                                         a,
933                                 )
934                         },
935                 }
936         }
937         #[allow(unused)]
938         pub(crate) fn from_native(native: &MaxDustHTLCExposureImport) -> Self {
939                 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeMaxDustHTLCExposure) };
940                 match native {
941                         nativeMaxDustHTLCExposure::FixedLimitMsat (ref a, ) => {
942                                 let mut a_nonref = Clone::clone(a);
943                                 MaxDustHTLCExposure::FixedLimitMsat (
944                                         a_nonref,
945                                 )
946                         },
947                         nativeMaxDustHTLCExposure::FeeRateMultiplier (ref a, ) => {
948                                 let mut a_nonref = Clone::clone(a);
949                                 MaxDustHTLCExposure::FeeRateMultiplier (
950                                         a_nonref,
951                                 )
952                         },
953                 }
954         }
955         #[allow(unused)]
956         pub(crate) fn native_into(native: nativeMaxDustHTLCExposure) -> Self {
957                 match native {
958                         nativeMaxDustHTLCExposure::FixedLimitMsat (mut a, ) => {
959                                 MaxDustHTLCExposure::FixedLimitMsat (
960                                         a,
961                                 )
962                         },
963                         nativeMaxDustHTLCExposure::FeeRateMultiplier (mut a, ) => {
964                                 MaxDustHTLCExposure::FeeRateMultiplier (
965                                         a,
966                                 )
967                         },
968                 }
969         }
970 }
971 /// Frees any resources used by the MaxDustHTLCExposure
972 #[no_mangle]
973 pub extern "C" fn MaxDustHTLCExposure_free(this_ptr: MaxDustHTLCExposure) { }
974 /// Creates a copy of the MaxDustHTLCExposure
975 #[no_mangle]
976 pub extern "C" fn MaxDustHTLCExposure_clone(orig: &MaxDustHTLCExposure) -> MaxDustHTLCExposure {
977         orig.clone()
978 }
979 #[allow(unused)]
980 /// Used only if an object of this type is returned as a trait impl by a method
981 pub(crate) extern "C" fn MaxDustHTLCExposure_clone_void(this_ptr: *const c_void) -> *mut c_void {
982         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const MaxDustHTLCExposure)).clone() })) as *mut c_void
983 }
984 #[allow(unused)]
985 /// Used only if an object of this type is returned as a trait impl by a method
986 pub(crate) extern "C" fn MaxDustHTLCExposure_free_void(this_ptr: *mut c_void) {
987         let _ = unsafe { Box::from_raw(this_ptr as *mut MaxDustHTLCExposure) };
988 }
989 #[no_mangle]
990 /// Utility method to constructs a new FixedLimitMsat-variant MaxDustHTLCExposure
991 pub extern "C" fn MaxDustHTLCExposure_fixed_limit_msat(a: u64) -> MaxDustHTLCExposure {
992         MaxDustHTLCExposure::FixedLimitMsat(a, )
993 }
994 #[no_mangle]
995 /// Utility method to constructs a new FeeRateMultiplier-variant MaxDustHTLCExposure
996 pub extern "C" fn MaxDustHTLCExposure_fee_rate_multiplier(a: u64) -> MaxDustHTLCExposure {
997         MaxDustHTLCExposure::FeeRateMultiplier(a, )
998 }
999 /// Get a string which allows debug introspection of a MaxDustHTLCExposure object
1000 pub extern "C" fn MaxDustHTLCExposure_debug_str_void(o: *const c_void) -> Str {
1001         alloc::format!("{:?}", unsafe { o as *const crate::lightning::util::config::MaxDustHTLCExposure }).into()}
1002 /// Checks if two MaxDustHTLCExposures contain equal inner contents.
1003 /// This ignores pointers and is_owned flags and looks at the values in fields.
1004 #[no_mangle]
1005 pub extern "C" fn MaxDustHTLCExposure_eq(a: &MaxDustHTLCExposure, b: &MaxDustHTLCExposure) -> bool {
1006         if &a.to_native() == &b.to_native() { true } else { false }
1007 }
1008 #[no_mangle]
1009 /// Serialize the MaxDustHTLCExposure object into a byte array which can be read by MaxDustHTLCExposure_read
1010 pub extern "C" fn MaxDustHTLCExposure_write(obj: &crate::lightning::util::config::MaxDustHTLCExposure) -> crate::c_types::derived::CVec_u8Z {
1011         crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
1012 }
1013 #[allow(unused)]
1014 pub(crate) extern "C" fn MaxDustHTLCExposure_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1015         MaxDustHTLCExposure_write(unsafe { &*(obj as *const MaxDustHTLCExposure) })
1016 }
1017 #[no_mangle]
1018 /// Read a MaxDustHTLCExposure from a byte array, created by MaxDustHTLCExposure_write
1019 pub extern "C" fn MaxDustHTLCExposure_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_MaxDustHTLCExposureDecodeErrorZ {
1020         let res: Result<lightning::util::config::MaxDustHTLCExposure, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1021         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() };
1022         local_res
1023 }
1024
1025 use lightning::util::config::ChannelConfig as nativeChannelConfigImport;
1026 pub(crate) type nativeChannelConfig = nativeChannelConfigImport;
1027
1028 /// Options which apply on a per-channel basis and may change at runtime or based on negotiation
1029 /// with our counterparty.
1030 #[must_use]
1031 #[repr(C)]
1032 pub struct ChannelConfig {
1033         /// A pointer to the opaque Rust object.
1034
1035         /// Nearly everywhere, inner must be non-null, however in places where
1036         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1037         pub inner: *mut nativeChannelConfig,
1038         /// Indicates that this is the only struct which contains the same pointer.
1039
1040         /// Rust functions which take ownership of an object provided via an argument require
1041         /// this to be true and invalidate the object pointed to by inner.
1042         pub is_owned: bool,
1043 }
1044
1045 impl Drop for ChannelConfig {
1046         fn drop(&mut self) {
1047                 if self.is_owned && !<*mut nativeChannelConfig>::is_null(self.inner) {
1048                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1049                 }
1050         }
1051 }
1052 /// Frees any resources used by the ChannelConfig, if is_owned is set and inner is non-NULL.
1053 #[no_mangle]
1054 pub extern "C" fn ChannelConfig_free(this_obj: ChannelConfig) { }
1055 #[allow(unused)]
1056 /// Used only if an object of this type is returned as a trait impl by a method
1057 pub(crate) extern "C" fn ChannelConfig_free_void(this_ptr: *mut c_void) {
1058         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelConfig) };
1059 }
1060 #[allow(unused)]
1061 impl ChannelConfig {
1062         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelConfig {
1063                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1064         }
1065         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelConfig {
1066                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1067         }
1068         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1069         pub(crate) fn take_inner(mut self) -> *mut nativeChannelConfig {
1070                 assert!(self.is_owned);
1071                 let ret = ObjOps::untweak_ptr(self.inner);
1072                 self.inner = core::ptr::null_mut();
1073                 ret
1074         }
1075 }
1076 /// Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
1077 /// over the channel.
1078 /// This may be allowed to change at runtime in a later update, however doing so must result in
1079 /// update messages sent to notify all nodes of our updated relay fee.
1080 ///
1081 /// Default value: 0.
1082 #[no_mangle]
1083 pub extern "C" fn ChannelConfig_get_forwarding_fee_proportional_millionths(this_ptr: &ChannelConfig) -> u32 {
1084         let mut inner_val = &mut this_ptr.get_native_mut_ref().forwarding_fee_proportional_millionths;
1085         *inner_val
1086 }
1087 /// Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
1088 /// over the channel.
1089 /// This may be allowed to change at runtime in a later update, however doing so must result in
1090 /// update messages sent to notify all nodes of our updated relay fee.
1091 ///
1092 /// Default value: 0.
1093 #[no_mangle]
1094 pub extern "C" fn ChannelConfig_set_forwarding_fee_proportional_millionths(this_ptr: &mut ChannelConfig, mut val: u32) {
1095         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.forwarding_fee_proportional_millionths = val;
1096 }
1097 /// Amount (in milli-satoshi) charged for payments forwarded outbound over the channel, in
1098 /// excess of [`forwarding_fee_proportional_millionths`].
1099 /// This may be allowed to change at runtime in a later update, however doing so must result in
1100 /// update messages sent to notify all nodes of our updated relay fee.
1101 ///
1102 /// The default value of a single satoshi roughly matches the market rate on many routing nodes
1103 /// as of July 2021. Adjusting it upwards or downwards may change whether nodes route through
1104 /// this node.
1105 ///
1106 /// Default value: 1000.
1107 ///
1108 /// [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
1109 #[no_mangle]
1110 pub extern "C" fn ChannelConfig_get_forwarding_fee_base_msat(this_ptr: &ChannelConfig) -> u32 {
1111         let mut inner_val = &mut this_ptr.get_native_mut_ref().forwarding_fee_base_msat;
1112         *inner_val
1113 }
1114 /// Amount (in milli-satoshi) charged for payments forwarded outbound over the channel, in
1115 /// excess of [`forwarding_fee_proportional_millionths`].
1116 /// This may be allowed to change at runtime in a later update, however doing so must result in
1117 /// update messages sent to notify all nodes of our updated relay fee.
1118 ///
1119 /// The default value of a single satoshi roughly matches the market rate on many routing nodes
1120 /// as of July 2021. Adjusting it upwards or downwards may change whether nodes route through
1121 /// this node.
1122 ///
1123 /// Default value: 1000.
1124 ///
1125 /// [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
1126 #[no_mangle]
1127 pub extern "C" fn ChannelConfig_set_forwarding_fee_base_msat(this_ptr: &mut ChannelConfig, mut val: u32) {
1128         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.forwarding_fee_base_msat = val;
1129 }
1130 /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
1131 /// the channel this config applies to.
1132 ///
1133 /// This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
1134 /// HTLC balance when a channel appears on-chain whereas
1135 /// [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
1136 /// (non-HTLC-encumbered) balance.
1137 ///
1138 /// Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
1139 /// we (or one of our watchtowers) MUST be online to check for broadcast of the current
1140 /// commitment transaction at least once per this many blocks (minus some margin to allow us
1141 /// enough time to broadcast and confirm a transaction, possibly with time in between to RBF
1142 /// the spending transaction).
1143 ///
1144 /// Default value: 72 (12 hours at an average of 6 blocks/hour).
1145 /// Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
1146 ///                [`MIN_CLTV_EXPIRY_DELTA`] instead.
1147 ///
1148 /// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
1149 #[no_mangle]
1150 pub extern "C" fn ChannelConfig_get_cltv_expiry_delta(this_ptr: &ChannelConfig) -> u16 {
1151         let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
1152         *inner_val
1153 }
1154 /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
1155 /// the channel this config applies to.
1156 ///
1157 /// This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
1158 /// HTLC balance when a channel appears on-chain whereas
1159 /// [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
1160 /// (non-HTLC-encumbered) balance.
1161 ///
1162 /// Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
1163 /// we (or one of our watchtowers) MUST be online to check for broadcast of the current
1164 /// commitment transaction at least once per this many blocks (minus some margin to allow us
1165 /// enough time to broadcast and confirm a transaction, possibly with time in between to RBF
1166 /// the spending transaction).
1167 ///
1168 /// Default value: 72 (12 hours at an average of 6 blocks/hour).
1169 /// Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
1170 ///                [`MIN_CLTV_EXPIRY_DELTA`] instead.
1171 ///
1172 /// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
1173 #[no_mangle]
1174 pub extern "C" fn ChannelConfig_set_cltv_expiry_delta(this_ptr: &mut ChannelConfig, mut val: u16) {
1175         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
1176 }
1177 /// Limit our total exposure to potential loss to on-chain fees on close, including in-flight
1178 /// HTLCs which are burned to fees as they are too small to claim on-chain and fees on
1179 /// commitment transaction(s) broadcasted by our counterparty in excess of our own fee estimate.
1180 ///
1181 /// # HTLC-based Dust Exposure
1182 ///
1183 /// When an HTLC present in one of our channels is below a \"dust\" threshold, the HTLC will
1184 /// not be claimable on-chain, instead being turned into additional miner fees if either
1185 /// party force-closes the channel. Because the threshold is per-HTLC, our total exposure
1186 /// to such payments may be substantial if there are many dust HTLCs present when the
1187 /// channel is force-closed.
1188 ///
1189 /// The dust threshold for each HTLC is based on the `dust_limit_satoshis` for each party in a
1190 /// channel negotiated throughout the channel open process, along with the fees required to have
1191 /// a broadcastable HTLC spending transaction. When a channel supports anchor outputs
1192 /// (specifically the zero fee HTLC transaction variant), this threshold no longer takes into
1193 /// account the HTLC transaction fee as it is zero. Because of this, you may want to set this
1194 /// value to a fixed limit for channels using anchor outputs, while the fee rate multiplier
1195 /// variant is primarily intended for use with pre-anchor channels.
1196 ///
1197 /// The selected limit is applied for sent, forwarded, and received HTLCs and limits the total
1198 /// exposure across all three types per-channel.
1199 ///
1200 /// # Transaction Fee Dust Exposure
1201 ///
1202 /// Further, counterparties broadcasting a commitment transaction in a force-close may result
1203 /// in other balance being burned to fees, and thus all fees on commitment and HTLC
1204 /// transactions in excess of our local fee estimates are included in the dust calculation.
1205 ///
1206 /// Because of this, another way to look at this limit is to divide it by 43,000 (or 218,750
1207 /// for non-anchor channels) and see it as the maximum feerate disagreement (in sats/vB) per
1208 /// non-dust HTLC we're allowed to have with our peers before risking a force-closure for
1209 /// inbound channels.
1210 ///
1211 /// Thus, for the default value of 10_000 * a current feerate estimate of 10 sat/vB (or 2,500
1212 /// sat/KW), we risk force-closure if we disagree with our peer by:
1213 /// * `10_000 * 2_500 / 43_000 / (483*2)` = 0.6 sat/vB for anchor channels with 483 HTLCs in
1214 ///   both directions (the maximum),
1215 /// * `10_000 * 2_500 / 43_000 / (50*2)` = 5.8 sat/vB for anchor channels with 50 HTLCs in both
1216 ///   directions (the LDK default max from [`ChannelHandshakeConfig::our_max_accepted_htlcs`])
1217 /// * `10_000 * 2_500 / 218_750 / (483*2)` = 0.1 sat/vB for non-anchor channels with 483 HTLCs
1218 ///   in both directions (the maximum),
1219 /// * `10_000 * 2_500 / 218_750 / (50*2)` = 1.1 sat/vB for non-anchor channels with 50 HTLCs
1220 ///   in both (the LDK default maximum from [`ChannelHandshakeConfig::our_max_accepted_htlcs`])
1221 ///
1222 /// Note that when using [`MaxDustHTLCExposure::FeeRateMultiplier`] this maximum disagreement
1223 /// will scale linearly with increases (or decreases) in the our feerate estimates. Further,
1224 /// for anchor channels we expect our counterparty to use a relatively low feerate estimate
1225 /// while we use [`ConfirmationTarget::OnChainSweep`] (which should be relatively high) and
1226 /// feerate disagreement force-closures should only occur when theirs is higher than ours.
1227 ///
1228 /// Default value: [`MaxDustHTLCExposure::FeeRateMultiplier`] with a multiplier of 10_000.
1229 ///
1230 /// [`ConfirmationTarget::OnChainSweep`]: crate::chain::chaininterface::ConfirmationTarget::OnChainSweep
1231 #[no_mangle]
1232 pub extern "C" fn ChannelConfig_get_max_dust_htlc_exposure(this_ptr: &ChannelConfig) -> crate::lightning::util::config::MaxDustHTLCExposure {
1233         let mut inner_val = &mut this_ptr.get_native_mut_ref().max_dust_htlc_exposure;
1234         crate::lightning::util::config::MaxDustHTLCExposure::from_native(inner_val)
1235 }
1236 /// Limit our total exposure to potential loss to on-chain fees on close, including in-flight
1237 /// HTLCs which are burned to fees as they are too small to claim on-chain and fees on
1238 /// commitment transaction(s) broadcasted by our counterparty in excess of our own fee estimate.
1239 ///
1240 /// # HTLC-based Dust Exposure
1241 ///
1242 /// When an HTLC present in one of our channels is below a \"dust\" threshold, the HTLC will
1243 /// not be claimable on-chain, instead being turned into additional miner fees if either
1244 /// party force-closes the channel. Because the threshold is per-HTLC, our total exposure
1245 /// to such payments may be substantial if there are many dust HTLCs present when the
1246 /// channel is force-closed.
1247 ///
1248 /// The dust threshold for each HTLC is based on the `dust_limit_satoshis` for each party in a
1249 /// channel negotiated throughout the channel open process, along with the fees required to have
1250 /// a broadcastable HTLC spending transaction. When a channel supports anchor outputs
1251 /// (specifically the zero fee HTLC transaction variant), this threshold no longer takes into
1252 /// account the HTLC transaction fee as it is zero. Because of this, you may want to set this
1253 /// value to a fixed limit for channels using anchor outputs, while the fee rate multiplier
1254 /// variant is primarily intended for use with pre-anchor channels.
1255 ///
1256 /// The selected limit is applied for sent, forwarded, and received HTLCs and limits the total
1257 /// exposure across all three types per-channel.
1258 ///
1259 /// # Transaction Fee Dust Exposure
1260 ///
1261 /// Further, counterparties broadcasting a commitment transaction in a force-close may result
1262 /// in other balance being burned to fees, and thus all fees on commitment and HTLC
1263 /// transactions in excess of our local fee estimates are included in the dust calculation.
1264 ///
1265 /// Because of this, another way to look at this limit is to divide it by 43,000 (or 218,750
1266 /// for non-anchor channels) and see it as the maximum feerate disagreement (in sats/vB) per
1267 /// non-dust HTLC we're allowed to have with our peers before risking a force-closure for
1268 /// inbound channels.
1269 ///
1270 /// Thus, for the default value of 10_000 * a current feerate estimate of 10 sat/vB (or 2,500
1271 /// sat/KW), we risk force-closure if we disagree with our peer by:
1272 /// * `10_000 * 2_500 / 43_000 / (483*2)` = 0.6 sat/vB for anchor channels with 483 HTLCs in
1273 ///   both directions (the maximum),
1274 /// * `10_000 * 2_500 / 43_000 / (50*2)` = 5.8 sat/vB for anchor channels with 50 HTLCs in both
1275 ///   directions (the LDK default max from [`ChannelHandshakeConfig::our_max_accepted_htlcs`])
1276 /// * `10_000 * 2_500 / 218_750 / (483*2)` = 0.1 sat/vB for non-anchor channels with 483 HTLCs
1277 ///   in both directions (the maximum),
1278 /// * `10_000 * 2_500 / 218_750 / (50*2)` = 1.1 sat/vB for non-anchor channels with 50 HTLCs
1279 ///   in both (the LDK default maximum from [`ChannelHandshakeConfig::our_max_accepted_htlcs`])
1280 ///
1281 /// Note that when using [`MaxDustHTLCExposure::FeeRateMultiplier`] this maximum disagreement
1282 /// will scale linearly with increases (or decreases) in the our feerate estimates. Further,
1283 /// for anchor channels we expect our counterparty to use a relatively low feerate estimate
1284 /// while we use [`ConfirmationTarget::OnChainSweep`] (which should be relatively high) and
1285 /// feerate disagreement force-closures should only occur when theirs is higher than ours.
1286 ///
1287 /// Default value: [`MaxDustHTLCExposure::FeeRateMultiplier`] with a multiplier of 10_000.
1288 ///
1289 /// [`ConfirmationTarget::OnChainSweep`]: crate::chain::chaininterface::ConfirmationTarget::OnChainSweep
1290 #[no_mangle]
1291 pub extern "C" fn ChannelConfig_set_max_dust_htlc_exposure(this_ptr: &mut ChannelConfig, mut val: crate::lightning::util::config::MaxDustHTLCExposure) {
1292         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_dust_htlc_exposure = val.into_native();
1293 }
1294 /// The additional fee we're willing to pay to avoid waiting for the counterparty's
1295 /// `to_self_delay` to reclaim funds.
1296 ///
1297 /// When we close a channel cooperatively with our counterparty, we negotiate a fee for the
1298 /// closing transaction which both sides find acceptable, ultimately paid by the channel
1299 /// funder/initiator.
1300 ///
1301 /// When we are the funder, because we have to pay the channel closing fee, we bound the
1302 /// acceptable fee by our [`ChannelCloseMinimum`] and [`NonAnchorChannelFee`] fees, with the upper bound increased by
1303 /// this value. Because the on-chain fee we'd pay to force-close the channel is kept near our
1304 /// [`NonAnchorChannelFee`] feerate during normal operation, this value represents the additional fee we're
1305 /// willing to pay in order to avoid waiting for our counterparty's to_self_delay to reclaim our
1306 /// funds.
1307 ///
1308 /// When we are not the funder, we require the closing transaction fee pay at least our
1309 /// [`ChannelCloseMinimum`] fee estimate, but allow our counterparty to pay as much fee as they like.
1310 /// Thus, this value is ignored when we are not the funder.
1311 ///
1312 /// Default value: 1000 satoshis.
1313 ///
1314 /// [`NonAnchorChannelFee`]: crate::chain::chaininterface::ConfirmationTarget::NonAnchorChannelFee
1315 /// [`ChannelCloseMinimum`]: crate::chain::chaininterface::ConfirmationTarget::ChannelCloseMinimum
1316 #[no_mangle]
1317 pub extern "C" fn ChannelConfig_get_force_close_avoidance_max_fee_satoshis(this_ptr: &ChannelConfig) -> u64 {
1318         let mut inner_val = &mut this_ptr.get_native_mut_ref().force_close_avoidance_max_fee_satoshis;
1319         *inner_val
1320 }
1321 /// The additional fee we're willing to pay to avoid waiting for the counterparty's
1322 /// `to_self_delay` to reclaim funds.
1323 ///
1324 /// When we close a channel cooperatively with our counterparty, we negotiate a fee for the
1325 /// closing transaction which both sides find acceptable, ultimately paid by the channel
1326 /// funder/initiator.
1327 ///
1328 /// When we are the funder, because we have to pay the channel closing fee, we bound the
1329 /// acceptable fee by our [`ChannelCloseMinimum`] and [`NonAnchorChannelFee`] fees, with the upper bound increased by
1330 /// this value. Because the on-chain fee we'd pay to force-close the channel is kept near our
1331 /// [`NonAnchorChannelFee`] feerate during normal operation, this value represents the additional fee we're
1332 /// willing to pay in order to avoid waiting for our counterparty's to_self_delay to reclaim our
1333 /// funds.
1334 ///
1335 /// When we are not the funder, we require the closing transaction fee pay at least our
1336 /// [`ChannelCloseMinimum`] fee estimate, but allow our counterparty to pay as much fee as they like.
1337 /// Thus, this value is ignored when we are not the funder.
1338 ///
1339 /// Default value: 1000 satoshis.
1340 ///
1341 /// [`NonAnchorChannelFee`]: crate::chain::chaininterface::ConfirmationTarget::NonAnchorChannelFee
1342 /// [`ChannelCloseMinimum`]: crate::chain::chaininterface::ConfirmationTarget::ChannelCloseMinimum
1343 #[no_mangle]
1344 pub extern "C" fn ChannelConfig_set_force_close_avoidance_max_fee_satoshis(this_ptr: &mut ChannelConfig, mut val: u64) {
1345         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.force_close_avoidance_max_fee_satoshis = val;
1346 }
1347 /// If set, allows this channel's counterparty to skim an additional fee off this node's inbound
1348 /// HTLCs. Useful for liquidity providers to offload on-chain channel costs to end users.
1349 ///
1350 /// Usage:
1351 /// - The payee will set this option and set its invoice route hints to use [intercept scids]
1352 ///   generated by this channel's counterparty.
1353 /// - The counterparty will get an [`HTLCIntercepted`] event upon payment forward, and call
1354 ///   [`forward_intercepted_htlc`] with less than the amount provided in
1355 ///   [`HTLCIntercepted::expected_outbound_amount_msat`]. The difference between the expected and
1356 ///   actual forward amounts is their fee. See
1357 ///   <https://github.com/BitcoinAndLightningLayerSpecs/lsp/tree/main/LSPS2#flow-lsp-trusts-client-model>
1358 ///   for how this feature may be used in the LSP use case.
1359 ///
1360 /// # Note
1361 /// It's important for payee wallet software to verify that [`PaymentClaimable::amount_msat`] is
1362 /// as-expected if this feature is activated, otherwise they may lose money!
1363 /// [`PaymentClaimable::counterparty_skimmed_fee_msat`] provides the fee taken by the
1364 /// counterparty.
1365 ///
1366 /// # Note
1367 /// Switching this config flag on may break compatibility with versions of LDK prior to 0.0.116.
1368 /// Unsetting this flag between restarts may lead to payment receive failures.
1369 ///
1370 /// Default value: false.
1371 ///
1372 /// [intercept scids]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
1373 /// [`forward_intercepted_htlc`]: crate::ln::channelmanager::ChannelManager::forward_intercepted_htlc
1374 /// [`HTLCIntercepted`]: crate::events::Event::HTLCIntercepted
1375 /// [`HTLCIntercepted::expected_outbound_amount_msat`]: crate::events::Event::HTLCIntercepted::expected_outbound_amount_msat
1376 /// [`PaymentClaimable::amount_msat`]: crate::events::Event::PaymentClaimable::amount_msat
1377 /// [`PaymentClaimable::counterparty_skimmed_fee_msat`]: crate::events::Event::PaymentClaimable::counterparty_skimmed_fee_msat
1378 #[no_mangle]
1379 pub extern "C" fn ChannelConfig_get_accept_underpaying_htlcs(this_ptr: &ChannelConfig) -> bool {
1380         let mut inner_val = &mut this_ptr.get_native_mut_ref().accept_underpaying_htlcs;
1381         *inner_val
1382 }
1383 /// If set, allows this channel's counterparty to skim an additional fee off this node's inbound
1384 /// HTLCs. Useful for liquidity providers to offload on-chain channel costs to end users.
1385 ///
1386 /// Usage:
1387 /// - The payee will set this option and set its invoice route hints to use [intercept scids]
1388 ///   generated by this channel's counterparty.
1389 /// - The counterparty will get an [`HTLCIntercepted`] event upon payment forward, and call
1390 ///   [`forward_intercepted_htlc`] with less than the amount provided in
1391 ///   [`HTLCIntercepted::expected_outbound_amount_msat`]. The difference between the expected and
1392 ///   actual forward amounts is their fee. See
1393 ///   <https://github.com/BitcoinAndLightningLayerSpecs/lsp/tree/main/LSPS2#flow-lsp-trusts-client-model>
1394 ///   for how this feature may be used in the LSP use case.
1395 ///
1396 /// # Note
1397 /// It's important for payee wallet software to verify that [`PaymentClaimable::amount_msat`] is
1398 /// as-expected if this feature is activated, otherwise they may lose money!
1399 /// [`PaymentClaimable::counterparty_skimmed_fee_msat`] provides the fee taken by the
1400 /// counterparty.
1401 ///
1402 /// # Note
1403 /// Switching this config flag on may break compatibility with versions of LDK prior to 0.0.116.
1404 /// Unsetting this flag between restarts may lead to payment receive failures.
1405 ///
1406 /// Default value: false.
1407 ///
1408 /// [intercept scids]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
1409 /// [`forward_intercepted_htlc`]: crate::ln::channelmanager::ChannelManager::forward_intercepted_htlc
1410 /// [`HTLCIntercepted`]: crate::events::Event::HTLCIntercepted
1411 /// [`HTLCIntercepted::expected_outbound_amount_msat`]: crate::events::Event::HTLCIntercepted::expected_outbound_amount_msat
1412 /// [`PaymentClaimable::amount_msat`]: crate::events::Event::PaymentClaimable::amount_msat
1413 /// [`PaymentClaimable::counterparty_skimmed_fee_msat`]: crate::events::Event::PaymentClaimable::counterparty_skimmed_fee_msat
1414 #[no_mangle]
1415 pub extern "C" fn ChannelConfig_set_accept_underpaying_htlcs(this_ptr: &mut ChannelConfig, mut val: bool) {
1416         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.accept_underpaying_htlcs = val;
1417 }
1418 /// Constructs a new ChannelConfig given each field
1419 #[must_use]
1420 #[no_mangle]
1421 pub extern "C" fn ChannelConfig_new(mut forwarding_fee_proportional_millionths_arg: u32, mut forwarding_fee_base_msat_arg: u32, mut cltv_expiry_delta_arg: u16, mut max_dust_htlc_exposure_arg: crate::lightning::util::config::MaxDustHTLCExposure, mut force_close_avoidance_max_fee_satoshis_arg: u64, mut accept_underpaying_htlcs_arg: bool) -> ChannelConfig {
1422         ChannelConfig { inner: ObjOps::heap_alloc(nativeChannelConfig {
1423                 forwarding_fee_proportional_millionths: forwarding_fee_proportional_millionths_arg,
1424                 forwarding_fee_base_msat: forwarding_fee_base_msat_arg,
1425                 cltv_expiry_delta: cltv_expiry_delta_arg,
1426                 max_dust_htlc_exposure: max_dust_htlc_exposure_arg.into_native(),
1427                 force_close_avoidance_max_fee_satoshis: force_close_avoidance_max_fee_satoshis_arg,
1428                 accept_underpaying_htlcs: accept_underpaying_htlcs_arg,
1429         }), is_owned: true }
1430 }
1431 impl Clone for ChannelConfig {
1432         fn clone(&self) -> Self {
1433                 Self {
1434                         inner: if <*mut nativeChannelConfig>::is_null(self.inner) { core::ptr::null_mut() } else {
1435                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1436                         is_owned: true,
1437                 }
1438         }
1439 }
1440 #[allow(unused)]
1441 /// Used only if an object of this type is returned as a trait impl by a method
1442 pub(crate) extern "C" fn ChannelConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
1443         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelConfig)).clone() })) as *mut c_void
1444 }
1445 #[no_mangle]
1446 /// Creates a copy of the ChannelConfig
1447 pub extern "C" fn ChannelConfig_clone(orig: &ChannelConfig) -> ChannelConfig {
1448         orig.clone()
1449 }
1450 /// Get a string which allows debug introspection of a ChannelConfig object
1451 pub extern "C" fn ChannelConfig_debug_str_void(o: *const c_void) -> Str {
1452         alloc::format!("{:?}", unsafe { o as *const crate::lightning::util::config::ChannelConfig }).into()}
1453 /// Checks if two ChannelConfigs contain equal inner contents.
1454 /// This ignores pointers and is_owned flags and looks at the values in fields.
1455 /// Two objects with NULL inner values will be considered "equal" here.
1456 #[no_mangle]
1457 pub extern "C" fn ChannelConfig_eq(a: &ChannelConfig, b: &ChannelConfig) -> bool {
1458         if a.inner == b.inner { return true; }
1459         if a.inner.is_null() || b.inner.is_null() { return false; }
1460         if a.get_native_ref() == b.get_native_ref() { true } else { false }
1461 }
1462 /// Applies the given [`ChannelConfigUpdate`] as a partial update to the [`ChannelConfig`].
1463 #[no_mangle]
1464 pub extern "C" fn ChannelConfig_apply(this_arg: &mut crate::lightning::util::config::ChannelConfig, update: &crate::lightning::util::config::ChannelConfigUpdate) {
1465         unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::util::config::nativeChannelConfig)) }.apply(update.get_native_ref())
1466 }
1467
1468 /// Creates a "default" ChannelConfig. See struct and individual field documentaiton for details on which values are used.
1469 #[must_use]
1470 #[no_mangle]
1471 pub extern "C" fn ChannelConfig_default() -> ChannelConfig {
1472         ChannelConfig { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
1473 }
1474 #[no_mangle]
1475 /// Serialize the ChannelConfig object into a byte array which can be read by ChannelConfig_read
1476 pub extern "C" fn ChannelConfig_write(obj: &crate::lightning::util::config::ChannelConfig) -> crate::c_types::derived::CVec_u8Z {
1477         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1478 }
1479 #[allow(unused)]
1480 pub(crate) extern "C" fn ChannelConfig_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1481         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelConfig) })
1482 }
1483 #[no_mangle]
1484 /// Read a ChannelConfig from a byte array, created by ChannelConfig_write
1485 pub extern "C" fn ChannelConfig_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelConfigDecodeErrorZ {
1486         let res: Result<lightning::util::config::ChannelConfig, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1487         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::util::config::ChannelConfig { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1488         local_res
1489 }
1490
1491 use lightning::util::config::ChannelConfigUpdate as nativeChannelConfigUpdateImport;
1492 pub(crate) type nativeChannelConfigUpdate = nativeChannelConfigUpdateImport;
1493
1494 /// A parallel struct to [`ChannelConfig`] to define partial updates.
1495 #[must_use]
1496 #[repr(C)]
1497 pub struct ChannelConfigUpdate {
1498         /// A pointer to the opaque Rust object.
1499
1500         /// Nearly everywhere, inner must be non-null, however in places where
1501         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1502         pub inner: *mut nativeChannelConfigUpdate,
1503         /// Indicates that this is the only struct which contains the same pointer.
1504
1505         /// Rust functions which take ownership of an object provided via an argument require
1506         /// this to be true and invalidate the object pointed to by inner.
1507         pub is_owned: bool,
1508 }
1509
1510 impl Drop for ChannelConfigUpdate {
1511         fn drop(&mut self) {
1512                 if self.is_owned && !<*mut nativeChannelConfigUpdate>::is_null(self.inner) {
1513                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1514                 }
1515         }
1516 }
1517 /// Frees any resources used by the ChannelConfigUpdate, if is_owned is set and inner is non-NULL.
1518 #[no_mangle]
1519 pub extern "C" fn ChannelConfigUpdate_free(this_obj: ChannelConfigUpdate) { }
1520 #[allow(unused)]
1521 /// Used only if an object of this type is returned as a trait impl by a method
1522 pub(crate) extern "C" fn ChannelConfigUpdate_free_void(this_ptr: *mut c_void) {
1523         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelConfigUpdate) };
1524 }
1525 #[allow(unused)]
1526 impl ChannelConfigUpdate {
1527         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelConfigUpdate {
1528                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1529         }
1530         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelConfigUpdate {
1531                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1532         }
1533         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1534         pub(crate) fn take_inner(mut self) -> *mut nativeChannelConfigUpdate {
1535                 assert!(self.is_owned);
1536                 let ret = ObjOps::untweak_ptr(self.inner);
1537                 self.inner = core::ptr::null_mut();
1538                 ret
1539         }
1540 }
1541 #[no_mangle]
1542 pub extern "C" fn ChannelConfigUpdate_get_forwarding_fee_proportional_millionths(this_ptr: &ChannelConfigUpdate) -> crate::c_types::derived::COption_u32Z {
1543         let mut inner_val = &mut this_ptr.get_native_mut_ref().forwarding_fee_proportional_millionths;
1544         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u32Z::None } else { crate::c_types::derived::COption_u32Z::Some( { inner_val.unwrap() }) };
1545         local_inner_val
1546 }
1547 #[no_mangle]
1548 pub extern "C" fn ChannelConfigUpdate_set_forwarding_fee_proportional_millionths(this_ptr: &mut ChannelConfigUpdate, mut val: crate::c_types::derived::COption_u32Z) {
1549         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1550         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.forwarding_fee_proportional_millionths = local_val;
1551 }
1552 #[no_mangle]
1553 pub extern "C" fn ChannelConfigUpdate_get_forwarding_fee_base_msat(this_ptr: &ChannelConfigUpdate) -> crate::c_types::derived::COption_u32Z {
1554         let mut inner_val = &mut this_ptr.get_native_mut_ref().forwarding_fee_base_msat;
1555         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u32Z::None } else { crate::c_types::derived::COption_u32Z::Some( { inner_val.unwrap() }) };
1556         local_inner_val
1557 }
1558 #[no_mangle]
1559 pub extern "C" fn ChannelConfigUpdate_set_forwarding_fee_base_msat(this_ptr: &mut ChannelConfigUpdate, mut val: crate::c_types::derived::COption_u32Z) {
1560         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1561         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.forwarding_fee_base_msat = local_val;
1562 }
1563 #[no_mangle]
1564 pub extern "C" fn ChannelConfigUpdate_get_cltv_expiry_delta(this_ptr: &ChannelConfigUpdate) -> crate::c_types::derived::COption_u16Z {
1565         let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
1566         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u16Z::None } else { crate::c_types::derived::COption_u16Z::Some( { inner_val.unwrap() }) };
1567         local_inner_val
1568 }
1569 #[no_mangle]
1570 pub extern "C" fn ChannelConfigUpdate_set_cltv_expiry_delta(this_ptr: &mut ChannelConfigUpdate, mut val: crate::c_types::derived::COption_u16Z) {
1571         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1572         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = local_val;
1573 }
1574 ///
1575 /// Returns a copy of the field.
1576 #[no_mangle]
1577 pub extern "C" fn ChannelConfigUpdate_get_max_dust_htlc_exposure_msat(this_ptr: &ChannelConfigUpdate) -> crate::c_types::derived::COption_MaxDustHTLCExposureZ {
1578         let mut inner_val = this_ptr.get_native_mut_ref().max_dust_htlc_exposure_msat.clone();
1579         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_MaxDustHTLCExposureZ::None } else { crate::c_types::derived::COption_MaxDustHTLCExposureZ::Some( { crate::lightning::util::config::MaxDustHTLCExposure::native_into(inner_val.unwrap()) }) };
1580         local_inner_val
1581 }
1582 #[no_mangle]
1583 pub extern "C" fn ChannelConfigUpdate_set_max_dust_htlc_exposure_msat(this_ptr: &mut ChannelConfigUpdate, mut val: crate::c_types::derived::COption_MaxDustHTLCExposureZ) {
1584         let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { { val_opt.take() }.into_native() }})} };
1585         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_dust_htlc_exposure_msat = local_val;
1586 }
1587 #[no_mangle]
1588 pub extern "C" fn ChannelConfigUpdate_get_force_close_avoidance_max_fee_satoshis(this_ptr: &ChannelConfigUpdate) -> crate::c_types::derived::COption_u64Z {
1589         let mut inner_val = &mut this_ptr.get_native_mut_ref().force_close_avoidance_max_fee_satoshis;
1590         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) };
1591         local_inner_val
1592 }
1593 #[no_mangle]
1594 pub extern "C" fn ChannelConfigUpdate_set_force_close_avoidance_max_fee_satoshis(this_ptr: &mut ChannelConfigUpdate, mut val: crate::c_types::derived::COption_u64Z) {
1595         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1596         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.force_close_avoidance_max_fee_satoshis = local_val;
1597 }
1598 /// Constructs a new ChannelConfigUpdate given each field
1599 #[must_use]
1600 #[no_mangle]
1601 pub extern "C" fn ChannelConfigUpdate_new(mut forwarding_fee_proportional_millionths_arg: crate::c_types::derived::COption_u32Z, mut forwarding_fee_base_msat_arg: crate::c_types::derived::COption_u32Z, mut cltv_expiry_delta_arg: crate::c_types::derived::COption_u16Z, mut max_dust_htlc_exposure_msat_arg: crate::c_types::derived::COption_MaxDustHTLCExposureZ, mut force_close_avoidance_max_fee_satoshis_arg: crate::c_types::derived::COption_u64Z) -> ChannelConfigUpdate {
1602         let mut local_forwarding_fee_proportional_millionths_arg = if forwarding_fee_proportional_millionths_arg.is_some() { Some( { forwarding_fee_proportional_millionths_arg.take() }) } else { None };
1603         let mut local_forwarding_fee_base_msat_arg = if forwarding_fee_base_msat_arg.is_some() { Some( { forwarding_fee_base_msat_arg.take() }) } else { None };
1604         let mut local_cltv_expiry_delta_arg = if cltv_expiry_delta_arg.is_some() { Some( { cltv_expiry_delta_arg.take() }) } else { None };
1605         let mut local_max_dust_htlc_exposure_msat_arg = { /*max_dust_htlc_exposure_msat_arg*/ let max_dust_htlc_exposure_msat_arg_opt = max_dust_htlc_exposure_msat_arg; if max_dust_htlc_exposure_msat_arg_opt.is_none() { None } else { Some({ { { max_dust_htlc_exposure_msat_arg_opt.take() }.into_native() }})} };
1606         let mut local_force_close_avoidance_max_fee_satoshis_arg = if force_close_avoidance_max_fee_satoshis_arg.is_some() { Some( { force_close_avoidance_max_fee_satoshis_arg.take() }) } else { None };
1607         ChannelConfigUpdate { inner: ObjOps::heap_alloc(nativeChannelConfigUpdate {
1608                 forwarding_fee_proportional_millionths: local_forwarding_fee_proportional_millionths_arg,
1609                 forwarding_fee_base_msat: local_forwarding_fee_base_msat_arg,
1610                 cltv_expiry_delta: local_cltv_expiry_delta_arg,
1611                 max_dust_htlc_exposure_msat: local_max_dust_htlc_exposure_msat_arg,
1612                 force_close_avoidance_max_fee_satoshis: local_force_close_avoidance_max_fee_satoshis_arg,
1613         }), is_owned: true }
1614 }
1615 /// Creates a "default" ChannelConfigUpdate. See struct and individual field documentaiton for details on which values are used.
1616 #[must_use]
1617 #[no_mangle]
1618 pub extern "C" fn ChannelConfigUpdate_default() -> ChannelConfigUpdate {
1619         ChannelConfigUpdate { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
1620 }
1621
1622 use lightning::util::config::UserConfig as nativeUserConfigImport;
1623 pub(crate) type nativeUserConfig = nativeUserConfigImport;
1624
1625 /// Top-level config which holds ChannelHandshakeLimits and ChannelConfig.
1626 ///
1627 /// Default::default() provides sane defaults for most configurations
1628 /// (but currently with 0 relay fees!)
1629 #[must_use]
1630 #[repr(C)]
1631 pub struct UserConfig {
1632         /// A pointer to the opaque Rust object.
1633
1634         /// Nearly everywhere, inner must be non-null, however in places where
1635         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1636         pub inner: *mut nativeUserConfig,
1637         /// Indicates that this is the only struct which contains the same pointer.
1638
1639         /// Rust functions which take ownership of an object provided via an argument require
1640         /// this to be true and invalidate the object pointed to by inner.
1641         pub is_owned: bool,
1642 }
1643
1644 impl Drop for UserConfig {
1645         fn drop(&mut self) {
1646                 if self.is_owned && !<*mut nativeUserConfig>::is_null(self.inner) {
1647                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1648                 }
1649         }
1650 }
1651 /// Frees any resources used by the UserConfig, if is_owned is set and inner is non-NULL.
1652 #[no_mangle]
1653 pub extern "C" fn UserConfig_free(this_obj: UserConfig) { }
1654 #[allow(unused)]
1655 /// Used only if an object of this type is returned as a trait impl by a method
1656 pub(crate) extern "C" fn UserConfig_free_void(this_ptr: *mut c_void) {
1657         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeUserConfig) };
1658 }
1659 #[allow(unused)]
1660 impl UserConfig {
1661         pub(crate) fn get_native_ref(&self) -> &'static nativeUserConfig {
1662                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1663         }
1664         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeUserConfig {
1665                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1666         }
1667         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1668         pub(crate) fn take_inner(mut self) -> *mut nativeUserConfig {
1669                 assert!(self.is_owned);
1670                 let ret = ObjOps::untweak_ptr(self.inner);
1671                 self.inner = core::ptr::null_mut();
1672                 ret
1673         }
1674 }
1675 /// Channel handshake config that we propose to our counterparty.
1676 #[no_mangle]
1677 pub extern "C" fn UserConfig_get_channel_handshake_config(this_ptr: &UserConfig) -> crate::lightning::util::config::ChannelHandshakeConfig {
1678         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_handshake_config;
1679         crate::lightning::util::config::ChannelHandshakeConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::util::config::ChannelHandshakeConfig<>) as *mut _) }, is_owned: false }
1680 }
1681 /// Channel handshake config that we propose to our counterparty.
1682 #[no_mangle]
1683 pub extern "C" fn UserConfig_set_channel_handshake_config(this_ptr: &mut UserConfig, mut val: crate::lightning::util::config::ChannelHandshakeConfig) {
1684         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_handshake_config = *unsafe { Box::from_raw(val.take_inner()) };
1685 }
1686 /// Limits applied to our counterparty's proposed channel handshake config settings.
1687 #[no_mangle]
1688 pub extern "C" fn UserConfig_get_channel_handshake_limits(this_ptr: &UserConfig) -> crate::lightning::util::config::ChannelHandshakeLimits {
1689         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_handshake_limits;
1690         crate::lightning::util::config::ChannelHandshakeLimits { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::util::config::ChannelHandshakeLimits<>) as *mut _) }, is_owned: false }
1691 }
1692 /// Limits applied to our counterparty's proposed channel handshake config settings.
1693 #[no_mangle]
1694 pub extern "C" fn UserConfig_set_channel_handshake_limits(this_ptr: &mut UserConfig, mut val: crate::lightning::util::config::ChannelHandshakeLimits) {
1695         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_handshake_limits = *unsafe { Box::from_raw(val.take_inner()) };
1696 }
1697 /// Channel config which affects behavior during channel lifetime.
1698 #[no_mangle]
1699 pub extern "C" fn UserConfig_get_channel_config(this_ptr: &UserConfig) -> crate::lightning::util::config::ChannelConfig {
1700         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_config;
1701         crate::lightning::util::config::ChannelConfig { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::util::config::ChannelConfig<>) as *mut _) }, is_owned: false }
1702 }
1703 /// Channel config which affects behavior during channel lifetime.
1704 #[no_mangle]
1705 pub extern "C" fn UserConfig_set_channel_config(this_ptr: &mut UserConfig, mut val: crate::lightning::util::config::ChannelConfig) {
1706         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_config = *unsafe { Box::from_raw(val.take_inner()) };
1707 }
1708 /// If this is set to false, we will reject any HTLCs which were to be forwarded over private
1709 /// channels. This prevents us from taking on HTLC-forwarding risk when we intend to run as a
1710 /// node which is not online reliably.
1711 ///
1712 /// For nodes which are not online reliably, you should set all channels to *not* be announced
1713 /// (using [`ChannelHandshakeConfig::announced_channel`] and
1714 /// [`ChannelHandshakeLimits::force_announced_channel_preference`]) and set this to false to
1715 /// ensure you are not exposed to any forwarding risk.
1716 ///
1717 /// Note that because you cannot change a channel's announced state after creation, there is no
1718 /// way to disable forwarding on public channels retroactively. Thus, in order to change a node
1719 /// from a publicly-announced forwarding node to a private non-forwarding node you must close
1720 /// all your channels and open new ones. For privacy, you should also change your node_id
1721 /// (swapping all private and public key material for new ones) at that time.
1722 ///
1723 /// Default value: false.
1724 #[no_mangle]
1725 pub extern "C" fn UserConfig_get_accept_forwards_to_priv_channels(this_ptr: &UserConfig) -> bool {
1726         let mut inner_val = &mut this_ptr.get_native_mut_ref().accept_forwards_to_priv_channels;
1727         *inner_val
1728 }
1729 /// If this is set to false, we will reject any HTLCs which were to be forwarded over private
1730 /// channels. This prevents us from taking on HTLC-forwarding risk when we intend to run as a
1731 /// node which is not online reliably.
1732 ///
1733 /// For nodes which are not online reliably, you should set all channels to *not* be announced
1734 /// (using [`ChannelHandshakeConfig::announced_channel`] and
1735 /// [`ChannelHandshakeLimits::force_announced_channel_preference`]) and set this to false to
1736 /// ensure you are not exposed to any forwarding risk.
1737 ///
1738 /// Note that because you cannot change a channel's announced state after creation, there is no
1739 /// way to disable forwarding on public channels retroactively. Thus, in order to change a node
1740 /// from a publicly-announced forwarding node to a private non-forwarding node you must close
1741 /// all your channels and open new ones. For privacy, you should also change your node_id
1742 /// (swapping all private and public key material for new ones) at that time.
1743 ///
1744 /// Default value: false.
1745 #[no_mangle]
1746 pub extern "C" fn UserConfig_set_accept_forwards_to_priv_channels(this_ptr: &mut UserConfig, mut val: bool) {
1747         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.accept_forwards_to_priv_channels = val;
1748 }
1749 /// If this is set to false, we do not accept inbound requests to open a new channel.
1750 /// Default value: true.
1751 #[no_mangle]
1752 pub extern "C" fn UserConfig_get_accept_inbound_channels(this_ptr: &UserConfig) -> bool {
1753         let mut inner_val = &mut this_ptr.get_native_mut_ref().accept_inbound_channels;
1754         *inner_val
1755 }
1756 /// If this is set to false, we do not accept inbound requests to open a new channel.
1757 /// Default value: true.
1758 #[no_mangle]
1759 pub extern "C" fn UserConfig_set_accept_inbound_channels(this_ptr: &mut UserConfig, mut val: bool) {
1760         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.accept_inbound_channels = val;
1761 }
1762 /// If this is set to true, the user needs to manually accept inbound requests to open a new
1763 /// channel.
1764 ///
1765 /// When set to true, [`Event::OpenChannelRequest`] will be triggered once a request to open a
1766 /// new inbound channel is received through a [`msgs::OpenChannel`] message. In that case, a
1767 /// [`msgs::AcceptChannel`] message will not be sent back to the counterparty node unless the
1768 /// user explicitly chooses to accept the request.
1769 ///
1770 /// Default value: false.
1771 ///
1772 /// [`Event::OpenChannelRequest`]: crate::events::Event::OpenChannelRequest
1773 /// [`msgs::OpenChannel`]: crate::ln::msgs::OpenChannel
1774 /// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
1775 #[no_mangle]
1776 pub extern "C" fn UserConfig_get_manually_accept_inbound_channels(this_ptr: &UserConfig) -> bool {
1777         let mut inner_val = &mut this_ptr.get_native_mut_ref().manually_accept_inbound_channels;
1778         *inner_val
1779 }
1780 /// If this is set to true, the user needs to manually accept inbound requests to open a new
1781 /// channel.
1782 ///
1783 /// When set to true, [`Event::OpenChannelRequest`] will be triggered once a request to open a
1784 /// new inbound channel is received through a [`msgs::OpenChannel`] message. In that case, a
1785 /// [`msgs::AcceptChannel`] message will not be sent back to the counterparty node unless the
1786 /// user explicitly chooses to accept the request.
1787 ///
1788 /// Default value: false.
1789 ///
1790 /// [`Event::OpenChannelRequest`]: crate::events::Event::OpenChannelRequest
1791 /// [`msgs::OpenChannel`]: crate::ln::msgs::OpenChannel
1792 /// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
1793 #[no_mangle]
1794 pub extern "C" fn UserConfig_set_manually_accept_inbound_channels(this_ptr: &mut UserConfig, mut val: bool) {
1795         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.manually_accept_inbound_channels = val;
1796 }
1797 ///  If this is set to true, LDK will intercept HTLCs that are attempting to be forwarded over
1798 ///  fake short channel ids generated via [`ChannelManager::get_intercept_scid`]. Upon HTLC
1799 ///  intercept, LDK will generate an [`Event::HTLCIntercepted`] which MUST be handled by the user.
1800 ///
1801 ///  Setting this to true may break backwards compatibility with LDK versions < 0.0.113.
1802 ///
1803 ///  Default value: false.
1804 ///
1805 /// [`ChannelManager::get_intercept_scid`]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
1806 /// [`Event::HTLCIntercepted`]: crate::events::Event::HTLCIntercepted
1807 #[no_mangle]
1808 pub extern "C" fn UserConfig_get_accept_intercept_htlcs(this_ptr: &UserConfig) -> bool {
1809         let mut inner_val = &mut this_ptr.get_native_mut_ref().accept_intercept_htlcs;
1810         *inner_val
1811 }
1812 ///  If this is set to true, LDK will intercept HTLCs that are attempting to be forwarded over
1813 ///  fake short channel ids generated via [`ChannelManager::get_intercept_scid`]. Upon HTLC
1814 ///  intercept, LDK will generate an [`Event::HTLCIntercepted`] which MUST be handled by the user.
1815 ///
1816 ///  Setting this to true may break backwards compatibility with LDK versions < 0.0.113.
1817 ///
1818 ///  Default value: false.
1819 ///
1820 /// [`ChannelManager::get_intercept_scid`]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
1821 /// [`Event::HTLCIntercepted`]: crate::events::Event::HTLCIntercepted
1822 #[no_mangle]
1823 pub extern "C" fn UserConfig_set_accept_intercept_htlcs(this_ptr: &mut UserConfig, mut val: bool) {
1824         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.accept_intercept_htlcs = val;
1825 }
1826 /// If this is set to false, when receiving a keysend payment we'll fail it if it has multiple
1827 /// parts. If this is set to true, we'll accept the payment.
1828 ///
1829 /// Setting this to true will break backwards compatibility upon downgrading to an LDK
1830 /// version < 0.0.116 while receiving an MPP keysend. If we have already received an MPP
1831 /// keysend, downgrading will cause us to fail to deserialize [`ChannelManager`].
1832 ///
1833 /// Default value: false.
1834 ///
1835 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
1836 #[no_mangle]
1837 pub extern "C" fn UserConfig_get_accept_mpp_keysend(this_ptr: &UserConfig) -> bool {
1838         let mut inner_val = &mut this_ptr.get_native_mut_ref().accept_mpp_keysend;
1839         *inner_val
1840 }
1841 /// If this is set to false, when receiving a keysend payment we'll fail it if it has multiple
1842 /// parts. If this is set to true, we'll accept the payment.
1843 ///
1844 /// Setting this to true will break backwards compatibility upon downgrading to an LDK
1845 /// version < 0.0.116 while receiving an MPP keysend. If we have already received an MPP
1846 /// keysend, downgrading will cause us to fail to deserialize [`ChannelManager`].
1847 ///
1848 /// Default value: false.
1849 ///
1850 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
1851 #[no_mangle]
1852 pub extern "C" fn UserConfig_set_accept_mpp_keysend(this_ptr: &mut UserConfig, mut val: bool) {
1853         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.accept_mpp_keysend = val;
1854 }
1855 /// Constructs a new UserConfig given each field
1856 #[must_use]
1857 #[no_mangle]
1858 pub extern "C" fn UserConfig_new(mut channel_handshake_config_arg: crate::lightning::util::config::ChannelHandshakeConfig, mut channel_handshake_limits_arg: crate::lightning::util::config::ChannelHandshakeLimits, mut channel_config_arg: crate::lightning::util::config::ChannelConfig, mut accept_forwards_to_priv_channels_arg: bool, mut accept_inbound_channels_arg: bool, mut manually_accept_inbound_channels_arg: bool, mut accept_intercept_htlcs_arg: bool, mut accept_mpp_keysend_arg: bool) -> UserConfig {
1859         UserConfig { inner: ObjOps::heap_alloc(nativeUserConfig {
1860                 channel_handshake_config: *unsafe { Box::from_raw(channel_handshake_config_arg.take_inner()) },
1861                 channel_handshake_limits: *unsafe { Box::from_raw(channel_handshake_limits_arg.take_inner()) },
1862                 channel_config: *unsafe { Box::from_raw(channel_config_arg.take_inner()) },
1863                 accept_forwards_to_priv_channels: accept_forwards_to_priv_channels_arg,
1864                 accept_inbound_channels: accept_inbound_channels_arg,
1865                 manually_accept_inbound_channels: manually_accept_inbound_channels_arg,
1866                 accept_intercept_htlcs: accept_intercept_htlcs_arg,
1867                 accept_mpp_keysend: accept_mpp_keysend_arg,
1868         }), is_owned: true }
1869 }
1870 impl Clone for UserConfig {
1871         fn clone(&self) -> Self {
1872                 Self {
1873                         inner: if <*mut nativeUserConfig>::is_null(self.inner) { core::ptr::null_mut() } else {
1874                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1875                         is_owned: true,
1876                 }
1877         }
1878 }
1879 #[allow(unused)]
1880 /// Used only if an object of this type is returned as a trait impl by a method
1881 pub(crate) extern "C" fn UserConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
1882         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUserConfig)).clone() })) as *mut c_void
1883 }
1884 #[no_mangle]
1885 /// Creates a copy of the UserConfig
1886 pub extern "C" fn UserConfig_clone(orig: &UserConfig) -> UserConfig {
1887         orig.clone()
1888 }
1889 /// Get a string which allows debug introspection of a UserConfig object
1890 pub extern "C" fn UserConfig_debug_str_void(o: *const c_void) -> Str {
1891         alloc::format!("{:?}", unsafe { o as *const crate::lightning::util::config::UserConfig }).into()}
1892 /// Creates a "default" UserConfig. See struct and individual field documentaiton for details on which values are used.
1893 #[must_use]
1894 #[no_mangle]
1895 pub extern "C" fn UserConfig_default() -> UserConfig {
1896         UserConfig { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
1897 }