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 unsafe { let _ = 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).
79 pub extern "C" fn ChannelHandshakeConfig_get_minimum_depth(this_ptr: &ChannelHandshakeConfig) -> u32 {
80 let mut inner_val = &mut this_ptr.get_native_mut_ref().minimum_depth;
83 /// Confirmations we will wait for before considering the channel locked in.
84 /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
85 /// equivalent limit applied to outbound channels).
89 pub extern "C" fn ChannelHandshakeConfig_set_minimum_depth(this_ptr: &mut ChannelHandshakeConfig, mut val: u32) {
90 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.minimum_depth = val;
92 /// Set to the number of blocks we require our counterparty to wait to claim their money (ie
93 /// the number of blocks we have to punish our counterparty if they broadcast a revoked
96 /// This is one of the main parameters of our security model. We (or one of our watchtowers) MUST
97 /// be online to check for revoked transactions on-chain at least once every our_to_self_delay
98 /// blocks (minus some margin to allow us enough time to broadcast and confirm a transaction,
99 /// possibly with time in between to RBF the spending transaction).
101 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
102 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
105 /// Default value: [`BREAKDOWN_TIMEOUT`], we enforce it as a minimum at channel opening so you
106 /// can tweak config to ask for more security, not less.
108 pub extern "C" fn ChannelHandshakeConfig_get_our_to_self_delay(this_ptr: &ChannelHandshakeConfig) -> u16 {
109 let mut inner_val = &mut this_ptr.get_native_mut_ref().our_to_self_delay;
112 /// Set to the number of blocks we require our counterparty to wait to claim their money (ie
113 /// the number of blocks we have to punish our counterparty if they broadcast a revoked
116 /// This is one of the main parameters of our security model. We (or one of our watchtowers) MUST
117 /// be online to check for revoked transactions on-chain at least once every our_to_self_delay
118 /// blocks (minus some margin to allow us enough time to broadcast and confirm a transaction,
119 /// possibly with time in between to RBF the spending transaction).
121 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
122 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
125 /// Default value: [`BREAKDOWN_TIMEOUT`], we enforce it as a minimum at channel opening so you
126 /// can tweak config to ask for more security, not less.
128 pub extern "C" fn ChannelHandshakeConfig_set_our_to_self_delay(this_ptr: &mut ChannelHandshakeConfig, mut val: u16) {
129 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.our_to_self_delay = val;
131 /// Set to the smallest value HTLC we will accept to process.
133 /// This value is sent to our counterparty on channel-open and we close the channel any time
134 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
136 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
139 pub extern "C" fn ChannelHandshakeConfig_get_our_htlc_minimum_msat(this_ptr: &ChannelHandshakeConfig) -> u64 {
140 let mut inner_val = &mut this_ptr.get_native_mut_ref().our_htlc_minimum_msat;
143 /// Set to the smallest value HTLC we will accept to process.
145 /// This value is sent to our counterparty on channel-open and we close the channel any time
146 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
148 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
151 pub extern "C" fn ChannelHandshakeConfig_set_our_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeConfig, mut val: u64) {
152 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.our_htlc_minimum_msat = val;
154 /// If set, we attempt to negotiate the `scid_privacy` (referred to as `scid_alias` in the
155 /// BOLTs) option for outbound private channels. This provides better privacy by not including
156 /// our real on-chain channel UTXO in each invoice and requiring that our counterparty only
157 /// relay HTLCs to us using the channel's SCID alias.
159 /// If this option is set, channels may be created that will not be readable by LDK versions
160 /// prior to 0.0.106, causing [`ChannelManager`]'s read method to return a
161 /// [`DecodeError:InvalidValue`].
163 /// Note that setting this to true does *not* prevent us from opening channels with
164 /// counterparties that do not support the `scid_alias` option; we will simply fall back to a
165 /// private channel without that option.
167 /// Ignored if the channel is negotiated to be announced, see
168 /// [`ChannelConfig::announced_channel`] and
169 /// [`ChannelHandshakeLimits::force_announced_channel_preference`] for more.
171 /// Default value: false. This value is likely to change to true in the future.
173 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
174 /// [`DecodeError:InvalidValue`]: crate::ln::msgs::DecodeError::InvalidValue
176 pub extern "C" fn ChannelHandshakeConfig_get_negotiate_scid_privacy(this_ptr: &ChannelHandshakeConfig) -> bool {
177 let mut inner_val = &mut this_ptr.get_native_mut_ref().negotiate_scid_privacy;
180 /// If set, we attempt to negotiate the `scid_privacy` (referred to as `scid_alias` in the
181 /// BOLTs) option for outbound private channels. This provides better privacy by not including
182 /// our real on-chain channel UTXO in each invoice and requiring that our counterparty only
183 /// relay HTLCs to us using the channel's SCID alias.
185 /// If this option is set, channels may be created that will not be readable by LDK versions
186 /// prior to 0.0.106, causing [`ChannelManager`]'s read method to return a
187 /// [`DecodeError:InvalidValue`].
189 /// Note that setting this to true does *not* prevent us from opening channels with
190 /// counterparties that do not support the `scid_alias` option; we will simply fall back to a
191 /// private channel without that option.
193 /// Ignored if the channel is negotiated to be announced, see
194 /// [`ChannelConfig::announced_channel`] and
195 /// [`ChannelHandshakeLimits::force_announced_channel_preference`] for more.
197 /// Default value: false. This value is likely to change to true in the future.
199 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
200 /// [`DecodeError:InvalidValue`]: crate::ln::msgs::DecodeError::InvalidValue
202 pub extern "C" fn ChannelHandshakeConfig_set_negotiate_scid_privacy(this_ptr: &mut ChannelHandshakeConfig, mut val: bool) {
203 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.negotiate_scid_privacy = val;
205 /// Constructs a new ChannelHandshakeConfig given each field
208 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 negotiate_scid_privacy_arg: bool) -> ChannelHandshakeConfig {
209 ChannelHandshakeConfig { inner: ObjOps::heap_alloc(nativeChannelHandshakeConfig {
210 minimum_depth: minimum_depth_arg,
211 our_to_self_delay: our_to_self_delay_arg,
212 our_htlc_minimum_msat: our_htlc_minimum_msat_arg,
213 negotiate_scid_privacy: negotiate_scid_privacy_arg,
216 impl Clone for ChannelHandshakeConfig {
217 fn clone(&self) -> Self {
219 inner: if <*mut nativeChannelHandshakeConfig>::is_null(self.inner) { core::ptr::null_mut() } else {
220 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
226 /// Used only if an object of this type is returned as a trait impl by a method
227 pub(crate) extern "C" fn ChannelHandshakeConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
228 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeConfig)).clone() })) as *mut c_void
231 /// Creates a copy of the ChannelHandshakeConfig
232 pub extern "C" fn ChannelHandshakeConfig_clone(orig: &ChannelHandshakeConfig) -> ChannelHandshakeConfig {
235 /// Creates a "default" ChannelHandshakeConfig. See struct and individual field documentaiton for details on which values are used.
238 pub extern "C" fn ChannelHandshakeConfig_default() -> ChannelHandshakeConfig {
239 ChannelHandshakeConfig { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
242 use lightning::util::config::ChannelHandshakeLimits as nativeChannelHandshakeLimitsImport;
243 pub(crate) type nativeChannelHandshakeLimits = nativeChannelHandshakeLimitsImport;
245 /// Optional channel limits which are applied during channel creation.
247 /// These limits are only applied to our counterparty's limits, not our own.
249 /// Use 0/<type>::max_value() as appropriate to skip checking.
251 /// Provides sane defaults for most configurations.
253 /// Most additional limits are disabled except those with which specify a default in individual
254 /// field documentation. Note that this may result in barely-usable channels, but since they
255 /// are applied mostly only to incoming channels that's not much of a problem.
258 pub struct ChannelHandshakeLimits {
259 /// A pointer to the opaque Rust object.
261 /// Nearly everywhere, inner must be non-null, however in places where
262 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
263 pub inner: *mut nativeChannelHandshakeLimits,
264 /// Indicates that this is the only struct which contains the same pointer.
266 /// Rust functions which take ownership of an object provided via an argument require
267 /// this to be true and invalidate the object pointed to by inner.
271 impl Drop for ChannelHandshakeLimits {
273 if self.is_owned && !<*mut nativeChannelHandshakeLimits>::is_null(self.inner) {
274 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
278 /// Frees any resources used by the ChannelHandshakeLimits, if is_owned is set and inner is non-NULL.
280 pub extern "C" fn ChannelHandshakeLimits_free(this_obj: ChannelHandshakeLimits) { }
282 /// Used only if an object of this type is returned as a trait impl by a method
283 pub(crate) extern "C" fn ChannelHandshakeLimits_free_void(this_ptr: *mut c_void) {
284 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelHandshakeLimits); }
287 impl ChannelHandshakeLimits {
288 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelHandshakeLimits {
289 unsafe { &*ObjOps::untweak_ptr(self.inner) }
291 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelHandshakeLimits {
292 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
294 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
295 pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeLimits {
296 assert!(self.is_owned);
297 let ret = ObjOps::untweak_ptr(self.inner);
298 self.inner = core::ptr::null_mut();
302 /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
303 /// only applies to inbound channels.
305 /// Default value: 0.
307 pub extern "C" fn ChannelHandshakeLimits_get_min_funding_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
308 let mut inner_val = &mut this_ptr.get_native_mut_ref().min_funding_satoshis;
311 /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
312 /// only applies to inbound channels.
314 /// Default value: 0.
316 pub extern "C" fn ChannelHandshakeLimits_set_min_funding_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
317 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.min_funding_satoshis = val;
319 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
320 /// you to limit the maximum minimum-size they can require.
322 /// Default value: u64::max_value.
324 pub extern "C" fn ChannelHandshakeLimits_get_max_htlc_minimum_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
325 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_htlc_minimum_msat;
328 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
329 /// you to limit the maximum minimum-size they can require.
331 /// Default value: u64::max_value.
333 pub extern "C" fn ChannelHandshakeLimits_set_max_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
334 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_htlc_minimum_msat = val;
336 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
337 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
339 /// Default value: 0.
341 pub extern "C" fn ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
342 let mut inner_val = &mut this_ptr.get_native_mut_ref().min_max_htlc_value_in_flight_msat;
345 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
346 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
348 /// Default value: 0.
350 pub extern "C" fn ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
351 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.min_max_htlc_value_in_flight_msat = val;
353 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
354 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
355 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
357 /// Default value: u64::max_value.
359 pub extern "C" fn ChannelHandshakeLimits_get_max_channel_reserve_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
360 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_channel_reserve_satoshis;
363 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
364 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
365 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
367 /// Default value: u64::max_value.
369 pub extern "C" fn ChannelHandshakeLimits_set_max_channel_reserve_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
370 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_channel_reserve_satoshis = val;
372 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
373 /// time. This allows you to set a minimum such value.
375 /// Default value: 0.
377 pub extern "C" fn ChannelHandshakeLimits_get_min_max_accepted_htlcs(this_ptr: &ChannelHandshakeLimits) -> u16 {
378 let mut inner_val = &mut this_ptr.get_native_mut_ref().min_max_accepted_htlcs;
381 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
382 /// time. This allows you to set a minimum such value.
384 /// Default value: 0.
386 pub extern "C" fn ChannelHandshakeLimits_set_min_max_accepted_htlcs(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
387 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.min_max_accepted_htlcs = val;
389 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
390 /// certain number of blocks, specified by the node which is not the funder (as the funder can
391 /// assume they aren't going to double-spend themselves).
392 /// This config allows you to set a limit on the maximum amount of time to wait.
394 /// Default value: 144, or roughly one day and only applies to outbound channels.
396 pub extern "C" fn ChannelHandshakeLimits_get_max_minimum_depth(this_ptr: &ChannelHandshakeLimits) -> u32 {
397 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_minimum_depth;
400 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
401 /// certain number of blocks, specified by the node which is not the funder (as the funder can
402 /// assume they aren't going to double-spend themselves).
403 /// This config allows you to set a limit on the maximum amount of time to wait.
405 /// Default value: 144, or roughly one day and only applies to outbound channels.
407 pub extern "C" fn ChannelHandshakeLimits_set_max_minimum_depth(this_ptr: &mut ChannelHandshakeLimits, mut val: u32) {
408 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_minimum_depth = val;
410 /// Set to force an incoming channel to match our announced channel preference in
411 /// [`ChannelConfig::announced_channel`].
413 /// For a node which is not online reliably, this should be set to true and
414 /// [`ChannelConfig::announced_channel`] set to false, ensuring that no announced (aka public)
415 /// channels will ever be opened.
417 /// Default value: true.
419 pub extern "C" fn ChannelHandshakeLimits_get_force_announced_channel_preference(this_ptr: &ChannelHandshakeLimits) -> bool {
420 let mut inner_val = &mut this_ptr.get_native_mut_ref().force_announced_channel_preference;
423 /// Set to force an incoming channel to match our announced channel preference in
424 /// [`ChannelConfig::announced_channel`].
426 /// For a node which is not online reliably, this should be set to true and
427 /// [`ChannelConfig::announced_channel`] set to false, ensuring that no announced (aka public)
428 /// channels will ever be opened.
430 /// Default value: true.
432 pub extern "C" fn ChannelHandshakeLimits_set_force_announced_channel_preference(this_ptr: &mut ChannelHandshakeLimits, mut val: bool) {
433 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.force_announced_channel_preference = val;
435 /// Set to the amount of time we're willing to wait to claim money back to us.
437 /// Not checking this value would be a security issue, as our peer would be able to set it to
438 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
440 /// Default value: 2016, which we also enforce as a maximum value so you can tweak config to
441 /// reduce the loss of having useless locked funds (if your peer accepts)
443 pub extern "C" fn ChannelHandshakeLimits_get_their_to_self_delay(this_ptr: &ChannelHandshakeLimits) -> u16 {
444 let mut inner_val = &mut this_ptr.get_native_mut_ref().their_to_self_delay;
447 /// Set to the amount of time we're willing to wait to claim money back to us.
449 /// Not checking this value would be a security issue, as our peer would be able to set it to
450 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
452 /// Default value: 2016, which we also enforce as a maximum value so you can tweak config to
453 /// reduce the loss of having useless locked funds (if your peer accepts)
455 pub extern "C" fn ChannelHandshakeLimits_set_their_to_self_delay(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
456 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.their_to_self_delay = val;
458 /// Constructs a new ChannelHandshakeLimits given each field
461 pub extern "C" fn ChannelHandshakeLimits_new(mut min_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 force_announced_channel_preference_arg: bool, mut their_to_self_delay_arg: u16) -> ChannelHandshakeLimits {
462 ChannelHandshakeLimits { inner: ObjOps::heap_alloc(nativeChannelHandshakeLimits {
463 min_funding_satoshis: min_funding_satoshis_arg,
464 max_htlc_minimum_msat: max_htlc_minimum_msat_arg,
465 min_max_htlc_value_in_flight_msat: min_max_htlc_value_in_flight_msat_arg,
466 max_channel_reserve_satoshis: max_channel_reserve_satoshis_arg,
467 min_max_accepted_htlcs: min_max_accepted_htlcs_arg,
468 max_minimum_depth: max_minimum_depth_arg,
469 force_announced_channel_preference: force_announced_channel_preference_arg,
470 their_to_self_delay: their_to_self_delay_arg,
473 impl Clone for ChannelHandshakeLimits {
474 fn clone(&self) -> Self {
476 inner: if <*mut nativeChannelHandshakeLimits>::is_null(self.inner) { core::ptr::null_mut() } else {
477 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
483 /// Used only if an object of this type is returned as a trait impl by a method
484 pub(crate) extern "C" fn ChannelHandshakeLimits_clone_void(this_ptr: *const c_void) -> *mut c_void {
485 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeLimits)).clone() })) as *mut c_void
488 /// Creates a copy of the ChannelHandshakeLimits
489 pub extern "C" fn ChannelHandshakeLimits_clone(orig: &ChannelHandshakeLimits) -> ChannelHandshakeLimits {
492 /// Creates a "default" ChannelHandshakeLimits. See struct and individual field documentaiton for details on which values are used.
495 pub extern "C" fn ChannelHandshakeLimits_default() -> ChannelHandshakeLimits {
496 ChannelHandshakeLimits { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
499 use lightning::util::config::ChannelConfig as nativeChannelConfigImport;
500 pub(crate) type nativeChannelConfig = nativeChannelConfigImport;
502 /// Options which apply on a per-channel basis and may change at runtime or based on negotiation
503 /// with our counterparty.
506 pub struct ChannelConfig {
507 /// A pointer to the opaque Rust object.
509 /// Nearly everywhere, inner must be non-null, however in places where
510 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
511 pub inner: *mut nativeChannelConfig,
512 /// Indicates that this is the only struct which contains the same pointer.
514 /// Rust functions which take ownership of an object provided via an argument require
515 /// this to be true and invalidate the object pointed to by inner.
519 impl Drop for ChannelConfig {
521 if self.is_owned && !<*mut nativeChannelConfig>::is_null(self.inner) {
522 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
526 /// Frees any resources used by the ChannelConfig, if is_owned is set and inner is non-NULL.
528 pub extern "C" fn ChannelConfig_free(this_obj: ChannelConfig) { }
530 /// Used only if an object of this type is returned as a trait impl by a method
531 pub(crate) extern "C" fn ChannelConfig_free_void(this_ptr: *mut c_void) {
532 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelConfig); }
536 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelConfig {
537 unsafe { &*ObjOps::untweak_ptr(self.inner) }
539 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelConfig {
540 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
542 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
543 pub(crate) fn take_inner(mut self) -> *mut nativeChannelConfig {
544 assert!(self.is_owned);
545 let ret = ObjOps::untweak_ptr(self.inner);
546 self.inner = core::ptr::null_mut();
550 /// Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
551 /// over the channel.
552 /// This may be allowed to change at runtime in a later update, however doing so must result in
553 /// update messages sent to notify all nodes of our updated relay fee.
555 /// Default value: 0.
557 pub extern "C" fn ChannelConfig_get_forwarding_fee_proportional_millionths(this_ptr: &ChannelConfig) -> u32 {
558 let mut inner_val = &mut this_ptr.get_native_mut_ref().forwarding_fee_proportional_millionths;
561 /// Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
562 /// over the channel.
563 /// This may be allowed to change at runtime in a later update, however doing so must result in
564 /// update messages sent to notify all nodes of our updated relay fee.
566 /// Default value: 0.
568 pub extern "C" fn ChannelConfig_set_forwarding_fee_proportional_millionths(this_ptr: &mut ChannelConfig, mut val: u32) {
569 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.forwarding_fee_proportional_millionths = val;
571 /// Amount (in milli-satoshi) charged for payments forwarded outbound over the channel, in
572 /// excess of [`forwarding_fee_proportional_millionths`].
573 /// This may be allowed to change at runtime in a later update, however doing so must result in
574 /// update messages sent to notify all nodes of our updated relay fee.
576 /// The default value of a single satoshi roughly matches the market rate on many routing nodes
577 /// as of July 2021. Adjusting it upwards or downwards may change whether nodes route through
580 /// Default value: 1000.
582 /// [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
584 pub extern "C" fn ChannelConfig_get_forwarding_fee_base_msat(this_ptr: &ChannelConfig) -> u32 {
585 let mut inner_val = &mut this_ptr.get_native_mut_ref().forwarding_fee_base_msat;
588 /// Amount (in milli-satoshi) charged for payments forwarded outbound over the channel, in
589 /// excess of [`forwarding_fee_proportional_millionths`].
590 /// This may be allowed to change at runtime in a later update, however doing so must result in
591 /// update messages sent to notify all nodes of our updated relay fee.
593 /// The default value of a single satoshi roughly matches the market rate on many routing nodes
594 /// as of July 2021. Adjusting it upwards or downwards may change whether nodes route through
597 /// Default value: 1000.
599 /// [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
601 pub extern "C" fn ChannelConfig_set_forwarding_fee_base_msat(this_ptr: &mut ChannelConfig, mut val: u32) {
602 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.forwarding_fee_base_msat = val;
604 /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
605 /// the channel this config applies to.
607 /// This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
608 /// HTLC balance when a channel appears on-chain whereas
609 /// [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
610 /// (non-HTLC-encumbered) balance.
612 /// Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
613 /// we (or one of our watchtowers) MUST be online to check for broadcast of the current
614 /// commitment transaction at least once per this many blocks (minus some margin to allow us
615 /// enough time to broadcast and confirm a transaction, possibly with time in between to RBF
616 /// the spending transaction).
618 /// Default value: 72 (12 hours at an average of 6 blocks/hour).
619 /// Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
620 /// [`MIN_CLTV_EXPIRY_DELTA`] instead.
622 /// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
624 pub extern "C" fn ChannelConfig_get_cltv_expiry_delta(this_ptr: &ChannelConfig) -> u16 {
625 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
628 /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
629 /// the channel this config applies to.
631 /// This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
632 /// HTLC balance when a channel appears on-chain whereas
633 /// [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
634 /// (non-HTLC-encumbered) balance.
636 /// Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
637 /// we (or one of our watchtowers) MUST be online to check for broadcast of the current
638 /// commitment transaction at least once per this many blocks (minus some margin to allow us
639 /// enough time to broadcast and confirm a transaction, possibly with time in between to RBF
640 /// the spending transaction).
642 /// Default value: 72 (12 hours at an average of 6 blocks/hour).
643 /// Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
644 /// [`MIN_CLTV_EXPIRY_DELTA`] instead.
646 /// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
648 pub extern "C" fn ChannelConfig_set_cltv_expiry_delta(this_ptr: &mut ChannelConfig, mut val: u16) {
649 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
651 /// Set to announce the channel publicly and notify all nodes that they can route via this
654 /// This should only be set to true for nodes which expect to be online reliably.
656 /// As the node which funds a channel picks this value this will only apply for new outbound
657 /// channels unless [`ChannelHandshakeLimits::force_announced_channel_preference`] is set.
659 /// This cannot be changed after the initial channel handshake.
661 /// Default value: false.
663 pub extern "C" fn ChannelConfig_get_announced_channel(this_ptr: &ChannelConfig) -> bool {
664 let mut inner_val = &mut this_ptr.get_native_mut_ref().announced_channel;
667 /// Set to announce the channel publicly and notify all nodes that they can route via this
670 /// This should only be set to true for nodes which expect to be online reliably.
672 /// As the node which funds a channel picks this value this will only apply for new outbound
673 /// channels unless [`ChannelHandshakeLimits::force_announced_channel_preference`] is set.
675 /// This cannot be changed after the initial channel handshake.
677 /// Default value: false.
679 pub extern "C" fn ChannelConfig_set_announced_channel(this_ptr: &mut ChannelConfig, mut val: bool) {
680 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announced_channel = val;
682 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
683 /// supports it, they will then enforce the mutual-close output to us matches what we provided
684 /// at intialization, preventing us from closing to an alternate pubkey.
686 /// This is set to true by default to provide a slight increase in security, though ultimately
687 /// any attacker who is able to take control of a channel can just as easily send the funds via
688 /// lightning payments, so we never require that our counterparties support this option.
690 /// This cannot be changed after a channel has been initialized.
692 /// Default value: true.
694 pub extern "C" fn ChannelConfig_get_commit_upfront_shutdown_pubkey(this_ptr: &ChannelConfig) -> bool {
695 let mut inner_val = &mut this_ptr.get_native_mut_ref().commit_upfront_shutdown_pubkey;
698 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
699 /// supports it, they will then enforce the mutual-close output to us matches what we provided
700 /// at intialization, preventing us from closing to an alternate pubkey.
702 /// This is set to true by default to provide a slight increase in security, though ultimately
703 /// any attacker who is able to take control of a channel can just as easily send the funds via
704 /// lightning payments, so we never require that our counterparties support this option.
706 /// This cannot be changed after a channel has been initialized.
708 /// Default value: true.
710 pub extern "C" fn ChannelConfig_set_commit_upfront_shutdown_pubkey(this_ptr: &mut ChannelConfig, mut val: bool) {
711 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.commit_upfront_shutdown_pubkey = val;
713 /// Limit our total exposure to in-flight HTLCs which are burned to fees as they are too
714 /// small to claim on-chain.
716 /// When an HTLC present in one of our channels is below a \"dust\" threshold, the HTLC will
717 /// not be claimable on-chain, instead being turned into additional miner fees if either
718 /// party force-closes the channel. Because the threshold is per-HTLC, our total exposure
719 /// to such payments may be sustantial if there are many dust HTLCs present when the
720 /// channel is force-closed.
722 /// This limit is applied for sent, forwarded, and received HTLCs and limits the total
723 /// exposure across all three types per-channel. Setting this too low may prevent the
724 /// sending or receipt of low-value HTLCs on high-traffic nodes, and this limit is very
725 /// important to prevent stealing of dust HTLCs by miners.
727 /// Default value: 5_000_000 msat.
729 pub extern "C" fn ChannelConfig_get_max_dust_htlc_exposure_msat(this_ptr: &ChannelConfig) -> u64 {
730 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_dust_htlc_exposure_msat;
733 /// Limit our total exposure to in-flight HTLCs which are burned to fees as they are too
734 /// small to claim on-chain.
736 /// When an HTLC present in one of our channels is below a \"dust\" threshold, the HTLC will
737 /// not be claimable on-chain, instead being turned into additional miner fees if either
738 /// party force-closes the channel. Because the threshold is per-HTLC, our total exposure
739 /// to such payments may be sustantial if there are many dust HTLCs present when the
740 /// channel is force-closed.
742 /// This limit is applied for sent, forwarded, and received HTLCs and limits the total
743 /// exposure across all three types per-channel. Setting this too low may prevent the
744 /// sending or receipt of low-value HTLCs on high-traffic nodes, and this limit is very
745 /// important to prevent stealing of dust HTLCs by miners.
747 /// Default value: 5_000_000 msat.
749 pub extern "C" fn ChannelConfig_set_max_dust_htlc_exposure_msat(this_ptr: &mut ChannelConfig, mut val: u64) {
750 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_dust_htlc_exposure_msat = val;
752 /// The additional fee we're willing to pay to avoid waiting for the counterparty's
753 /// `to_self_delay` to reclaim funds.
755 /// When we close a channel cooperatively with our counterparty, we negotiate a fee for the
756 /// closing transaction which both sides find acceptable, ultimately paid by the channel
757 /// funder/initiator.
759 /// When we are the funder, because we have to pay the channel closing fee, we bound the
760 /// acceptable fee by our [`Background`] and [`Normal`] fees, with the upper bound increased by
761 /// this value. Because the on-chain fee we'd pay to force-close the channel is kept near our
762 /// [`Normal`] feerate during normal operation, this value represents the additional fee we're
763 /// willing to pay in order to avoid waiting for our counterparty's to_self_delay to reclaim our
766 /// When we are not the funder, we require the closing transaction fee pay at least our
767 /// [`Background`] fee estimate, but allow our counterparty to pay as much fee as they like.
768 /// Thus, this value is ignored when we are not the funder.
770 /// Default value: 1000 satoshis.
772 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
773 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
775 pub extern "C" fn ChannelConfig_get_force_close_avoidance_max_fee_satoshis(this_ptr: &ChannelConfig) -> u64 {
776 let mut inner_val = &mut this_ptr.get_native_mut_ref().force_close_avoidance_max_fee_satoshis;
779 /// The additional fee we're willing to pay to avoid waiting for the counterparty's
780 /// `to_self_delay` to reclaim funds.
782 /// When we close a channel cooperatively with our counterparty, we negotiate a fee for the
783 /// closing transaction which both sides find acceptable, ultimately paid by the channel
784 /// funder/initiator.
786 /// When we are the funder, because we have to pay the channel closing fee, we bound the
787 /// acceptable fee by our [`Background`] and [`Normal`] fees, with the upper bound increased by
788 /// this value. Because the on-chain fee we'd pay to force-close the channel is kept near our
789 /// [`Normal`] feerate during normal operation, this value represents the additional fee we're
790 /// willing to pay in order to avoid waiting for our counterparty's to_self_delay to reclaim our
793 /// When we are not the funder, we require the closing transaction fee pay at least our
794 /// [`Background`] fee estimate, but allow our counterparty to pay as much fee as they like.
795 /// Thus, this value is ignored when we are not the funder.
797 /// Default value: 1000 satoshis.
799 /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
800 /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
802 pub extern "C" fn ChannelConfig_set_force_close_avoidance_max_fee_satoshis(this_ptr: &mut ChannelConfig, mut val: u64) {
803 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.force_close_avoidance_max_fee_satoshis = val;
805 /// Constructs a new ChannelConfig given each field
808 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 announced_channel_arg: bool, mut commit_upfront_shutdown_pubkey_arg: bool, mut max_dust_htlc_exposure_msat_arg: u64, mut force_close_avoidance_max_fee_satoshis_arg: u64) -> ChannelConfig {
809 ChannelConfig { inner: ObjOps::heap_alloc(nativeChannelConfig {
810 forwarding_fee_proportional_millionths: forwarding_fee_proportional_millionths_arg,
811 forwarding_fee_base_msat: forwarding_fee_base_msat_arg,
812 cltv_expiry_delta: cltv_expiry_delta_arg,
813 announced_channel: announced_channel_arg,
814 commit_upfront_shutdown_pubkey: commit_upfront_shutdown_pubkey_arg,
815 max_dust_htlc_exposure_msat: max_dust_htlc_exposure_msat_arg,
816 force_close_avoidance_max_fee_satoshis: force_close_avoidance_max_fee_satoshis_arg,
819 impl Clone for ChannelConfig {
820 fn clone(&self) -> Self {
822 inner: if <*mut nativeChannelConfig>::is_null(self.inner) { core::ptr::null_mut() } else {
823 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
829 /// Used only if an object of this type is returned as a trait impl by a method
830 pub(crate) extern "C" fn ChannelConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
831 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelConfig)).clone() })) as *mut c_void
834 /// Creates a copy of the ChannelConfig
835 pub extern "C" fn ChannelConfig_clone(orig: &ChannelConfig) -> ChannelConfig {
838 /// Creates a "default" ChannelConfig. See struct and individual field documentaiton for details on which values are used.
841 pub extern "C" fn ChannelConfig_default() -> ChannelConfig {
842 ChannelConfig { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
845 /// Serialize the ChannelConfig object into a byte array which can be read by ChannelConfig_read
846 pub extern "C" fn ChannelConfig_write(obj: &crate::lightning::util::config::ChannelConfig) -> crate::c_types::derived::CVec_u8Z {
847 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
850 pub(crate) extern "C" fn ChannelConfig_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
851 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelConfig) })
854 /// Read a ChannelConfig from a byte array, created by ChannelConfig_write
855 pub extern "C" fn ChannelConfig_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelConfigDecodeErrorZ {
856 let res: Result<lightning::util::config::ChannelConfig, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
857 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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
861 use lightning::util::config::UserConfig as nativeUserConfigImport;
862 pub(crate) type nativeUserConfig = nativeUserConfigImport;
864 /// Top-level config which holds ChannelHandshakeLimits and ChannelConfig.
866 /// Default::default() provides sane defaults for most configurations
867 /// (but currently with 0 relay fees!)
870 pub struct UserConfig {
871 /// A pointer to the opaque Rust object.
873 /// Nearly everywhere, inner must be non-null, however in places where
874 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
875 pub inner: *mut nativeUserConfig,
876 /// Indicates that this is the only struct which contains the same pointer.
878 /// Rust functions which take ownership of an object provided via an argument require
879 /// this to be true and invalidate the object pointed to by inner.
883 impl Drop for UserConfig {
885 if self.is_owned && !<*mut nativeUserConfig>::is_null(self.inner) {
886 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
890 /// Frees any resources used by the UserConfig, if is_owned is set and inner is non-NULL.
892 pub extern "C" fn UserConfig_free(this_obj: UserConfig) { }
894 /// Used only if an object of this type is returned as a trait impl by a method
895 pub(crate) extern "C" fn UserConfig_free_void(this_ptr: *mut c_void) {
896 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUserConfig); }
900 pub(crate) fn get_native_ref(&self) -> &'static nativeUserConfig {
901 unsafe { &*ObjOps::untweak_ptr(self.inner) }
903 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeUserConfig {
904 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
906 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
907 pub(crate) fn take_inner(mut self) -> *mut nativeUserConfig {
908 assert!(self.is_owned);
909 let ret = ObjOps::untweak_ptr(self.inner);
910 self.inner = core::ptr::null_mut();
914 /// Channel config that we propose to our counterparty.
916 pub extern "C" fn UserConfig_get_own_channel_config(this_ptr: &UserConfig) -> crate::lightning::util::config::ChannelHandshakeConfig {
917 let mut inner_val = &mut this_ptr.get_native_mut_ref().own_channel_config;
918 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 }
920 /// Channel config that we propose to our counterparty.
922 pub extern "C" fn UserConfig_set_own_channel_config(this_ptr: &mut UserConfig, mut val: crate::lightning::util::config::ChannelHandshakeConfig) {
923 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.own_channel_config = *unsafe { Box::from_raw(val.take_inner()) };
925 /// Limits applied to our counterparty's proposed channel config settings.
927 pub extern "C" fn UserConfig_get_peer_channel_config_limits(this_ptr: &UserConfig) -> crate::lightning::util::config::ChannelHandshakeLimits {
928 let mut inner_val = &mut this_ptr.get_native_mut_ref().peer_channel_config_limits;
929 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 }
931 /// Limits applied to our counterparty's proposed channel config settings.
933 pub extern "C" fn UserConfig_set_peer_channel_config_limits(this_ptr: &mut UserConfig, mut val: crate::lightning::util::config::ChannelHandshakeLimits) {
934 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.peer_channel_config_limits = *unsafe { Box::from_raw(val.take_inner()) };
936 /// Channel config which affects behavior during channel lifetime.
938 pub extern "C" fn UserConfig_get_channel_options(this_ptr: &UserConfig) -> crate::lightning::util::config::ChannelConfig {
939 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_options;
940 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 }
942 /// Channel config which affects behavior during channel lifetime.
944 pub extern "C" fn UserConfig_set_channel_options(this_ptr: &mut UserConfig, mut val: crate::lightning::util::config::ChannelConfig) {
945 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_options = *unsafe { Box::from_raw(val.take_inner()) };
947 /// If this is set to false, we will reject any HTLCs which were to be forwarded over private
948 /// channels. This prevents us from taking on HTLC-forwarding risk when we intend to run as a
949 /// node which is not online reliably.
951 /// For nodes which are not online reliably, you should set all channels to *not* be announced
952 /// (using [`ChannelConfig::announced_channel`] and
953 /// [`ChannelHandshakeLimits::force_announced_channel_preference`]) and set this to false to
954 /// ensure you are not exposed to any forwarding risk.
956 /// Note that because you cannot change a channel's announced state after creation, there is no
957 /// way to disable forwarding on public channels retroactively. Thus, in order to change a node
958 /// from a publicly-announced forwarding node to a private non-forwarding node you must close
959 /// all your channels and open new ones. For privacy, you should also change your node_id
960 /// (swapping all private and public key material for new ones) at that time.
962 /// Default value: false.
964 pub extern "C" fn UserConfig_get_accept_forwards_to_priv_channels(this_ptr: &UserConfig) -> bool {
965 let mut inner_val = &mut this_ptr.get_native_mut_ref().accept_forwards_to_priv_channels;
968 /// If this is set to false, we will reject any HTLCs which were to be forwarded over private
969 /// channels. This prevents us from taking on HTLC-forwarding risk when we intend to run as a
970 /// node which is not online reliably.
972 /// For nodes which are not online reliably, you should set all channels to *not* be announced
973 /// (using [`ChannelConfig::announced_channel`] and
974 /// [`ChannelHandshakeLimits::force_announced_channel_preference`]) and set this to false to
975 /// ensure you are not exposed to any forwarding risk.
977 /// Note that because you cannot change a channel's announced state after creation, there is no
978 /// way to disable forwarding on public channels retroactively. Thus, in order to change a node
979 /// from a publicly-announced forwarding node to a private non-forwarding node you must close
980 /// all your channels and open new ones. For privacy, you should also change your node_id
981 /// (swapping all private and public key material for new ones) at that time.
983 /// Default value: false.
985 pub extern "C" fn UserConfig_set_accept_forwards_to_priv_channels(this_ptr: &mut UserConfig, mut val: bool) {
986 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.accept_forwards_to_priv_channels = val;
988 /// If this is set to false, we do not accept inbound requests to open a new channel.
989 /// Default value: true.
991 pub extern "C" fn UserConfig_get_accept_inbound_channels(this_ptr: &UserConfig) -> bool {
992 let mut inner_val = &mut this_ptr.get_native_mut_ref().accept_inbound_channels;
995 /// If this is set to false, we do not accept inbound requests to open a new channel.
996 /// Default value: true.
998 pub extern "C" fn UserConfig_set_accept_inbound_channels(this_ptr: &mut UserConfig, mut val: bool) {
999 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.accept_inbound_channels = val;
1001 /// If this is set to true, the user needs to manually accept inbound requests to open a new
1004 /// When set to true, [`Event::OpenChannelRequest`] will be triggered once a request to open a
1005 /// new inbound channel is received through a [`msgs::OpenChannel`] message. In that case, a
1006 /// [`msgs::AcceptChannel`] message will not be sent back to the counterparty node unless the
1007 /// user explicitly chooses to accept the request.
1009 /// Default value: false.
1011 /// [`Event::OpenChannelRequest`]: crate::util::events::Event::OpenChannelRequest
1012 /// [`msgs::OpenChannel`]: crate::ln::msgs::OpenChannel
1013 /// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
1015 pub extern "C" fn UserConfig_get_manually_accept_inbound_channels(this_ptr: &UserConfig) -> bool {
1016 let mut inner_val = &mut this_ptr.get_native_mut_ref().manually_accept_inbound_channels;
1019 /// If this is set to true, the user needs to manually accept inbound requests to open a new
1022 /// When set to true, [`Event::OpenChannelRequest`] will be triggered once a request to open a
1023 /// new inbound channel is received through a [`msgs::OpenChannel`] message. In that case, a
1024 /// [`msgs::AcceptChannel`] message will not be sent back to the counterparty node unless the
1025 /// user explicitly chooses to accept the request.
1027 /// Default value: false.
1029 /// [`Event::OpenChannelRequest`]: crate::util::events::Event::OpenChannelRequest
1030 /// [`msgs::OpenChannel`]: crate::ln::msgs::OpenChannel
1031 /// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
1033 pub extern "C" fn UserConfig_set_manually_accept_inbound_channels(this_ptr: &mut UserConfig, mut val: bool) {
1034 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.manually_accept_inbound_channels = val;
1036 /// Constructs a new UserConfig given each field
1039 pub extern "C" fn UserConfig_new(mut own_channel_config_arg: crate::lightning::util::config::ChannelHandshakeConfig, mut peer_channel_config_limits_arg: crate::lightning::util::config::ChannelHandshakeLimits, mut channel_options_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) -> UserConfig {
1040 UserConfig { inner: ObjOps::heap_alloc(nativeUserConfig {
1041 own_channel_config: *unsafe { Box::from_raw(own_channel_config_arg.take_inner()) },
1042 peer_channel_config_limits: *unsafe { Box::from_raw(peer_channel_config_limits_arg.take_inner()) },
1043 channel_options: *unsafe { Box::from_raw(channel_options_arg.take_inner()) },
1044 accept_forwards_to_priv_channels: accept_forwards_to_priv_channels_arg,
1045 accept_inbound_channels: accept_inbound_channels_arg,
1046 manually_accept_inbound_channels: manually_accept_inbound_channels_arg,
1047 }), is_owned: true }
1049 impl Clone for UserConfig {
1050 fn clone(&self) -> Self {
1052 inner: if <*mut nativeUserConfig>::is_null(self.inner) { core::ptr::null_mut() } else {
1053 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1059 /// Used only if an object of this type is returned as a trait impl by a method
1060 pub(crate) extern "C" fn UserConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
1061 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUserConfig)).clone() })) as *mut c_void
1064 /// Creates a copy of the UserConfig
1065 pub extern "C" fn UserConfig_clone(orig: &UserConfig) -> UserConfig {
1068 /// Creates a "default" UserConfig. See struct and individual field documentaiton for details on which values are used.
1071 pub extern "C" fn UserConfig_default() -> UserConfig {
1072 UserConfig { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }