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 std::str::FromStr;
14 use bitcoin::hashes::Hash;
15 use crate::c_types::*;
18 use lightning::util::config::ChannelHandshakeConfig as nativeChannelHandshakeConfigImport;
19 type nativeChannelHandshakeConfig = nativeChannelHandshakeConfigImport;
21 /// Configuration we set when applicable.
23 /// Default::default() provides sane defaults.
26 pub struct ChannelHandshakeConfig {
27 /// A pointer to the opaque Rust object.
29 /// Nearly everywhere, inner must be non-null, however in places where
30 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
31 pub inner: *mut nativeChannelHandshakeConfig,
32 /// Indicates that this is the only struct which contains the same pointer.
34 /// Rust functions which take ownership of an object provided via an argument require
35 /// this to be true and invalidate the object pointed to by inner.
39 impl Drop for ChannelHandshakeConfig {
41 if self.is_owned && !<*mut nativeChannelHandshakeConfig>::is_null(self.inner) {
42 let _ = unsafe { Box::from_raw(self.inner) };
46 /// Frees any resources used by the ChannelHandshakeConfig, if is_owned is set and inner is non-NULL.
48 pub extern "C" fn ChannelHandshakeConfig_free(this_obj: ChannelHandshakeConfig) { }
50 /// Used only if an object of this type is returned as a trait impl by a method
51 extern "C" fn ChannelHandshakeConfig_free_void(this_ptr: *mut c_void) {
52 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelHandshakeConfig); }
55 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
56 impl ChannelHandshakeConfig {
57 pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeConfig {
58 assert!(self.is_owned);
60 self.inner = std::ptr::null_mut();
64 /// Confirmations we will wait for before considering the channel locked in.
65 /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
66 /// equivalent limit applied to outbound channels).
70 pub extern "C" fn ChannelHandshakeConfig_get_minimum_depth(this_ptr: &ChannelHandshakeConfig) -> u32 {
71 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.minimum_depth;
74 /// Confirmations we will wait for before considering the channel locked in.
75 /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
76 /// equivalent limit applied to outbound channels).
80 pub extern "C" fn ChannelHandshakeConfig_set_minimum_depth(this_ptr: &mut ChannelHandshakeConfig, mut val: u32) {
81 unsafe { &mut *this_ptr.inner }.minimum_depth = val;
83 /// Set to the number of blocks we require our counterparty to wait to claim their money (ie
84 /// the number of blocks we have to punish our counterparty if they broadcast a revoked
87 /// This is one of the main parameters of our security model. We (or one of our watchtowers) MUST
88 /// be online to check for revoked transactions on-chain at least once every our_to_self_delay
89 /// blocks (minus some margin to allow us enough time to broadcast and confirm a transaction,
90 /// possibly with time in between to RBF the spending transaction).
92 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
93 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
96 /// Default value: [`BREAKDOWN_TIMEOUT`], we enforce it as a minimum at channel opening so you
97 /// can tweak config to ask for more security, not less.
99 pub extern "C" fn ChannelHandshakeConfig_get_our_to_self_delay(this_ptr: &ChannelHandshakeConfig) -> u16 {
100 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.our_to_self_delay;
103 /// Set to the number of blocks we require our counterparty to wait to claim their money (ie
104 /// the number of blocks we have to punish our counterparty if they broadcast a revoked
107 /// This is one of the main parameters of our security model. We (or one of our watchtowers) MUST
108 /// be online to check for revoked transactions on-chain at least once every our_to_self_delay
109 /// blocks (minus some margin to allow us enough time to broadcast and confirm a transaction,
110 /// possibly with time in between to RBF the spending transaction).
112 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
113 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
116 /// Default value: [`BREAKDOWN_TIMEOUT`], we enforce it as a minimum at channel opening so you
117 /// can tweak config to ask for more security, not less.
119 pub extern "C" fn ChannelHandshakeConfig_set_our_to_self_delay(this_ptr: &mut ChannelHandshakeConfig, mut val: u16) {
120 unsafe { &mut *this_ptr.inner }.our_to_self_delay = val;
122 /// Set to the smallest value HTLC we will accept to process.
124 /// This value is sent to our counterparty on channel-open and we close the channel any time
125 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
127 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
130 pub extern "C" fn ChannelHandshakeConfig_get_our_htlc_minimum_msat(this_ptr: &ChannelHandshakeConfig) -> u64 {
131 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.our_htlc_minimum_msat;
134 /// Set to the smallest value HTLC we will accept to process.
136 /// This value is sent to our counterparty on channel-open and we close the channel any time
137 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
139 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
142 pub extern "C" fn ChannelHandshakeConfig_set_our_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeConfig, mut val: u64) {
143 unsafe { &mut *this_ptr.inner }.our_htlc_minimum_msat = val;
145 /// Constructs a new ChannelHandshakeConfig given each field
148 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) -> ChannelHandshakeConfig {
149 ChannelHandshakeConfig { inner: Box::into_raw(Box::new(nativeChannelHandshakeConfig {
150 minimum_depth: minimum_depth_arg,
151 our_to_self_delay: our_to_self_delay_arg,
152 our_htlc_minimum_msat: our_htlc_minimum_msat_arg,
153 })), is_owned: true }
155 impl Clone for ChannelHandshakeConfig {
156 fn clone(&self) -> Self {
158 inner: if <*mut nativeChannelHandshakeConfig>::is_null(self.inner) { std::ptr::null_mut() } else {
159 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
165 /// Used only if an object of this type is returned as a trait impl by a method
166 pub(crate) extern "C" fn ChannelHandshakeConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
167 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeConfig)).clone() })) as *mut c_void
170 /// Creates a copy of the ChannelHandshakeConfig
171 pub extern "C" fn ChannelHandshakeConfig_clone(orig: &ChannelHandshakeConfig) -> ChannelHandshakeConfig {
174 /// Creates a "default" ChannelHandshakeConfig. See struct and individual field documentaiton for details on which values are used.
177 pub extern "C" fn ChannelHandshakeConfig_default() -> ChannelHandshakeConfig {
178 ChannelHandshakeConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
181 use lightning::util::config::ChannelHandshakeLimits as nativeChannelHandshakeLimitsImport;
182 type nativeChannelHandshakeLimits = nativeChannelHandshakeLimitsImport;
184 /// Optional channel limits which are applied during channel creation.
186 /// These limits are only applied to our counterparty's limits, not our own.
188 /// Use 0/<type>::max_value() as appropriate to skip checking.
190 /// Provides sane defaults for most configurations.
192 /// Most additional limits are disabled except those with which specify a default in individual
193 /// field documentation. Note that this may result in barely-usable channels, but since they
194 /// are applied mostly only to incoming channels that's not much of a problem.
197 pub struct ChannelHandshakeLimits {
198 /// A pointer to the opaque Rust object.
200 /// Nearly everywhere, inner must be non-null, however in places where
201 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
202 pub inner: *mut nativeChannelHandshakeLimits,
203 /// Indicates that this is the only struct which contains the same pointer.
205 /// Rust functions which take ownership of an object provided via an argument require
206 /// this to be true and invalidate the object pointed to by inner.
210 impl Drop for ChannelHandshakeLimits {
212 if self.is_owned && !<*mut nativeChannelHandshakeLimits>::is_null(self.inner) {
213 let _ = unsafe { Box::from_raw(self.inner) };
217 /// Frees any resources used by the ChannelHandshakeLimits, if is_owned is set and inner is non-NULL.
219 pub extern "C" fn ChannelHandshakeLimits_free(this_obj: ChannelHandshakeLimits) { }
221 /// Used only if an object of this type is returned as a trait impl by a method
222 extern "C" fn ChannelHandshakeLimits_free_void(this_ptr: *mut c_void) {
223 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelHandshakeLimits); }
226 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
227 impl ChannelHandshakeLimits {
228 pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeLimits {
229 assert!(self.is_owned);
230 let ret = self.inner;
231 self.inner = std::ptr::null_mut();
235 /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
236 /// only applies to inbound channels.
238 /// Default value: 0.
240 pub extern "C" fn ChannelHandshakeLimits_get_min_funding_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
241 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_funding_satoshis;
244 /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
245 /// only applies to inbound channels.
247 /// Default value: 0.
249 pub extern "C" fn ChannelHandshakeLimits_set_min_funding_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
250 unsafe { &mut *this_ptr.inner }.min_funding_satoshis = val;
252 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
253 /// you to limit the maximum minimum-size they can require.
255 /// Default value: u64::max_value.
257 pub extern "C" fn ChannelHandshakeLimits_get_max_htlc_minimum_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
258 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_htlc_minimum_msat;
261 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
262 /// you to limit the maximum minimum-size they can require.
264 /// Default value: u64::max_value.
266 pub extern "C" fn ChannelHandshakeLimits_set_max_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
267 unsafe { &mut *this_ptr.inner }.max_htlc_minimum_msat = val;
269 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
270 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
272 /// Default value: 0.
274 pub extern "C" fn ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
275 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_max_htlc_value_in_flight_msat;
278 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
279 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
281 /// Default value: 0.
283 pub extern "C" fn ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
284 unsafe { &mut *this_ptr.inner }.min_max_htlc_value_in_flight_msat = val;
286 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
287 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
288 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
290 /// Default value: u64::max_value.
292 pub extern "C" fn ChannelHandshakeLimits_get_max_channel_reserve_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
293 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_channel_reserve_satoshis;
296 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
297 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
298 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
300 /// Default value: u64::max_value.
302 pub extern "C" fn ChannelHandshakeLimits_set_max_channel_reserve_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
303 unsafe { &mut *this_ptr.inner }.max_channel_reserve_satoshis = val;
305 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
306 /// time. This allows you to set a minimum such value.
308 /// Default value: 0.
310 pub extern "C" fn ChannelHandshakeLimits_get_min_max_accepted_htlcs(this_ptr: &ChannelHandshakeLimits) -> u16 {
311 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_max_accepted_htlcs;
314 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
315 /// time. This allows you to set a minimum such value.
317 /// Default value: 0.
319 pub extern "C" fn ChannelHandshakeLimits_set_min_max_accepted_htlcs(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
320 unsafe { &mut *this_ptr.inner }.min_max_accepted_htlcs = val;
322 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
323 /// certain number of blocks, specified by the node which is not the funder (as the funder can
324 /// assume they aren't going to double-spend themselves).
325 /// This config allows you to set a limit on the maximum amount of time to wait.
327 /// Default value: 144, or roughly one day and only applies to outbound channels.
329 pub extern "C" fn ChannelHandshakeLimits_get_max_minimum_depth(this_ptr: &ChannelHandshakeLimits) -> u32 {
330 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_minimum_depth;
333 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
334 /// certain number of blocks, specified by the node which is not the funder (as the funder can
335 /// assume they aren't going to double-spend themselves).
336 /// This config allows you to set a limit on the maximum amount of time to wait.
338 /// Default value: 144, or roughly one day and only applies to outbound channels.
340 pub extern "C" fn ChannelHandshakeLimits_set_max_minimum_depth(this_ptr: &mut ChannelHandshakeLimits, mut val: u32) {
341 unsafe { &mut *this_ptr.inner }.max_minimum_depth = val;
343 /// Set to force the incoming channel to match our announced channel preference in
346 /// Default value: true, to make the default that no announced channels are possible (which is
347 /// appropriate for any nodes which are not online very reliably).
349 pub extern "C" fn ChannelHandshakeLimits_get_force_announced_channel_preference(this_ptr: &ChannelHandshakeLimits) -> bool {
350 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.force_announced_channel_preference;
353 /// Set to force the incoming channel to match our announced channel preference in
356 /// Default value: true, to make the default that no announced channels are possible (which is
357 /// appropriate for any nodes which are not online very reliably).
359 pub extern "C" fn ChannelHandshakeLimits_set_force_announced_channel_preference(this_ptr: &mut ChannelHandshakeLimits, mut val: bool) {
360 unsafe { &mut *this_ptr.inner }.force_announced_channel_preference = val;
362 /// Set to the amount of time we're willing to wait to claim money back to us.
364 /// Not checking this value would be a security issue, as our peer would be able to set it to
365 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
367 /// Default value: 2016, which we also enforce as a maximum value so you can tweak config to
368 /// reduce the loss of having useless locked funds (if your peer accepts)
370 pub extern "C" fn ChannelHandshakeLimits_get_their_to_self_delay(this_ptr: &ChannelHandshakeLimits) -> u16 {
371 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.their_to_self_delay;
374 /// Set to the amount of time we're willing to wait to claim money back to us.
376 /// Not checking this value would be a security issue, as our peer would be able to set it to
377 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
379 /// Default value: 2016, which we also enforce as a maximum value so you can tweak config to
380 /// reduce the loss of having useless locked funds (if your peer accepts)
382 pub extern "C" fn ChannelHandshakeLimits_set_their_to_self_delay(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
383 unsafe { &mut *this_ptr.inner }.their_to_self_delay = val;
385 /// Constructs a new ChannelHandshakeLimits given each field
388 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 {
389 ChannelHandshakeLimits { inner: Box::into_raw(Box::new(nativeChannelHandshakeLimits {
390 min_funding_satoshis: min_funding_satoshis_arg,
391 max_htlc_minimum_msat: max_htlc_minimum_msat_arg,
392 min_max_htlc_value_in_flight_msat: min_max_htlc_value_in_flight_msat_arg,
393 max_channel_reserve_satoshis: max_channel_reserve_satoshis_arg,
394 min_max_accepted_htlcs: min_max_accepted_htlcs_arg,
395 max_minimum_depth: max_minimum_depth_arg,
396 force_announced_channel_preference: force_announced_channel_preference_arg,
397 their_to_self_delay: their_to_self_delay_arg,
398 })), is_owned: true }
400 impl Clone for ChannelHandshakeLimits {
401 fn clone(&self) -> Self {
403 inner: if <*mut nativeChannelHandshakeLimits>::is_null(self.inner) { std::ptr::null_mut() } else {
404 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
410 /// Used only if an object of this type is returned as a trait impl by a method
411 pub(crate) extern "C" fn ChannelHandshakeLimits_clone_void(this_ptr: *const c_void) -> *mut c_void {
412 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeLimits)).clone() })) as *mut c_void
415 /// Creates a copy of the ChannelHandshakeLimits
416 pub extern "C" fn ChannelHandshakeLimits_clone(orig: &ChannelHandshakeLimits) -> ChannelHandshakeLimits {
419 /// Creates a "default" ChannelHandshakeLimits. See struct and individual field documentaiton for details on which values are used.
422 pub extern "C" fn ChannelHandshakeLimits_default() -> ChannelHandshakeLimits {
423 ChannelHandshakeLimits { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
426 use lightning::util::config::ChannelConfig as nativeChannelConfigImport;
427 type nativeChannelConfig = nativeChannelConfigImport;
429 /// Options which apply on a per-channel basis and may change at runtime or based on negotiation
430 /// with our counterparty.
433 pub struct ChannelConfig {
434 /// A pointer to the opaque Rust object.
436 /// Nearly everywhere, inner must be non-null, however in places where
437 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
438 pub inner: *mut nativeChannelConfig,
439 /// Indicates that this is the only struct which contains the same pointer.
441 /// Rust functions which take ownership of an object provided via an argument require
442 /// this to be true and invalidate the object pointed to by inner.
446 impl Drop for ChannelConfig {
448 if self.is_owned && !<*mut nativeChannelConfig>::is_null(self.inner) {
449 let _ = unsafe { Box::from_raw(self.inner) };
453 /// Frees any resources used by the ChannelConfig, if is_owned is set and inner is non-NULL.
455 pub extern "C" fn ChannelConfig_free(this_obj: ChannelConfig) { }
457 /// Used only if an object of this type is returned as a trait impl by a method
458 extern "C" fn ChannelConfig_free_void(this_ptr: *mut c_void) {
459 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelConfig); }
462 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
464 pub(crate) fn take_inner(mut self) -> *mut nativeChannelConfig {
465 assert!(self.is_owned);
466 let ret = self.inner;
467 self.inner = std::ptr::null_mut();
471 /// Amount (in millionths of a satoshi) the channel will charge per transferred satoshi.
472 /// This may be allowed to change at runtime in a later update, however doing so must result in
473 /// update messages sent to notify all nodes of our updated relay fee.
475 /// Default value: 0.
477 pub extern "C" fn ChannelConfig_get_fee_proportional_millionths(this_ptr: &ChannelConfig) -> u32 {
478 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fee_proportional_millionths;
481 /// Amount (in millionths of a satoshi) the channel will charge per transferred satoshi.
482 /// This may be allowed to change at runtime in a later update, however doing so must result in
483 /// update messages sent to notify all nodes of our updated relay fee.
485 /// Default value: 0.
487 pub extern "C" fn ChannelConfig_set_fee_proportional_millionths(this_ptr: &mut ChannelConfig, mut val: u32) {
488 unsafe { &mut *this_ptr.inner }.fee_proportional_millionths = val;
490 /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
491 /// the channel this config applies to.
493 /// This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
494 /// HTLC balance when a channel appears on-chain whereas
495 /// [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
496 /// (non-HTLC-encumbered) balance.
498 /// Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
499 /// we (or one of our watchtowers) MUST be online to check for broadcast of the current
500 /// commitment transaction at least once per this many blocks (minus some margin to allow us
501 /// enough time to broadcast and confirm a transaction, possibly with time in between to RBF
502 /// the spending transaction).
504 /// Default value: 72 (12 hours at an average of 6 blocks/hour).
505 /// Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
506 /// [`MIN_CLTV_EXPIRY_DELTA`] instead.
508 /// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
510 pub extern "C" fn ChannelConfig_get_cltv_expiry_delta(this_ptr: &ChannelConfig) -> u16 {
511 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry_delta;
514 /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
515 /// the channel this config applies to.
517 /// This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
518 /// HTLC balance when a channel appears on-chain whereas
519 /// [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
520 /// (non-HTLC-encumbered) balance.
522 /// Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
523 /// we (or one of our watchtowers) MUST be online to check for broadcast of the current
524 /// commitment transaction at least once per this many blocks (minus some margin to allow us
525 /// enough time to broadcast and confirm a transaction, possibly with time in between to RBF
526 /// the spending transaction).
528 /// Default value: 72 (12 hours at an average of 6 blocks/hour).
529 /// Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
530 /// [`MIN_CLTV_EXPIRY_DELTA`] instead.
532 /// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
534 pub extern "C" fn ChannelConfig_set_cltv_expiry_delta(this_ptr: &mut ChannelConfig, mut val: u16) {
535 unsafe { &mut *this_ptr.inner }.cltv_expiry_delta = val;
537 /// Set to announce the channel publicly and notify all nodes that they can route via this
540 /// This should only be set to true for nodes which expect to be online reliably.
542 /// As the node which funds a channel picks this value this will only apply for new outbound
543 /// channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set.
545 /// This cannot be changed after the initial channel handshake.
547 /// Default value: false.
549 pub extern "C" fn ChannelConfig_get_announced_channel(this_ptr: &ChannelConfig) -> bool {
550 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announced_channel;
553 /// Set to announce the channel publicly and notify all nodes that they can route via this
556 /// This should only be set to true for nodes which expect to be online reliably.
558 /// As the node which funds a channel picks this value this will only apply for new outbound
559 /// channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set.
561 /// This cannot be changed after the initial channel handshake.
563 /// Default value: false.
565 pub extern "C" fn ChannelConfig_set_announced_channel(this_ptr: &mut ChannelConfig, mut val: bool) {
566 unsafe { &mut *this_ptr.inner }.announced_channel = val;
568 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
569 /// supports it, they will then enforce the mutual-close output to us matches what we provided
570 /// at intialization, preventing us from closing to an alternate pubkey.
572 /// This is set to true by default to provide a slight increase in security, though ultimately
573 /// any attacker who is able to take control of a channel can just as easily send the funds via
574 /// lightning payments, so we never require that our counterparties support this option.
576 /// This cannot be changed after a channel has been initialized.
578 /// Default value: true.
580 pub extern "C" fn ChannelConfig_get_commit_upfront_shutdown_pubkey(this_ptr: &ChannelConfig) -> bool {
581 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.commit_upfront_shutdown_pubkey;
584 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
585 /// supports it, they will then enforce the mutual-close output to us matches what we provided
586 /// at intialization, preventing us from closing to an alternate pubkey.
588 /// This is set to true by default to provide a slight increase in security, though ultimately
589 /// any attacker who is able to take control of a channel can just as easily send the funds via
590 /// lightning payments, so we never require that our counterparties support this option.
592 /// This cannot be changed after a channel has been initialized.
594 /// Default value: true.
596 pub extern "C" fn ChannelConfig_set_commit_upfront_shutdown_pubkey(this_ptr: &mut ChannelConfig, mut val: bool) {
597 unsafe { &mut *this_ptr.inner }.commit_upfront_shutdown_pubkey = val;
599 /// Constructs a new ChannelConfig given each field
602 pub extern "C" fn ChannelConfig_new(mut fee_proportional_millionths_arg: u32, mut cltv_expiry_delta_arg: u16, mut announced_channel_arg: bool, mut commit_upfront_shutdown_pubkey_arg: bool) -> ChannelConfig {
603 ChannelConfig { inner: Box::into_raw(Box::new(nativeChannelConfig {
604 fee_proportional_millionths: fee_proportional_millionths_arg,
605 cltv_expiry_delta: cltv_expiry_delta_arg,
606 announced_channel: announced_channel_arg,
607 commit_upfront_shutdown_pubkey: commit_upfront_shutdown_pubkey_arg,
608 })), is_owned: true }
610 impl Clone for ChannelConfig {
611 fn clone(&self) -> Self {
613 inner: if <*mut nativeChannelConfig>::is_null(self.inner) { std::ptr::null_mut() } else {
614 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
620 /// Used only if an object of this type is returned as a trait impl by a method
621 pub(crate) extern "C" fn ChannelConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
622 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelConfig)).clone() })) as *mut c_void
625 /// Creates a copy of the ChannelConfig
626 pub extern "C" fn ChannelConfig_clone(orig: &ChannelConfig) -> ChannelConfig {
629 /// Creates a "default" ChannelConfig. See struct and individual field documentaiton for details on which values are used.
632 pub extern "C" fn ChannelConfig_default() -> ChannelConfig {
633 ChannelConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
636 /// Serialize the ChannelConfig object into a byte array which can be read by ChannelConfig_read
637 pub extern "C" fn ChannelConfig_write(obj: &ChannelConfig) -> crate::c_types::derived::CVec_u8Z {
638 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
641 pub(crate) extern "C" fn ChannelConfig_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
642 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelConfig) })
645 /// Read a ChannelConfig from a byte array, created by ChannelConfig_write
646 pub extern "C" fn ChannelConfig_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelConfigDecodeErrorZ {
647 let res = crate::c_types::deserialize_obj(ser);
648 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::util::config::ChannelConfig { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
652 use lightning::util::config::UserConfig as nativeUserConfigImport;
653 type nativeUserConfig = nativeUserConfigImport;
655 /// Top-level config which holds ChannelHandshakeLimits and ChannelConfig.
657 /// Default::default() provides sane defaults for most configurations
658 /// (but currently with 0 relay fees!)
661 pub struct UserConfig {
662 /// A pointer to the opaque Rust object.
664 /// Nearly everywhere, inner must be non-null, however in places where
665 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
666 pub inner: *mut nativeUserConfig,
667 /// Indicates that this is the only struct which contains the same pointer.
669 /// Rust functions which take ownership of an object provided via an argument require
670 /// this to be true and invalidate the object pointed to by inner.
674 impl Drop for UserConfig {
676 if self.is_owned && !<*mut nativeUserConfig>::is_null(self.inner) {
677 let _ = unsafe { Box::from_raw(self.inner) };
681 /// Frees any resources used by the UserConfig, if is_owned is set and inner is non-NULL.
683 pub extern "C" fn UserConfig_free(this_obj: UserConfig) { }
685 /// Used only if an object of this type is returned as a trait impl by a method
686 extern "C" fn UserConfig_free_void(this_ptr: *mut c_void) {
687 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUserConfig); }
690 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
692 pub(crate) fn take_inner(mut self) -> *mut nativeUserConfig {
693 assert!(self.is_owned);
694 let ret = self.inner;
695 self.inner = std::ptr::null_mut();
699 /// Channel config that we propose to our counterparty.
701 pub extern "C" fn UserConfig_get_own_channel_config(this_ptr: &UserConfig) -> crate::lightning::util::config::ChannelHandshakeConfig {
702 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.own_channel_config;
703 crate::lightning::util::config::ChannelHandshakeConfig { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
705 /// Channel config that we propose to our counterparty.
707 pub extern "C" fn UserConfig_set_own_channel_config(this_ptr: &mut UserConfig, mut val: crate::lightning::util::config::ChannelHandshakeConfig) {
708 unsafe { &mut *this_ptr.inner }.own_channel_config = *unsafe { Box::from_raw(val.take_inner()) };
710 /// Limits applied to our counterparty's proposed channel config settings.
712 pub extern "C" fn UserConfig_get_peer_channel_config_limits(this_ptr: &UserConfig) -> crate::lightning::util::config::ChannelHandshakeLimits {
713 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.peer_channel_config_limits;
714 crate::lightning::util::config::ChannelHandshakeLimits { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
716 /// Limits applied to our counterparty's proposed channel config settings.
718 pub extern "C" fn UserConfig_set_peer_channel_config_limits(this_ptr: &mut UserConfig, mut val: crate::lightning::util::config::ChannelHandshakeLimits) {
719 unsafe { &mut *this_ptr.inner }.peer_channel_config_limits = *unsafe { Box::from_raw(val.take_inner()) };
721 /// Channel config which affects behavior during channel lifetime.
723 pub extern "C" fn UserConfig_get_channel_options(this_ptr: &UserConfig) -> crate::lightning::util::config::ChannelConfig {
724 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_options;
725 crate::lightning::util::config::ChannelConfig { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
727 /// Channel config which affects behavior during channel lifetime.
729 pub extern "C" fn UserConfig_set_channel_options(this_ptr: &mut UserConfig, mut val: crate::lightning::util::config::ChannelConfig) {
730 unsafe { &mut *this_ptr.inner }.channel_options = *unsafe { Box::from_raw(val.take_inner()) };
732 /// Constructs a new UserConfig given each field
735 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) -> UserConfig {
736 UserConfig { inner: Box::into_raw(Box::new(nativeUserConfig {
737 own_channel_config: *unsafe { Box::from_raw(own_channel_config_arg.take_inner()) },
738 peer_channel_config_limits: *unsafe { Box::from_raw(peer_channel_config_limits_arg.take_inner()) },
739 channel_options: *unsafe { Box::from_raw(channel_options_arg.take_inner()) },
740 })), is_owned: true }
742 impl Clone for UserConfig {
743 fn clone(&self) -> Self {
745 inner: if <*mut nativeUserConfig>::is_null(self.inner) { std::ptr::null_mut() } else {
746 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
752 /// Used only if an object of this type is returned as a trait impl by a method
753 pub(crate) extern "C" fn UserConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
754 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUserConfig)).clone() })) as *mut c_void
757 /// Creates a copy of the UserConfig
758 pub extern "C" fn UserConfig_clone(orig: &UserConfig) -> UserConfig {
761 /// Creates a "default" UserConfig. See struct and individual field documentaiton for details on which values are used.
764 pub extern "C" fn UserConfig_default() -> UserConfig {
765 UserConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }