1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
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.
9 //! Various user-configurable channel limits and settings which ChannelManager
12 use alloc::str::FromStr;
13 use core::ffi::c_void;
14 use core::convert::Infallible;
15 use bitcoin::hashes::Hash;
16 use crate::c_types::*;
17 #[cfg(feature="no-std")]
18 use alloc::{vec::Vec, boxed::Box};
21 use lightning::util::config::ChannelHandshakeConfig as nativeChannelHandshakeConfigImport;
22 pub(crate) type nativeChannelHandshakeConfig = nativeChannelHandshakeConfigImport;
24 /// Configuration we set when applicable.
26 /// Default::default() provides sane defaults.
29 pub struct ChannelHandshakeConfig {
30 /// A pointer to the opaque Rust object.
32 /// Nearly everywhere, inner must be non-null, however in places where
33 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
34 pub inner: *mut nativeChannelHandshakeConfig,
35 /// Indicates that this is the only struct which contains the same pointer.
37 /// Rust functions which take ownership of an object provided via an argument require
38 /// this to be true and invalidate the object pointed to by inner.
42 impl Drop for ChannelHandshakeConfig {
44 if self.is_owned && !<*mut nativeChannelHandshakeConfig>::is_null(self.inner) {
45 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
49 /// Frees any resources used by the ChannelHandshakeConfig, if is_owned is set and inner is non-NULL.
51 pub extern "C" fn ChannelHandshakeConfig_free(this_obj: ChannelHandshakeConfig) { }
53 /// Used only if an object of this type is returned as a trait impl by a method
54 pub(crate) extern "C" fn ChannelHandshakeConfig_free_void(this_ptr: *mut c_void) {
55 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelHandshakeConfig) };
58 impl ChannelHandshakeConfig {
59 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelHandshakeConfig {
60 unsafe { &*ObjOps::untweak_ptr(self.inner) }
62 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelHandshakeConfig {
63 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
65 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
66 pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeConfig {
67 assert!(self.is_owned);
68 let ret = ObjOps::untweak_ptr(self.inner);
69 self.inner = core::ptr::null_mut();
73 /// Confirmations we will wait for before considering the channel locked in.
74 /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
75 /// equivalent limit applied to outbound channels).
77 /// A lower-bound of 1 is applied, requiring all channels to have a confirmed commitment
78 /// transaction before operation. If you wish to accept channels with zero confirmations, see
79 /// [`UserConfig::manually_accept_inbound_channels`] and
80 /// [`ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`].
84 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
85 /// [`ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel_from_trusted_peer_0conf
87 pub extern "C" fn ChannelHandshakeConfig_get_minimum_depth(this_ptr: &ChannelHandshakeConfig) -> u32 {
88 let mut inner_val = &mut this_ptr.get_native_mut_ref().minimum_depth;
91 /// Confirmations we will wait for before considering the channel locked in.
92 /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
93 /// equivalent limit applied to outbound channels).
95 /// A lower-bound of 1 is applied, requiring all channels to have a confirmed commitment
96 /// transaction before operation. If you wish to accept channels with zero confirmations, see
97 /// [`UserConfig::manually_accept_inbound_channels`] and
98 /// [`ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`].
100 /// Default value: 6.
102 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
103 /// [`ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel_from_trusted_peer_0conf
105 pub extern "C" fn ChannelHandshakeConfig_set_minimum_depth(this_ptr: &mut ChannelHandshakeConfig, mut val: u32) {
106 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.minimum_depth = val;
108 /// Set to the number of blocks we require our counterparty to wait to claim their money (ie
109 /// the number of blocks we have to punish our counterparty if they broadcast a revoked
112 /// This is one of the main parameters of our security model. We (or one of our watchtowers) MUST
113 /// be online to check for revoked transactions on-chain at least once every our_to_self_delay
114 /// blocks (minus some margin to allow us enough time to broadcast and confirm a transaction,
115 /// possibly with time in between to RBF the spending transaction).
117 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
118 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
121 /// Default value: [`BREAKDOWN_TIMEOUT`], we enforce it as a minimum at channel opening so you
122 /// can tweak config to ask for more security, not less.
124 pub extern "C" fn ChannelHandshakeConfig_get_our_to_self_delay(this_ptr: &ChannelHandshakeConfig) -> u16 {
125 let mut inner_val = &mut this_ptr.get_native_mut_ref().our_to_self_delay;
128 /// Set to the number of blocks we require our counterparty to wait to claim their money (ie
129 /// the number of blocks we have to punish our counterparty if they broadcast a revoked
132 /// This is one of the main parameters of our security model. We (or one of our watchtowers) MUST
133 /// be online to check for revoked transactions on-chain at least once every our_to_self_delay
134 /// blocks (minus some margin to allow us enough time to broadcast and confirm a transaction,
135 /// possibly with time in between to RBF the spending transaction).
137 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
138 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
141 /// Default value: [`BREAKDOWN_TIMEOUT`], we enforce it as a minimum at channel opening so you
142 /// can tweak config to ask for more security, not less.
144 pub extern "C" fn ChannelHandshakeConfig_set_our_to_self_delay(this_ptr: &mut ChannelHandshakeConfig, mut val: u16) {
145 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.our_to_self_delay = val;
147 /// Set to the smallest value HTLC we will accept to process.
149 /// This value is sent to our counterparty on channel-open and we close the channel any time
150 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
152 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
155 pub extern "C" fn ChannelHandshakeConfig_get_our_htlc_minimum_msat(this_ptr: &ChannelHandshakeConfig) -> u64 {
156 let mut inner_val = &mut this_ptr.get_native_mut_ref().our_htlc_minimum_msat;
159 /// Set to the smallest value HTLC we will accept to process.
161 /// This value is sent to our counterparty on channel-open and we close the channel any time
162 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
164 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
167 pub extern "C" fn ChannelHandshakeConfig_set_our_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeConfig, mut val: u64) {
168 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.our_htlc_minimum_msat = val;
170 /// Sets the percentage of the channel value we will cap the total value of outstanding inbound
173 /// This can be set to a value between 1-100, where the value corresponds to the percent of the
174 /// channel value in whole percentages.
177 /// * If configured to another value than the default value 10, any new channels created with
178 /// the non default value will cause versions of LDK prior to 0.0.104 to refuse to read the
179 /// `ChannelManager`.
181 /// * This caps the total value for inbound HTLCs in-flight only, and there's currently
182 /// no way to configure the cap for the total value of outbound HTLCs in-flight.
184 /// * The requirements for your node being online to ensure the safety of HTLC-encumbered funds
185 /// are different from the non-HTLC-encumbered funds. This makes this an important knob to
186 /// restrict exposure to loss due to being offline for too long.
187 /// See [`ChannelHandshakeConfig::our_to_self_delay`] and [`ChannelConfig::cltv_expiry_delta`]
188 /// for more information.
190 /// Default value: 10.
191 /// Minimum value: 1, any values less than 1 will be treated as 1 instead.
192 /// Maximum value: 100, any values larger than 100 will be treated as 100 instead.
194 pub extern "C" fn ChannelHandshakeConfig_get_max_inbound_htlc_value_in_flight_percent_of_channel(this_ptr: &ChannelHandshakeConfig) -> u8 {
195 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_inbound_htlc_value_in_flight_percent_of_channel;
198 /// Sets the percentage of the channel value we will cap the total value of outstanding inbound
201 /// This can be set to a value between 1-100, where the value corresponds to the percent of the
202 /// channel value in whole percentages.
205 /// * If configured to another value than the default value 10, any new channels created with
206 /// the non default value will cause versions of LDK prior to 0.0.104 to refuse to read the
207 /// `ChannelManager`.
209 /// * This caps the total value for inbound HTLCs in-flight only, and there's currently
210 /// no way to configure the cap for the total value of outbound HTLCs in-flight.
212 /// * The requirements for your node being online to ensure the safety of HTLC-encumbered funds
213 /// are different from the non-HTLC-encumbered funds. This makes this an important knob to
214 /// restrict exposure to loss due to being offline for too long.
215 /// See [`ChannelHandshakeConfig::our_to_self_delay`] and [`ChannelConfig::cltv_expiry_delta`]
216 /// for more information.
218 /// Default value: 10.
219 /// Minimum value: 1, any values less than 1 will be treated as 1 instead.
220 /// Maximum value: 100, any values larger than 100 will be treated as 100 instead.
222 pub extern "C" fn ChannelHandshakeConfig_set_max_inbound_htlc_value_in_flight_percent_of_channel(this_ptr: &mut ChannelHandshakeConfig, mut val: u8) {
223 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_inbound_htlc_value_in_flight_percent_of_channel = val;
225 /// If set, we attempt to negotiate the `scid_privacy` (referred to as `scid_alias` in the
226 /// BOLTs) option for outbound private channels. This provides better privacy by not including
227 /// our real on-chain channel UTXO in each invoice and requiring that our counterparty only
228 /// relay HTLCs to us using the channel's SCID alias.
230 /// If this option is set, channels may be created that will not be readable by LDK versions
231 /// prior to 0.0.106, causing [`ChannelManager`]'s read method to return a
232 /// [`DecodeError::InvalidValue`].
234 /// Note that setting this to true does *not* prevent us from opening channels with
235 /// counterparties that do not support the `scid_alias` option; we will simply fall back to a
236 /// private channel without that option.
238 /// Ignored if the channel is negotiated to be announced, see
239 /// [`ChannelHandshakeConfig::announced_channel`] and
240 /// [`ChannelHandshakeLimits::force_announced_channel_preference`] for more.
242 /// Default value: false. This value is likely to change to true in the future.
244 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
245 /// [`DecodeError::InvalidValue`]: crate::ln::msgs::DecodeError::InvalidValue
247 pub extern "C" fn ChannelHandshakeConfig_get_negotiate_scid_privacy(this_ptr: &ChannelHandshakeConfig) -> bool {
248 let mut inner_val = &mut this_ptr.get_native_mut_ref().negotiate_scid_privacy;
251 /// If set, we attempt to negotiate the `scid_privacy` (referred to as `scid_alias` in the
252 /// BOLTs) option for outbound private channels. This provides better privacy by not including
253 /// our real on-chain channel UTXO in each invoice and requiring that our counterparty only
254 /// relay HTLCs to us using the channel's SCID alias.
256 /// If this option is set, channels may be created that will not be readable by LDK versions
257 /// prior to 0.0.106, causing [`ChannelManager`]'s read method to return a
258 /// [`DecodeError::InvalidValue`].
260 /// Note that setting this to true does *not* prevent us from opening channels with
261 /// counterparties that do not support the `scid_alias` option; we will simply fall back to a
262 /// private channel without that option.
264 /// Ignored if the channel is negotiated to be announced, see
265 /// [`ChannelHandshakeConfig::announced_channel`] and
266 /// [`ChannelHandshakeLimits::force_announced_channel_preference`] for more.
268 /// Default value: false. This value is likely to change to true in the future.
270 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
271 /// [`DecodeError::InvalidValue`]: crate::ln::msgs::DecodeError::InvalidValue
273 pub extern "C" fn ChannelHandshakeConfig_set_negotiate_scid_privacy(this_ptr: &mut ChannelHandshakeConfig, mut val: bool) {
274 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.negotiate_scid_privacy = val;
276 /// Set to announce the channel publicly and notify all nodes that they can route via this
279 /// This should only be set to true for nodes which expect to be online reliably.
281 /// As the node which funds a channel picks this value this will only apply for new outbound
282 /// channels unless [`ChannelHandshakeLimits::force_announced_channel_preference`] is set.
284 /// Default value: false.
286 pub extern "C" fn ChannelHandshakeConfig_get_announced_channel(this_ptr: &ChannelHandshakeConfig) -> bool {
287 let mut inner_val = &mut this_ptr.get_native_mut_ref().announced_channel;
290 /// Set to announce the channel publicly and notify all nodes that they can route via this
293 /// This should only be set to true for nodes which expect to be online reliably.
295 /// As the node which funds a channel picks this value this will only apply for new outbound
296 /// channels unless [`ChannelHandshakeLimits::force_announced_channel_preference`] is set.
298 /// Default value: false.
300 pub extern "C" fn ChannelHandshakeConfig_set_announced_channel(this_ptr: &mut ChannelHandshakeConfig, mut val: bool) {
301 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announced_channel = val;
303 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
304 /// supports it, they will then enforce the mutual-close output to us matches what we provided
305 /// at intialization, preventing us from closing to an alternate pubkey.
307 /// This is set to true by default to provide a slight increase in security, though ultimately
308 /// any attacker who is able to take control of a channel can just as easily send the funds via
309 /// lightning payments, so we never require that our counterparties support this option.
311 /// The upfront key committed is provided from [`KeysInterface::get_shutdown_scriptpubkey`].
313 /// Default value: true.
315 /// [`KeysInterface::get_shutdown_scriptpubkey`]: crate::chain::keysinterface::KeysInterface::get_shutdown_scriptpubkey
317 pub extern "C" fn ChannelHandshakeConfig_get_commit_upfront_shutdown_pubkey(this_ptr: &ChannelHandshakeConfig) -> bool {
318 let mut inner_val = &mut this_ptr.get_native_mut_ref().commit_upfront_shutdown_pubkey;
321 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
322 /// supports it, they will then enforce the mutual-close output to us matches what we provided
323 /// at intialization, preventing us from closing to an alternate pubkey.
325 /// This is set to true by default to provide a slight increase in security, though ultimately
326 /// any attacker who is able to take control of a channel can just as easily send the funds via
327 /// lightning payments, so we never require that our counterparties support this option.
329 /// The upfront key committed is provided from [`KeysInterface::get_shutdown_scriptpubkey`].
331 /// Default value: true.
333 /// [`KeysInterface::get_shutdown_scriptpubkey`]: crate::chain::keysinterface::KeysInterface::get_shutdown_scriptpubkey
335 pub extern "C" fn ChannelHandshakeConfig_set_commit_upfront_shutdown_pubkey(this_ptr: &mut ChannelHandshakeConfig, mut val: bool) {
336 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.commit_upfront_shutdown_pubkey = val;
338 /// The Proportion of the channel value to configure as counterparty's channel reserve,
339 /// i.e., `their_channel_reserve_satoshis` for both outbound and inbound channels.
341 /// `their_channel_reserve_satoshis` is the minimum balance that the other node has to maintain
342 /// on their side, at all times.
343 /// This ensures that if our counterparty broadcasts a revoked state, we can punish them by
344 /// claiming at least this value on chain.
346 /// Channel reserve values greater than 30% could be considered highly unreasonable, since that
347 /// amount can never be used for payments.
348 /// Also, if our selected channel reserve for counterparty and counterparty's selected
349 /// channel reserve for us sum up to equal or greater than channel value, channel negotiations
352 /// Note: Versions of LDK earlier than v0.0.104 will fail to read channels with any channel reserve
353 /// other than the default value.
355 /// Default value: 1% of channel value, i.e., configured as 10,000 millionths.
356 /// Minimum value: If the calculated proportional value is less than 1000 sats, it will be treated
357 /// as 1000 sats instead, which is a safe implementation-specific lower bound.
358 /// Maximum value: 1,000,000, any values larger than 1 Million will be treated as 1 Million (or 100%)
359 /// instead, although channel negotiations will fail in that case.
361 pub extern "C" fn ChannelHandshakeConfig_get_their_channel_reserve_proportional_millionths(this_ptr: &ChannelHandshakeConfig) -> u32 {
362 let mut inner_val = &mut this_ptr.get_native_mut_ref().their_channel_reserve_proportional_millionths;
365 /// The Proportion of the channel value to configure as counterparty's channel reserve,
366 /// i.e., `their_channel_reserve_satoshis` for both outbound and inbound channels.
368 /// `their_channel_reserve_satoshis` is the minimum balance that the other node has to maintain
369 /// on their side, at all times.
370 /// This ensures that if our counterparty broadcasts a revoked state, we can punish them by
371 /// claiming at least this value on chain.
373 /// Channel reserve values greater than 30% could be considered highly unreasonable, since that
374 /// amount can never be used for payments.
375 /// Also, if our selected channel reserve for counterparty and counterparty's selected
376 /// channel reserve for us sum up to equal or greater than channel value, channel negotiations
379 /// Note: Versions of LDK earlier than v0.0.104 will fail to read channels with any channel reserve
380 /// other than the default value.
382 /// Default value: 1% of channel value, i.e., configured as 10,000 millionths.
383 /// Minimum value: If the calculated proportional value is less than 1000 sats, it will be treated
384 /// as 1000 sats instead, which is a safe implementation-specific lower bound.
385 /// Maximum value: 1,000,000, any values larger than 1 Million will be treated as 1 Million (or 100%)
386 /// instead, although channel negotiations will fail in that case.
388 pub extern "C" fn ChannelHandshakeConfig_set_their_channel_reserve_proportional_millionths(this_ptr: &mut ChannelHandshakeConfig, mut val: u32) {
389 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.their_channel_reserve_proportional_millionths = val;
391 /// Constructs a new ChannelHandshakeConfig given each field
394 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) -> ChannelHandshakeConfig {
395 ChannelHandshakeConfig { inner: ObjOps::heap_alloc(nativeChannelHandshakeConfig {
396 minimum_depth: minimum_depth_arg,
397 our_to_self_delay: our_to_self_delay_arg,
398 our_htlc_minimum_msat: our_htlc_minimum_msat_arg,
399 max_inbound_htlc_value_in_flight_percent_of_channel: max_inbound_htlc_value_in_flight_percent_of_channel_arg,
400 negotiate_scid_privacy: negotiate_scid_privacy_arg,
401 announced_channel: announced_channel_arg,
402 commit_upfront_shutdown_pubkey: commit_upfront_shutdown_pubkey_arg,
403 their_channel_reserve_proportional_millionths: their_channel_reserve_proportional_millionths_arg,
406 impl Clone for ChannelHandshakeConfig {
407 fn clone(&self) -> Self {
409 inner: if <*mut nativeChannelHandshakeConfig>::is_null(self.inner) { core::ptr::null_mut() } else {
410 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
416 /// Used only if an object of this type is returned as a trait impl by a method
417 pub(crate) extern "C" fn ChannelHandshakeConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
418 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeConfig)).clone() })) as *mut c_void
421 /// Creates a copy of the ChannelHandshakeConfig
422 pub extern "C" fn ChannelHandshakeConfig_clone(orig: &ChannelHandshakeConfig) -> ChannelHandshakeConfig {
425 /// Creates a "default" ChannelHandshakeConfig. See struct and individual field documentaiton for details on which values are used.
428 pub extern "C" fn ChannelHandshakeConfig_default() -> ChannelHandshakeConfig {
429 ChannelHandshakeConfig { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
432 use lightning::util::config::ChannelHandshakeLimits as nativeChannelHandshakeLimitsImport;
433 pub(crate) type nativeChannelHandshakeLimits = nativeChannelHandshakeLimitsImport;
435 /// Optional channel limits which are applied during channel creation.
437 /// These limits are only applied to our counterparty's limits, not our own.
439 /// Use 0/<type>::max_value() as appropriate to skip checking.
441 /// Provides sane defaults for most configurations.
443 /// Most additional limits are disabled except those with which specify a default in individual
444 /// field documentation. Note that this may result in barely-usable channels, but since they
445 /// are applied mostly only to incoming channels that's not much of a problem.
448 pub struct ChannelHandshakeLimits {
449 /// A pointer to the opaque Rust object.
451 /// Nearly everywhere, inner must be non-null, however in places where
452 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
453 pub inner: *mut nativeChannelHandshakeLimits,
454 /// Indicates that this is the only struct which contains the same pointer.
456 /// Rust functions which take ownership of an object provided via an argument require
457 /// this to be true and invalidate the object pointed to by inner.
461 impl Drop for ChannelHandshakeLimits {
463 if self.is_owned && !<*mut nativeChannelHandshakeLimits>::is_null(self.inner) {
464 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
468 /// Frees any resources used by the ChannelHandshakeLimits, if is_owned is set and inner is non-NULL.
470 pub extern "C" fn ChannelHandshakeLimits_free(this_obj: ChannelHandshakeLimits) { }
472 /// Used only if an object of this type is returned as a trait impl by a method
473 pub(crate) extern "C" fn ChannelHandshakeLimits_free_void(this_ptr: *mut c_void) {
474 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelHandshakeLimits) };
477 impl ChannelHandshakeLimits {
478 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelHandshakeLimits {
479 unsafe { &*ObjOps::untweak_ptr(self.inner) }
481 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelHandshakeLimits {
482 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
484 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
485 pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeLimits {
486 assert!(self.is_owned);
487 let ret = ObjOps::untweak_ptr(self.inner);
488 self.inner = core::ptr::null_mut();
492 /// Minimum allowed satoshis when a channel is funded. This is supplied by the sender and so
493 /// only applies to inbound channels.
495 /// Default value: 0.
497 pub extern "C" fn ChannelHandshakeLimits_get_min_funding_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
498 let mut inner_val = &mut this_ptr.get_native_mut_ref().min_funding_satoshis;
501 /// Minimum allowed satoshis when a channel is funded. This is supplied by the sender and so
502 /// only applies to inbound channels.
504 /// Default value: 0.
506 pub extern "C" fn ChannelHandshakeLimits_set_min_funding_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
507 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.min_funding_satoshis = val;
509 /// Maximum allowed satoshis when a channel is funded. This is supplied by the sender and so
510 /// only applies to inbound channels.
512 /// Default value: 2^24 - 1.
514 pub extern "C" fn ChannelHandshakeLimits_get_max_funding_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
515 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_funding_satoshis;
518 /// Maximum allowed satoshis when a channel is funded. This is supplied by the sender and so
519 /// only applies to inbound channels.
521 /// Default value: 2^24 - 1.
523 pub extern "C" fn ChannelHandshakeLimits_set_max_funding_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
524 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_funding_satoshis = val;
526 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
527 /// you to limit the maximum minimum-size they can require.
529 /// Default value: u64::max_value.
531 pub extern "C" fn ChannelHandshakeLimits_get_max_htlc_minimum_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
532 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_htlc_minimum_msat;
535 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
536 /// you to limit the maximum minimum-size they can require.
538 /// Default value: u64::max_value.
540 pub extern "C" fn ChannelHandshakeLimits_set_max_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
541 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_htlc_minimum_msat = val;
543 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
544 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
546 /// Default value: 0.
548 pub extern "C" fn ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
549 let mut inner_val = &mut this_ptr.get_native_mut_ref().min_max_htlc_value_in_flight_msat;
552 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
553 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
555 /// Default value: 0.
557 pub extern "C" fn ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
558 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.min_max_htlc_value_in_flight_msat = val;
560 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
561 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
562 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
564 /// Default value: u64::max_value.
566 pub extern "C" fn ChannelHandshakeLimits_get_max_channel_reserve_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
567 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_channel_reserve_satoshis;
570 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
571 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
572 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
574 /// Default value: u64::max_value.
576 pub extern "C" fn ChannelHandshakeLimits_set_max_channel_reserve_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
577 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_channel_reserve_satoshis = val;
579 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
580 /// time. This allows you to set a minimum such value.
582 /// Default value: 0.
584 pub extern "C" fn ChannelHandshakeLimits_get_min_max_accepted_htlcs(this_ptr: &ChannelHandshakeLimits) -> u16 {
585 let mut inner_val = &mut this_ptr.get_native_mut_ref().min_max_accepted_htlcs;
588 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
589 /// time. This allows you to set a minimum such value.
591 /// Default value: 0.
593 pub extern "C" fn ChannelHandshakeLimits_set_min_max_accepted_htlcs(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
594 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.min_max_accepted_htlcs = val;
596 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
597 /// certain number of blocks, specified by the node which is not the funder (as the funder can
598 /// assume they aren't going to double-spend themselves).
599 /// This config allows you to set a limit on the maximum amount of time to wait.
601 /// Default value: 144, or roughly one day and only applies to outbound channels.
603 pub extern "C" fn ChannelHandshakeLimits_get_max_minimum_depth(this_ptr: &ChannelHandshakeLimits) -> u32 {
604 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_minimum_depth;
607 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
608 /// certain number of blocks, specified by the node which is not the funder (as the funder can
609 /// assume they aren't going to double-spend themselves).
610 /// This config allows you to set a limit on the maximum amount of time to wait.
612 /// Default value: 144, or roughly one day and only applies to outbound channels.
614 pub extern "C" fn ChannelHandshakeLimits_set_max_minimum_depth(this_ptr: &mut ChannelHandshakeLimits, mut val: u32) {
615 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_minimum_depth = val;
617 /// Whether we implicitly trust funding transactions generated by us for our own outbound
618 /// channels to not be double-spent.
620 /// If this is set, we assume that our own funding transactions are *never* double-spent, and
621 /// thus we can trust them without any confirmations. This is generally a reasonable
622 /// assumption, given we're the only ones who could ever double-spend it (assuming we have sole
623 /// control of the signing keys).
625 /// You may wish to un-set this if you allow the user to (or do in an automated fashion)
626 /// double-spend the funding transaction to RBF with an alternative channel open.
628 /// This only applies if our counterparty set their confirmations-required value to 0, and we
629 /// always trust our own funding transaction at 1 confirmation irrespective of this value.
630 /// Thus, this effectively acts as a `min_minimum_depth`, with the only possible values being
631 /// `true` (0) and `false` (1).
633 /// Default value: true
635 pub extern "C" fn ChannelHandshakeLimits_get_trust_own_funding_0conf(this_ptr: &ChannelHandshakeLimits) -> bool {
636 let mut inner_val = &mut this_ptr.get_native_mut_ref().trust_own_funding_0conf;
639 /// Whether we implicitly trust funding transactions generated by us for our own outbound
640 /// channels to not be double-spent.
642 /// If this is set, we assume that our own funding transactions are *never* double-spent, and
643 /// thus we can trust them without any confirmations. This is generally a reasonable
644 /// assumption, given we're the only ones who could ever double-spend it (assuming we have sole
645 /// control of the signing keys).
647 /// You may wish to un-set this if you allow the user to (or do in an automated fashion)
648 /// double-spend the funding transaction to RBF with an alternative channel open.
650 /// This only applies if our counterparty set their confirmations-required value to 0, and we
651 /// always trust our own funding transaction at 1 confirmation irrespective of this value.
652 /// Thus, this effectively acts as a `min_minimum_depth`, with the only possible values being
653 /// `true` (0) and `false` (1).
655 /// Default value: true
657 pub extern "C" fn ChannelHandshakeLimits_set_trust_own_funding_0conf(this_ptr: &mut ChannelHandshakeLimits, mut val: bool) {
658 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.trust_own_funding_0conf = val;
660 /// Set to force an incoming channel to match our announced channel preference in
661 /// [`ChannelHandshakeConfig::announced_channel`].
663 /// For a node which is not online reliably, this should be set to true and
664 /// [`ChannelHandshakeConfig::announced_channel`] set to false, ensuring that no announced (aka public)
665 /// channels will ever be opened.
667 /// Default value: true.
669 pub extern "C" fn ChannelHandshakeLimits_get_force_announced_channel_preference(this_ptr: &ChannelHandshakeLimits) -> bool {
670 let mut inner_val = &mut this_ptr.get_native_mut_ref().force_announced_channel_preference;
673 /// Set to force an incoming channel to match our announced channel preference in
674 /// [`ChannelHandshakeConfig::announced_channel`].
676 /// For a node which is not online reliably, this should be set to true and
677 /// [`ChannelHandshakeConfig::announced_channel`] set to false, ensuring that no announced (aka public)
678 /// channels will ever be opened.
680 /// Default value: true.
682 pub extern "C" fn ChannelHandshakeLimits_set_force_announced_channel_preference(this_ptr: &mut ChannelHandshakeLimits, mut val: bool) {
683 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.force_announced_channel_preference = val;
685 /// Set to the amount of time we're willing to wait to claim money back to us.
687 /// Not checking this value would be a security issue, as our peer would be able to set it to
688 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
690 /// Default value: 2016, which we also enforce as a maximum value so you can tweak config to
691 /// reduce the loss of having useless locked funds (if your peer accepts)
693 pub extern "C" fn ChannelHandshakeLimits_get_their_to_self_delay(this_ptr: &ChannelHandshakeLimits) -> u16 {
694 let mut inner_val = &mut this_ptr.get_native_mut_ref().their_to_self_delay;
697 /// Set to the amount of time we're willing to wait to claim money back to us.
699 /// Not checking this value would be a security issue, as our peer would be able to set it to
700 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
702 /// Default value: 2016, which we also enforce as a maximum value so you can tweak config to
703 /// reduce the loss of having useless locked funds (if your peer accepts)
705 pub extern "C" fn ChannelHandshakeLimits_set_their_to_self_delay(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
706 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.their_to_self_delay = val;
708 /// Constructs a new ChannelHandshakeLimits given each field
711 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 {
712 ChannelHandshakeLimits { inner: ObjOps::heap_alloc(nativeChannelHandshakeLimits {
713 min_funding_satoshis: min_funding_satoshis_arg,
714 max_funding_satoshis: max_funding_satoshis_arg,
715 max_htlc_minimum_msat: max_htlc_minimum_msat_arg,
716 min_max_htlc_value_in_flight_msat: min_max_htlc_value_in_flight_msat_arg,
717 max_channel_reserve_satoshis: max_channel_reserve_satoshis_arg,
718 min_max_accepted_htlcs: min_max_accepted_htlcs_arg,
719 max_minimum_depth: max_minimum_depth_arg,
720 trust_own_funding_0conf: trust_own_funding_0conf_arg,
721 force_announced_channel_preference: force_announced_channel_preference_arg,
722 their_to_self_delay: their_to_self_delay_arg,
725 impl Clone for ChannelHandshakeLimits {
726 fn clone(&self) -> Self {
728 inner: if <*mut nativeChannelHandshakeLimits>::is_null(self.inner) { core::ptr::null_mut() } else {
729 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
735 /// Used only if an object of this type is returned as a trait impl by a method
736 pub(crate) extern "C" fn ChannelHandshakeLimits_clone_void(this_ptr: *const c_void) -> *mut c_void {
737 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeLimits)).clone() })) as *mut c_void
740 /// Creates a copy of the ChannelHandshakeLimits
741 pub extern "C" fn ChannelHandshakeLimits_clone(orig: &ChannelHandshakeLimits) -> ChannelHandshakeLimits {
744 /// Creates a "default" ChannelHandshakeLimits. See struct and individual field documentaiton for details on which values are used.
747 pub extern "C" fn ChannelHandshakeLimits_default() -> ChannelHandshakeLimits {
748 ChannelHandshakeLimits { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
751 use lightning::util::config::ChannelConfig as nativeChannelConfigImport;
752 pub(crate) type nativeChannelConfig = nativeChannelConfigImport;
754 /// Options which apply on a per-channel basis and may change at runtime or based on negotiation
755 /// with our counterparty.
758 pub struct ChannelConfig {
759 /// A pointer to the opaque Rust object.
761 /// Nearly everywhere, inner must be non-null, however in places where
762 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
763 pub inner: *mut nativeChannelConfig,
764 /// Indicates that this is the only struct which contains the same pointer.
766 /// Rust functions which take ownership of an object provided via an argument require
767 /// this to be true and invalidate the object pointed to by inner.
771 impl Drop for ChannelConfig {
773 if self.is_owned && !<*mut nativeChannelConfig>::is_null(self.inner) {
774 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
778 /// Frees any resources used by the ChannelConfig, if is_owned is set and inner is non-NULL.
780 pub extern "C" fn ChannelConfig_free(this_obj: ChannelConfig) { }
782 /// Used only if an object of this type is returned as a trait impl by a method
783 pub(crate) extern "C" fn ChannelConfig_free_void(this_ptr: *mut c_void) {
784 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelConfig) };
788 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelConfig {
789 unsafe { &*ObjOps::untweak_ptr(self.inner) }
791 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelConfig {
792 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
794 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
795 pub(crate) fn take_inner(mut self) -> *mut nativeChannelConfig {
796 assert!(self.is_owned);
797 let ret = ObjOps::untweak_ptr(self.inner);
798 self.inner = core::ptr::null_mut();
802 /// Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
803 /// over the channel.
804 /// This may be allowed to change at runtime in a later update, however doing so must result in
805 /// update messages sent to notify all nodes of our updated relay fee.
807 /// Default value: 0.
809 pub extern "C" fn ChannelConfig_get_forwarding_fee_proportional_millionths(this_ptr: &ChannelConfig) -> u32 {
810 let mut inner_val = &mut this_ptr.get_native_mut_ref().forwarding_fee_proportional_millionths;
813 /// Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
814 /// over the channel.
815 /// This may be allowed to change at runtime in a later update, however doing so must result in
816 /// update messages sent to notify all nodes of our updated relay fee.
818 /// Default value: 0.
820 pub extern "C" fn ChannelConfig_set_forwarding_fee_proportional_millionths(this_ptr: &mut ChannelConfig, mut val: u32) {
821 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.forwarding_fee_proportional_millionths = val;
823 /// Amount (in milli-satoshi) charged for payments forwarded outbound over the channel, in
824 /// excess of [`forwarding_fee_proportional_millionths`].
825 /// This may be allowed to change at runtime in a later update, however doing so must result in
826 /// update messages sent to notify all nodes of our updated relay fee.
828 /// The default value of a single satoshi roughly matches the market rate on many routing nodes
829 /// as of July 2021. Adjusting it upwards or downwards may change whether nodes route through
832 /// Default value: 1000.
834 /// [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
836 pub extern "C" fn ChannelConfig_get_forwarding_fee_base_msat(this_ptr: &ChannelConfig) -> u32 {
837 let mut inner_val = &mut this_ptr.get_native_mut_ref().forwarding_fee_base_msat;
840 /// Amount (in milli-satoshi) charged for payments forwarded outbound over the channel, in
841 /// excess of [`forwarding_fee_proportional_millionths`].
842 /// This may be allowed to change at runtime in a later update, however doing so must result in
843 /// update messages sent to notify all nodes of our updated relay fee.
845 /// The default value of a single satoshi roughly matches the market rate on many routing nodes
846 /// as of July 2021. Adjusting it upwards or downwards may change whether nodes route through
849 /// Default value: 1000.
851 /// [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
853 pub extern "C" fn ChannelConfig_set_forwarding_fee_base_msat(this_ptr: &mut ChannelConfig, mut val: u32) {
854 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.forwarding_fee_base_msat = val;
856 /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
857 /// the channel this config applies to.
859 /// This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
860 /// HTLC balance when a channel appears on-chain whereas
861 /// [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
862 /// (non-HTLC-encumbered) balance.
864 /// Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
865 /// we (or one of our watchtowers) MUST be online to check for broadcast of the current
866 /// commitment transaction at least once per this many blocks (minus some margin to allow us
867 /// enough time to broadcast and confirm a transaction, possibly with time in between to RBF
868 /// the spending transaction).
870 /// Default value: 72 (12 hours at an average of 6 blocks/hour).
871 /// Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
872 /// [`MIN_CLTV_EXPIRY_DELTA`] instead.
874 /// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
876 pub extern "C" fn ChannelConfig_get_cltv_expiry_delta(this_ptr: &ChannelConfig) -> u16 {
877 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
880 /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
881 /// the channel this config applies to.
883 /// This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
884 /// HTLC balance when a channel appears on-chain whereas
885 /// [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
886 /// (non-HTLC-encumbered) balance.
888 /// Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
889 /// we (or one of our watchtowers) MUST be online to check for broadcast of the current
890 /// commitment transaction at least once per this many blocks (minus some margin to allow us
891 /// enough time to broadcast and confirm a transaction, possibly with time in between to RBF
892 /// the spending transaction).
894 /// Default value: 72 (12 hours at an average of 6 blocks/hour).
895 /// Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
896 /// [`MIN_CLTV_EXPIRY_DELTA`] instead.
898 /// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
900 pub extern "C" fn ChannelConfig_set_cltv_expiry_delta(this_ptr: &mut ChannelConfig, mut val: u16) {
901 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
903 /// Limit our total exposure to in-flight HTLCs which are burned to fees as they are too
904 /// small to claim on-chain.
906 /// When an HTLC present in one of our channels is below a \"dust\" threshold, the HTLC will
907 /// not be claimable on-chain, instead being turned into additional miner fees if either
908 /// party force-closes the channel. Because the threshold is per-HTLC, our total exposure
909 /// to such payments may be sustantial if there are many dust HTLCs present when the
910 /// channel is force-closed.
912 /// The dust threshold for each HTLC is based on the `dust_limit_satoshis` for each party in a
913 /// channel negotiated throughout the channel open process, along with the fees required to have
914 /// a broadcastable HTLC spending transaction. When a channel supports anchor outputs
915 /// (specifically the zero fee HTLC transaction variant), this threshold no longer takes into
916 /// account the HTLC transaction fee as it is zero.
918 /// This limit is applied for sent, forwarded, and received HTLCs and limits the total
919 /// exposure across all three types per-channel. Setting this too low may prevent the
920 /// sending or receipt of low-value HTLCs on high-traffic nodes, and this limit is very
921 /// important to prevent stealing of dust HTLCs by miners.
923 /// Default value: 5_000_000 msat.
925 pub extern "C" fn ChannelConfig_get_max_dust_htlc_exposure_msat(this_ptr: &ChannelConfig) -> u64 {
926 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_dust_htlc_exposure_msat;
929 /// Limit our total exposure to in-flight HTLCs which are burned to fees as they are too
930 /// small to claim on-chain.
932 /// When an HTLC present in one of our channels is below a \"dust\" threshold, the HTLC will
933 /// not be claimable on-chain, instead being turned into additional miner fees if either
934 /// party force-closes the channel. Because the threshold is per-HTLC, our total exposure
935 /// to such payments may be sustantial if there are many dust HTLCs present when the
936 /// channel is force-closed.
938 /// The dust threshold for each HTLC is based on the `dust_limit_satoshis` for each party in a
939 /// channel negotiated throughout the channel open process, along with the fees required to have
940 /// a broadcastable HTLC spending transaction. When a channel supports anchor outputs
941 /// (specifically the zero fee HTLC transaction variant), this threshold no longer takes into
942 /// account the HTLC transaction fee as it is zero.
944 /// This limit is applied for sent, forwarded, and received HTLCs and limits the total
945 /// exposure across all three types per-channel. Setting this too low may prevent the
946 /// sending or receipt of low-value HTLCs on high-traffic nodes, and this limit is very
947 /// important to prevent stealing of dust HTLCs by miners.
949 /// Default value: 5_000_000 msat.
951 pub extern "C" fn ChannelConfig_set_max_dust_htlc_exposure_msat(this_ptr: &mut ChannelConfig, mut val: u64) {
952 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_dust_htlc_exposure_msat = val;
954 /// The additional fee we're willing to pay to avoid waiting for the counterparty's
955 /// `to_self_delay` to reclaim funds.
957 /// When we close a channel cooperatively with our counterparty, we negotiate a fee for the
958 /// closing transaction which both sides find acceptable, ultimately paid by the channel
959 /// funder/initiator.
961 /// When we are the funder, because we have to pay the channel closing fee, we bound the
962 /// acceptable fee by our [`Background`] and [`Normal`] fees, with the upper bound increased by
963 /// this value. Because the on-chain fee we'd pay to force-close the channel is kept near our
964 /// [`Normal`] feerate during normal operation, this value represents the additional fee we're
965 /// willing to pay in order to avoid waiting for our counterparty's to_self_delay to reclaim our
968 /// When we are not the funder, we require the closing transaction fee pay at least our
969 /// [`Background`] fee estimate, but allow our counterparty to pay as much fee as they like.
970 /// Thus, this value is ignored when we are not the funder.
972 /// Default value: 1000 satoshis.
974 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
975 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
977 pub extern "C" fn ChannelConfig_get_force_close_avoidance_max_fee_satoshis(this_ptr: &ChannelConfig) -> u64 {
978 let mut inner_val = &mut this_ptr.get_native_mut_ref().force_close_avoidance_max_fee_satoshis;
981 /// The additional fee we're willing to pay to avoid waiting for the counterparty's
982 /// `to_self_delay` to reclaim funds.
984 /// When we close a channel cooperatively with our counterparty, we negotiate a fee for the
985 /// closing transaction which both sides find acceptable, ultimately paid by the channel
986 /// funder/initiator.
988 /// When we are the funder, because we have to pay the channel closing fee, we bound the
989 /// acceptable fee by our [`Background`] and [`Normal`] fees, with the upper bound increased by
990 /// this value. Because the on-chain fee we'd pay to force-close the channel is kept near our
991 /// [`Normal`] feerate during normal operation, this value represents the additional fee we're
992 /// willing to pay in order to avoid waiting for our counterparty's to_self_delay to reclaim our
995 /// When we are not the funder, we require the closing transaction fee pay at least our
996 /// [`Background`] fee estimate, but allow our counterparty to pay as much fee as they like.
997 /// Thus, this value is ignored when we are not the funder.
999 /// Default value: 1000 satoshis.
1001 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
1002 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
1004 pub extern "C" fn ChannelConfig_set_force_close_avoidance_max_fee_satoshis(this_ptr: &mut ChannelConfig, mut val: u64) {
1005 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.force_close_avoidance_max_fee_satoshis = val;
1007 /// Constructs a new ChannelConfig given each field
1010 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_msat_arg: u64, mut force_close_avoidance_max_fee_satoshis_arg: u64) -> ChannelConfig {
1011 ChannelConfig { inner: ObjOps::heap_alloc(nativeChannelConfig {
1012 forwarding_fee_proportional_millionths: forwarding_fee_proportional_millionths_arg,
1013 forwarding_fee_base_msat: forwarding_fee_base_msat_arg,
1014 cltv_expiry_delta: cltv_expiry_delta_arg,
1015 max_dust_htlc_exposure_msat: max_dust_htlc_exposure_msat_arg,
1016 force_close_avoidance_max_fee_satoshis: force_close_avoidance_max_fee_satoshis_arg,
1017 }), is_owned: true }
1019 impl Clone for ChannelConfig {
1020 fn clone(&self) -> Self {
1022 inner: if <*mut nativeChannelConfig>::is_null(self.inner) { core::ptr::null_mut() } else {
1023 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1029 /// Used only if an object of this type is returned as a trait impl by a method
1030 pub(crate) extern "C" fn ChannelConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
1031 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelConfig)).clone() })) as *mut c_void
1034 /// Creates a copy of the ChannelConfig
1035 pub extern "C" fn ChannelConfig_clone(orig: &ChannelConfig) -> ChannelConfig {
1038 /// Checks if two ChannelConfigs contain equal inner contents.
1039 /// This ignores pointers and is_owned flags and looks at the values in fields.
1040 /// Two objects with NULL inner values will be considered "equal" here.
1042 pub extern "C" fn ChannelConfig_eq(a: &ChannelConfig, b: &ChannelConfig) -> bool {
1043 if a.inner == b.inner { return true; }
1044 if a.inner.is_null() || b.inner.is_null() { return false; }
1045 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1047 /// Creates a "default" ChannelConfig. See struct and individual field documentaiton for details on which values are used.
1050 pub extern "C" fn ChannelConfig_default() -> ChannelConfig {
1051 ChannelConfig { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
1054 /// Serialize the ChannelConfig object into a byte array which can be read by ChannelConfig_read
1055 pub extern "C" fn ChannelConfig_write(obj: &crate::lightning::util::config::ChannelConfig) -> crate::c_types::derived::CVec_u8Z {
1056 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1059 pub(crate) extern "C" fn ChannelConfig_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1060 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelConfig) })
1063 /// Read a ChannelConfig from a byte array, created by ChannelConfig_write
1064 pub extern "C" fn ChannelConfig_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelConfigDecodeErrorZ {
1065 let res: Result<lightning::util::config::ChannelConfig, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1066 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() };
1070 use lightning::util::config::UserConfig as nativeUserConfigImport;
1071 pub(crate) type nativeUserConfig = nativeUserConfigImport;
1073 /// Top-level config which holds ChannelHandshakeLimits and ChannelConfig.
1075 /// Default::default() provides sane defaults for most configurations
1076 /// (but currently with 0 relay fees!)
1079 pub struct UserConfig {
1080 /// A pointer to the opaque Rust object.
1082 /// Nearly everywhere, inner must be non-null, however in places where
1083 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1084 pub inner: *mut nativeUserConfig,
1085 /// Indicates that this is the only struct which contains the same pointer.
1087 /// Rust functions which take ownership of an object provided via an argument require
1088 /// this to be true and invalidate the object pointed to by inner.
1092 impl Drop for UserConfig {
1093 fn drop(&mut self) {
1094 if self.is_owned && !<*mut nativeUserConfig>::is_null(self.inner) {
1095 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1099 /// Frees any resources used by the UserConfig, if is_owned is set and inner is non-NULL.
1101 pub extern "C" fn UserConfig_free(this_obj: UserConfig) { }
1103 /// Used only if an object of this type is returned as a trait impl by a method
1104 pub(crate) extern "C" fn UserConfig_free_void(this_ptr: *mut c_void) {
1105 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeUserConfig) };
1109 pub(crate) fn get_native_ref(&self) -> &'static nativeUserConfig {
1110 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1112 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeUserConfig {
1113 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1115 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1116 pub(crate) fn take_inner(mut self) -> *mut nativeUserConfig {
1117 assert!(self.is_owned);
1118 let ret = ObjOps::untweak_ptr(self.inner);
1119 self.inner = core::ptr::null_mut();
1123 /// Channel handshake config that we propose to our counterparty.
1125 pub extern "C" fn UserConfig_get_channel_handshake_config(this_ptr: &UserConfig) -> crate::lightning::util::config::ChannelHandshakeConfig {
1126 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_handshake_config;
1127 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 }
1129 /// Channel handshake config that we propose to our counterparty.
1131 pub extern "C" fn UserConfig_set_channel_handshake_config(this_ptr: &mut UserConfig, mut val: crate::lightning::util::config::ChannelHandshakeConfig) {
1132 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_handshake_config = *unsafe { Box::from_raw(val.take_inner()) };
1134 /// Limits applied to our counterparty's proposed channel handshake config settings.
1136 pub extern "C" fn UserConfig_get_channel_handshake_limits(this_ptr: &UserConfig) -> crate::lightning::util::config::ChannelHandshakeLimits {
1137 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_handshake_limits;
1138 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 }
1140 /// Limits applied to our counterparty's proposed channel handshake config settings.
1142 pub extern "C" fn UserConfig_set_channel_handshake_limits(this_ptr: &mut UserConfig, mut val: crate::lightning::util::config::ChannelHandshakeLimits) {
1143 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_handshake_limits = *unsafe { Box::from_raw(val.take_inner()) };
1145 /// Channel config which affects behavior during channel lifetime.
1147 pub extern "C" fn UserConfig_get_channel_config(this_ptr: &UserConfig) -> crate::lightning::util::config::ChannelConfig {
1148 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_config;
1149 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 }
1151 /// Channel config which affects behavior during channel lifetime.
1153 pub extern "C" fn UserConfig_set_channel_config(this_ptr: &mut UserConfig, mut val: crate::lightning::util::config::ChannelConfig) {
1154 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_config = *unsafe { Box::from_raw(val.take_inner()) };
1156 /// If this is set to false, we will reject any HTLCs which were to be forwarded over private
1157 /// channels. This prevents us from taking on HTLC-forwarding risk when we intend to run as a
1158 /// node which is not online reliably.
1160 /// For nodes which are not online reliably, you should set all channels to *not* be announced
1161 /// (using [`ChannelHandshakeConfig::announced_channel`] and
1162 /// [`ChannelHandshakeLimits::force_announced_channel_preference`]) and set this to false to
1163 /// ensure you are not exposed to any forwarding risk.
1165 /// Note that because you cannot change a channel's announced state after creation, there is no
1166 /// way to disable forwarding on public channels retroactively. Thus, in order to change a node
1167 /// from a publicly-announced forwarding node to a private non-forwarding node you must close
1168 /// all your channels and open new ones. For privacy, you should also change your node_id
1169 /// (swapping all private and public key material for new ones) at that time.
1171 /// Default value: false.
1173 pub extern "C" fn UserConfig_get_accept_forwards_to_priv_channels(this_ptr: &UserConfig) -> bool {
1174 let mut inner_val = &mut this_ptr.get_native_mut_ref().accept_forwards_to_priv_channels;
1177 /// If this is set to false, we will reject any HTLCs which were to be forwarded over private
1178 /// channels. This prevents us from taking on HTLC-forwarding risk when we intend to run as a
1179 /// node which is not online reliably.
1181 /// For nodes which are not online reliably, you should set all channels to *not* be announced
1182 /// (using [`ChannelHandshakeConfig::announced_channel`] and
1183 /// [`ChannelHandshakeLimits::force_announced_channel_preference`]) and set this to false to
1184 /// ensure you are not exposed to any forwarding risk.
1186 /// Note that because you cannot change a channel's announced state after creation, there is no
1187 /// way to disable forwarding on public channels retroactively. Thus, in order to change a node
1188 /// from a publicly-announced forwarding node to a private non-forwarding node you must close
1189 /// all your channels and open new ones. For privacy, you should also change your node_id
1190 /// (swapping all private and public key material for new ones) at that time.
1192 /// Default value: false.
1194 pub extern "C" fn UserConfig_set_accept_forwards_to_priv_channels(this_ptr: &mut UserConfig, mut val: bool) {
1195 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.accept_forwards_to_priv_channels = val;
1197 /// If this is set to false, we do not accept inbound requests to open a new channel.
1198 /// Default value: true.
1200 pub extern "C" fn UserConfig_get_accept_inbound_channels(this_ptr: &UserConfig) -> bool {
1201 let mut inner_val = &mut this_ptr.get_native_mut_ref().accept_inbound_channels;
1204 /// If this is set to false, we do not accept inbound requests to open a new channel.
1205 /// Default value: true.
1207 pub extern "C" fn UserConfig_set_accept_inbound_channels(this_ptr: &mut UserConfig, mut val: bool) {
1208 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.accept_inbound_channels = val;
1210 /// If this is set to true, the user needs to manually accept inbound requests to open a new
1213 /// When set to true, [`Event::OpenChannelRequest`] will be triggered once a request to open a
1214 /// new inbound channel is received through a [`msgs::OpenChannel`] message. In that case, a
1215 /// [`msgs::AcceptChannel`] message will not be sent back to the counterparty node unless the
1216 /// user explicitly chooses to accept the request.
1218 /// Default value: false.
1220 /// [`Event::OpenChannelRequest`]: crate::util::events::Event::OpenChannelRequest
1221 /// [`msgs::OpenChannel`]: crate::ln::msgs::OpenChannel
1222 /// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
1224 pub extern "C" fn UserConfig_get_manually_accept_inbound_channels(this_ptr: &UserConfig) -> bool {
1225 let mut inner_val = &mut this_ptr.get_native_mut_ref().manually_accept_inbound_channels;
1228 /// If this is set to true, the user needs to manually accept inbound requests to open a new
1231 /// When set to true, [`Event::OpenChannelRequest`] will be triggered once a request to open a
1232 /// new inbound channel is received through a [`msgs::OpenChannel`] message. In that case, a
1233 /// [`msgs::AcceptChannel`] message will not be sent back to the counterparty node unless the
1234 /// user explicitly chooses to accept the request.
1236 /// Default value: false.
1238 /// [`Event::OpenChannelRequest`]: crate::util::events::Event::OpenChannelRequest
1239 /// [`msgs::OpenChannel`]: crate::ln::msgs::OpenChannel
1240 /// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
1242 pub extern "C" fn UserConfig_set_manually_accept_inbound_channels(this_ptr: &mut UserConfig, mut val: bool) {
1243 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.manually_accept_inbound_channels = val;
1245 /// If this is set to true, LDK will intercept HTLCs that are attempting to be forwarded over
1246 /// fake short channel ids generated via [`ChannelManager::get_intercept_scid`]. Upon HTLC
1247 /// intercept, LDK will generate an [`Event::HTLCIntercepted`] which MUST be handled by the user.
1249 /// Setting this to true may break backwards compatibility with LDK versions < 0.0.113.
1251 /// Default value: false.
1253 /// [`ChannelManager::get_intercept_scid`]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
1254 /// [`Event::HTLCIntercepted`]: crate::util::events::Event::HTLCIntercepted
1256 pub extern "C" fn UserConfig_get_accept_intercept_htlcs(this_ptr: &UserConfig) -> bool {
1257 let mut inner_val = &mut this_ptr.get_native_mut_ref().accept_intercept_htlcs;
1260 /// If this is set to true, LDK will intercept HTLCs that are attempting to be forwarded over
1261 /// fake short channel ids generated via [`ChannelManager::get_intercept_scid`]. Upon HTLC
1262 /// intercept, LDK will generate an [`Event::HTLCIntercepted`] which MUST be handled by the user.
1264 /// Setting this to true may break backwards compatibility with LDK versions < 0.0.113.
1266 /// Default value: false.
1268 /// [`ChannelManager::get_intercept_scid`]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
1269 /// [`Event::HTLCIntercepted`]: crate::util::events::Event::HTLCIntercepted
1271 pub extern "C" fn UserConfig_set_accept_intercept_htlcs(this_ptr: &mut UserConfig, mut val: bool) {
1272 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.accept_intercept_htlcs = val;
1274 /// Constructs a new UserConfig given each field
1277 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) -> UserConfig {
1278 UserConfig { inner: ObjOps::heap_alloc(nativeUserConfig {
1279 channel_handshake_config: *unsafe { Box::from_raw(channel_handshake_config_arg.take_inner()) },
1280 channel_handshake_limits: *unsafe { Box::from_raw(channel_handshake_limits_arg.take_inner()) },
1281 channel_config: *unsafe { Box::from_raw(channel_config_arg.take_inner()) },
1282 accept_forwards_to_priv_channels: accept_forwards_to_priv_channels_arg,
1283 accept_inbound_channels: accept_inbound_channels_arg,
1284 manually_accept_inbound_channels: manually_accept_inbound_channels_arg,
1285 accept_intercept_htlcs: accept_intercept_htlcs_arg,
1286 }), is_owned: true }
1288 impl Clone for UserConfig {
1289 fn clone(&self) -> Self {
1291 inner: if <*mut nativeUserConfig>::is_null(self.inner) { core::ptr::null_mut() } else {
1292 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1298 /// Used only if an object of this type is returned as a trait impl by a method
1299 pub(crate) extern "C" fn UserConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
1300 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUserConfig)).clone() })) as *mut c_void
1303 /// Creates a copy of the UserConfig
1304 pub extern "C" fn UserConfig_clone(orig: &UserConfig) -> UserConfig {
1307 /// Creates a "default" UserConfig. See struct and individual field documentaiton for details on which values are used.
1310 pub extern "C" fn UserConfig_default() -> UserConfig {
1311 UserConfig { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }