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
13 use bitcoin::hashes::Hash;
14 use crate::c_types::*;
17 use lightning::util::config::ChannelHandshakeConfig as nativeChannelHandshakeConfigImport;
18 type nativeChannelHandshakeConfig = nativeChannelHandshakeConfigImport;
20 /// Configuration we set when applicable.
22 /// Default::default() provides sane defaults.
25 pub struct ChannelHandshakeConfig {
26 /// A pointer to the opaque Rust object.
28 /// Nearly everywhere, inner must be non-null, however in places where
29 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
30 pub inner: *mut nativeChannelHandshakeConfig,
31 /// Indicates that this is the only struct which contains the same pointer.
33 /// Rust functions which take ownership of an object provided via an argument require
34 /// this to be true and invalidate the object pointed to by inner.
38 impl Drop for ChannelHandshakeConfig {
40 if self.is_owned && !<*mut nativeChannelHandshakeConfig>::is_null(self.inner) {
41 let _ = unsafe { Box::from_raw(self.inner) };
45 /// Frees any resources used by the ChannelHandshakeConfig, if is_owned is set and inner is non-NULL.
47 pub extern "C" fn ChannelHandshakeConfig_free(this_obj: ChannelHandshakeConfig) { }
49 /// Used only if an object of this type is returned as a trait impl by a method
50 extern "C" fn ChannelHandshakeConfig_free_void(this_ptr: *mut c_void) {
51 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelHandshakeConfig); }
54 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
55 impl ChannelHandshakeConfig {
56 pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeConfig {
57 assert!(self.is_owned);
59 self.inner = std::ptr::null_mut();
63 /// Confirmations we will wait for before considering the channel locked in.
64 /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
65 /// equivalent limit applied to outbound channels).
69 pub extern "C" fn ChannelHandshakeConfig_get_minimum_depth(this_ptr: &ChannelHandshakeConfig) -> u32 {
70 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.minimum_depth;
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_set_minimum_depth(this_ptr: &mut ChannelHandshakeConfig, mut val: u32) {
80 unsafe { &mut *this_ptr.inner }.minimum_depth = val;
82 /// Set to the number of blocks we require our counterparty to wait to claim their money (ie
83 /// the number of blocks we have to punish our counterparty if they broadcast a revoked
86 /// This is one of the main parameters of our security model. We (or one of our watchtowers) MUST
87 /// be online to check for revoked transactions on-chain at least once every our_to_self_delay
88 /// blocks (minus some margin to allow us enough time to broadcast and confirm a transaction,
89 /// possibly with time in between to RBF the spending transaction).
91 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
92 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
95 /// Default value: [`BREAKDOWN_TIMEOUT`], we enforce it as a minimum at channel opening so you
96 /// can tweak config to ask for more security, not less.
98 pub extern "C" fn ChannelHandshakeConfig_get_our_to_self_delay(this_ptr: &ChannelHandshakeConfig) -> u16 {
99 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.our_to_self_delay;
102 /// Set to the number of blocks we require our counterparty to wait to claim their money (ie
103 /// the number of blocks we have to punish our counterparty if they broadcast a revoked
106 /// This is one of the main parameters of our security model. We (or one of our watchtowers) MUST
107 /// be online to check for revoked transactions on-chain at least once every our_to_self_delay
108 /// blocks (minus some margin to allow us enough time to broadcast and confirm a transaction,
109 /// possibly with time in between to RBF the spending transaction).
111 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
112 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
115 /// Default value: [`BREAKDOWN_TIMEOUT`], we enforce it as a minimum at channel opening so you
116 /// can tweak config to ask for more security, not less.
118 pub extern "C" fn ChannelHandshakeConfig_set_our_to_self_delay(this_ptr: &mut ChannelHandshakeConfig, mut val: u16) {
119 unsafe { &mut *this_ptr.inner }.our_to_self_delay = val;
121 /// Set to the smallest value HTLC we will accept to process.
123 /// This value is sent to our counterparty on channel-open and we close the channel any time
124 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
126 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
129 pub extern "C" fn ChannelHandshakeConfig_get_our_htlc_minimum_msat(this_ptr: &ChannelHandshakeConfig) -> u64 {
130 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.our_htlc_minimum_msat;
133 /// Set to the smallest value HTLC we will accept to process.
135 /// This value is sent to our counterparty on channel-open and we close the channel any time
136 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
138 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
141 pub extern "C" fn ChannelHandshakeConfig_set_our_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeConfig, mut val: u64) {
142 unsafe { &mut *this_ptr.inner }.our_htlc_minimum_msat = val;
144 /// Constructs a new ChannelHandshakeConfig given each field
147 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 {
148 ChannelHandshakeConfig { inner: Box::into_raw(Box::new(nativeChannelHandshakeConfig {
149 minimum_depth: minimum_depth_arg,
150 our_to_self_delay: our_to_self_delay_arg,
151 our_htlc_minimum_msat: our_htlc_minimum_msat_arg,
152 })), is_owned: true }
154 impl Clone for ChannelHandshakeConfig {
155 fn clone(&self) -> Self {
157 inner: if <*mut nativeChannelHandshakeConfig>::is_null(self.inner) { std::ptr::null_mut() } else {
158 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
164 /// Used only if an object of this type is returned as a trait impl by a method
165 pub(crate) extern "C" fn ChannelHandshakeConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
166 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeConfig)).clone() })) as *mut c_void
169 /// Creates a copy of the ChannelHandshakeConfig
170 pub extern "C" fn ChannelHandshakeConfig_clone(orig: &ChannelHandshakeConfig) -> ChannelHandshakeConfig {
173 /// Creates a "default" ChannelHandshakeConfig. See struct and individual field documentaiton for details on which values are used.
176 pub extern "C" fn ChannelHandshakeConfig_default() -> ChannelHandshakeConfig {
177 ChannelHandshakeConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
180 use lightning::util::config::ChannelHandshakeLimits as nativeChannelHandshakeLimitsImport;
181 type nativeChannelHandshakeLimits = nativeChannelHandshakeLimitsImport;
183 /// Optional channel limits which are applied during channel creation.
185 /// These limits are only applied to our counterparty's limits, not our own.
187 /// Use 0/<type>::max_value() as appropriate to skip checking.
189 /// Provides sane defaults for most configurations.
191 /// Most additional limits are disabled except those with which specify a default in individual
192 /// field documentation. Note that this may result in barely-usable channels, but since they
193 /// are applied mostly only to incoming channels that's not much of a problem.
196 pub struct ChannelHandshakeLimits {
197 /// A pointer to the opaque Rust object.
199 /// Nearly everywhere, inner must be non-null, however in places where
200 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
201 pub inner: *mut nativeChannelHandshakeLimits,
202 /// Indicates that this is the only struct which contains the same pointer.
204 /// Rust functions which take ownership of an object provided via an argument require
205 /// this to be true and invalidate the object pointed to by inner.
209 impl Drop for ChannelHandshakeLimits {
211 if self.is_owned && !<*mut nativeChannelHandshakeLimits>::is_null(self.inner) {
212 let _ = unsafe { Box::from_raw(self.inner) };
216 /// Frees any resources used by the ChannelHandshakeLimits, if is_owned is set and inner is non-NULL.
218 pub extern "C" fn ChannelHandshakeLimits_free(this_obj: ChannelHandshakeLimits) { }
220 /// Used only if an object of this type is returned as a trait impl by a method
221 extern "C" fn ChannelHandshakeLimits_free_void(this_ptr: *mut c_void) {
222 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelHandshakeLimits); }
225 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
226 impl ChannelHandshakeLimits {
227 pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeLimits {
228 assert!(self.is_owned);
229 let ret = self.inner;
230 self.inner = std::ptr::null_mut();
234 /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
235 /// only applies to inbound channels.
237 /// Default value: 0.
239 pub extern "C" fn ChannelHandshakeLimits_get_min_funding_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
240 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_funding_satoshis;
243 /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
244 /// only applies to inbound channels.
246 /// Default value: 0.
248 pub extern "C" fn ChannelHandshakeLimits_set_min_funding_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
249 unsafe { &mut *this_ptr.inner }.min_funding_satoshis = val;
251 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
252 /// you to limit the maximum minimum-size they can require.
254 /// Default value: u64::max_value.
256 pub extern "C" fn ChannelHandshakeLimits_get_max_htlc_minimum_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
257 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_htlc_minimum_msat;
260 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
261 /// you to limit the maximum minimum-size they can require.
263 /// Default value: u64::max_value.
265 pub extern "C" fn ChannelHandshakeLimits_set_max_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
266 unsafe { &mut *this_ptr.inner }.max_htlc_minimum_msat = val;
268 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
269 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
271 /// Default value: 0.
273 pub extern "C" fn ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
274 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_max_htlc_value_in_flight_msat;
277 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
278 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
280 /// Default value: 0.
282 pub extern "C" fn ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
283 unsafe { &mut *this_ptr.inner }.min_max_htlc_value_in_flight_msat = val;
285 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
286 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
287 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
289 /// Default value: u64::max_value.
291 pub extern "C" fn ChannelHandshakeLimits_get_max_channel_reserve_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
292 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_channel_reserve_satoshis;
295 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
296 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
297 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
299 /// Default value: u64::max_value.
301 pub extern "C" fn ChannelHandshakeLimits_set_max_channel_reserve_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
302 unsafe { &mut *this_ptr.inner }.max_channel_reserve_satoshis = val;
304 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
305 /// time. This allows you to set a minimum such value.
307 /// Default value: 0.
309 pub extern "C" fn ChannelHandshakeLimits_get_min_max_accepted_htlcs(this_ptr: &ChannelHandshakeLimits) -> u16 {
310 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_max_accepted_htlcs;
313 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
314 /// time. This allows you to set a minimum such value.
316 /// Default value: 0.
318 pub extern "C" fn ChannelHandshakeLimits_set_min_max_accepted_htlcs(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
319 unsafe { &mut *this_ptr.inner }.min_max_accepted_htlcs = val;
321 /// Outputs below a certain value will not be added to on-chain transactions. The dust value is
322 /// required to always be higher than this value so this only applies to HTLC outputs (and
323 /// potentially to-self outputs before any payments have been made).
324 /// Thus, HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
325 /// This setting allows you to set a minimum dust limit for their commitment transactions,
326 /// reflecting the reality that tiny outputs are not considered standard transactions and will
327 /// not propagate through the Bitcoin network.
329 /// Default value: 546, the current dust limit on the Bitcoin network.
331 pub extern "C" fn ChannelHandshakeLimits_get_min_dust_limit_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
332 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_dust_limit_satoshis;
335 /// Outputs below a certain value will not be added to on-chain transactions. The dust value is
336 /// required to always be higher than this value so this only applies to HTLC outputs (and
337 /// potentially to-self outputs before any payments have been made).
338 /// Thus, HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
339 /// This setting allows you to set a minimum dust limit for their commitment transactions,
340 /// reflecting the reality that tiny outputs are not considered standard transactions and will
341 /// not propagate through the Bitcoin network.
343 /// Default value: 546, the current dust limit on the Bitcoin network.
345 pub extern "C" fn ChannelHandshakeLimits_set_min_dust_limit_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
346 unsafe { &mut *this_ptr.inner }.min_dust_limit_satoshis = val;
348 /// Maximum allowed threshold above which outputs will not be generated in their commitment
350 /// HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
352 /// Default value: u64::max_value.
354 pub extern "C" fn ChannelHandshakeLimits_get_max_dust_limit_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
355 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_dust_limit_satoshis;
358 /// Maximum allowed threshold above which outputs will not be generated in their commitment
360 /// HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
362 /// Default value: u64::max_value.
364 pub extern "C" fn ChannelHandshakeLimits_set_max_dust_limit_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
365 unsafe { &mut *this_ptr.inner }.max_dust_limit_satoshis = val;
367 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
368 /// certain number of blocks, specified by the node which is not the funder (as the funder can
369 /// assume they aren't going to double-spend themselves).
370 /// This config allows you to set a limit on the maximum amount of time to wait.
372 /// Default value: 144, or roughly one day and only applies to outbound channels.
374 pub extern "C" fn ChannelHandshakeLimits_get_max_minimum_depth(this_ptr: &ChannelHandshakeLimits) -> u32 {
375 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_minimum_depth;
378 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
379 /// certain number of blocks, specified by the node which is not the funder (as the funder can
380 /// assume they aren't going to double-spend themselves).
381 /// This config allows you to set a limit on the maximum amount of time to wait.
383 /// Default value: 144, or roughly one day and only applies to outbound channels.
385 pub extern "C" fn ChannelHandshakeLimits_set_max_minimum_depth(this_ptr: &mut ChannelHandshakeLimits, mut val: u32) {
386 unsafe { &mut *this_ptr.inner }.max_minimum_depth = val;
388 /// Set to force the incoming channel to match our announced channel preference in
391 /// Default value: true, to make the default that no announced channels are possible (which is
392 /// appropriate for any nodes which are not online very reliably).
394 pub extern "C" fn ChannelHandshakeLimits_get_force_announced_channel_preference(this_ptr: &ChannelHandshakeLimits) -> bool {
395 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.force_announced_channel_preference;
398 /// Set to force the incoming channel to match our announced channel preference in
401 /// Default value: true, to make the default that no announced channels are possible (which is
402 /// appropriate for any nodes which are not online very reliably).
404 pub extern "C" fn ChannelHandshakeLimits_set_force_announced_channel_preference(this_ptr: &mut ChannelHandshakeLimits, mut val: bool) {
405 unsafe { &mut *this_ptr.inner }.force_announced_channel_preference = val;
407 /// Set to the amount of time we're willing to wait to claim money back to us.
409 /// Not checking this value would be a security issue, as our peer would be able to set it to
410 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
412 /// Default value: 2016, which we also enforce as a maximum value so you can tweak config to
413 /// reduce the loss of having useless locked funds (if your peer accepts)
415 pub extern "C" fn ChannelHandshakeLimits_get_their_to_self_delay(this_ptr: &ChannelHandshakeLimits) -> u16 {
416 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.their_to_self_delay;
419 /// Set to the amount of time we're willing to wait to claim money back to us.
421 /// Not checking this value would be a security issue, as our peer would be able to set it to
422 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
424 /// Default value: 2016, which we also enforce as a maximum value so you can tweak config to
425 /// reduce the loss of having useless locked funds (if your peer accepts)
427 pub extern "C" fn ChannelHandshakeLimits_set_their_to_self_delay(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
428 unsafe { &mut *this_ptr.inner }.their_to_self_delay = val;
430 /// Constructs a new ChannelHandshakeLimits given each field
433 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 min_dust_limit_satoshis_arg: u64, mut max_dust_limit_satoshis_arg: u64, mut max_minimum_depth_arg: u32, mut force_announced_channel_preference_arg: bool, mut their_to_self_delay_arg: u16) -> ChannelHandshakeLimits {
434 ChannelHandshakeLimits { inner: Box::into_raw(Box::new(nativeChannelHandshakeLimits {
435 min_funding_satoshis: min_funding_satoshis_arg,
436 max_htlc_minimum_msat: max_htlc_minimum_msat_arg,
437 min_max_htlc_value_in_flight_msat: min_max_htlc_value_in_flight_msat_arg,
438 max_channel_reserve_satoshis: max_channel_reserve_satoshis_arg,
439 min_max_accepted_htlcs: min_max_accepted_htlcs_arg,
440 min_dust_limit_satoshis: min_dust_limit_satoshis_arg,
441 max_dust_limit_satoshis: max_dust_limit_satoshis_arg,
442 max_minimum_depth: max_minimum_depth_arg,
443 force_announced_channel_preference: force_announced_channel_preference_arg,
444 their_to_self_delay: their_to_self_delay_arg,
445 })), is_owned: true }
447 impl Clone for ChannelHandshakeLimits {
448 fn clone(&self) -> Self {
450 inner: if <*mut nativeChannelHandshakeLimits>::is_null(self.inner) { std::ptr::null_mut() } else {
451 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
457 /// Used only if an object of this type is returned as a trait impl by a method
458 pub(crate) extern "C" fn ChannelHandshakeLimits_clone_void(this_ptr: *const c_void) -> *mut c_void {
459 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeLimits)).clone() })) as *mut c_void
462 /// Creates a copy of the ChannelHandshakeLimits
463 pub extern "C" fn ChannelHandshakeLimits_clone(orig: &ChannelHandshakeLimits) -> ChannelHandshakeLimits {
466 /// Creates a "default" ChannelHandshakeLimits. See struct and individual field documentaiton for details on which values are used.
469 pub extern "C" fn ChannelHandshakeLimits_default() -> ChannelHandshakeLimits {
470 ChannelHandshakeLimits { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
473 use lightning::util::config::ChannelConfig as nativeChannelConfigImport;
474 type nativeChannelConfig = nativeChannelConfigImport;
476 /// Options which apply on a per-channel basis and may change at runtime or based on negotiation
477 /// with our counterparty.
480 pub struct ChannelConfig {
481 /// A pointer to the opaque Rust object.
483 /// Nearly everywhere, inner must be non-null, however in places where
484 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
485 pub inner: *mut nativeChannelConfig,
486 /// Indicates that this is the only struct which contains the same pointer.
488 /// Rust functions which take ownership of an object provided via an argument require
489 /// this to be true and invalidate the object pointed to by inner.
493 impl Drop for ChannelConfig {
495 if self.is_owned && !<*mut nativeChannelConfig>::is_null(self.inner) {
496 let _ = unsafe { Box::from_raw(self.inner) };
500 /// Frees any resources used by the ChannelConfig, if is_owned is set and inner is non-NULL.
502 pub extern "C" fn ChannelConfig_free(this_obj: ChannelConfig) { }
504 /// Used only if an object of this type is returned as a trait impl by a method
505 extern "C" fn ChannelConfig_free_void(this_ptr: *mut c_void) {
506 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelConfig); }
509 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
511 pub(crate) fn take_inner(mut self) -> *mut nativeChannelConfig {
512 assert!(self.is_owned);
513 let ret = self.inner;
514 self.inner = std::ptr::null_mut();
518 /// Amount (in millionths of a satoshi) the channel will charge per transferred satoshi.
519 /// This may be allowed to change at runtime in a later update, however doing so must result in
520 /// update messages sent to notify all nodes of our updated relay fee.
522 /// Default value: 0.
524 pub extern "C" fn ChannelConfig_get_fee_proportional_millionths(this_ptr: &ChannelConfig) -> u32 {
525 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fee_proportional_millionths;
528 /// Amount (in millionths of a satoshi) the channel will charge per transferred satoshi.
529 /// This may be allowed to change at runtime in a later update, however doing so must result in
530 /// update messages sent to notify all nodes of our updated relay fee.
532 /// Default value: 0.
534 pub extern "C" fn ChannelConfig_set_fee_proportional_millionths(this_ptr: &mut ChannelConfig, mut val: u32) {
535 unsafe { &mut *this_ptr.inner }.fee_proportional_millionths = val;
537 /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
538 /// the channel this config applies to.
540 /// This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
541 /// HTLC balance when a channel appears on-chain whereas
542 /// [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
543 /// (non-HTLC-encumbered) balance.
545 /// Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
546 /// we (or one of our watchtowers) MUST be online to check for broadcast of the current
547 /// commitment transaction at least once per this many blocks (minus some margin to allow us
548 /// enough time to broadcast and confirm a transaction, possibly with time in between to RBF
549 /// the spending transaction).
551 /// Default value: 72 (12 hours at an average of 6 blocks/hour).
552 /// Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
553 /// [`MIN_CLTV_EXPIRY_DELTA`] instead.
555 /// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
557 pub extern "C" fn ChannelConfig_get_cltv_expiry_delta(this_ptr: &ChannelConfig) -> u16 {
558 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry_delta;
561 /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
562 /// the channel this config applies to.
564 /// This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
565 /// HTLC balance when a channel appears on-chain whereas
566 /// [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
567 /// (non-HTLC-encumbered) balance.
569 /// Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
570 /// we (or one of our watchtowers) MUST be online to check for broadcast of the current
571 /// commitment transaction at least once per this many blocks (minus some margin to allow us
572 /// enough time to broadcast and confirm a transaction, possibly with time in between to RBF
573 /// the spending transaction).
575 /// Default value: 72 (12 hours at an average of 6 blocks/hour).
576 /// Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
577 /// [`MIN_CLTV_EXPIRY_DELTA`] instead.
579 /// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
581 pub extern "C" fn ChannelConfig_set_cltv_expiry_delta(this_ptr: &mut ChannelConfig, mut val: u16) {
582 unsafe { &mut *this_ptr.inner }.cltv_expiry_delta = val;
584 /// Set to announce the channel publicly and notify all nodes that they can route via this
587 /// This should only be set to true for nodes which expect to be online reliably.
589 /// As the node which funds a channel picks this value this will only apply for new outbound
590 /// channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set.
592 /// This cannot be changed after the initial channel handshake.
594 /// Default value: false.
596 pub extern "C" fn ChannelConfig_get_announced_channel(this_ptr: &ChannelConfig) -> bool {
597 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announced_channel;
600 /// Set to announce the channel publicly and notify all nodes that they can route via this
603 /// This should only be set to true for nodes which expect to be online reliably.
605 /// As the node which funds a channel picks this value this will only apply for new outbound
606 /// channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set.
608 /// This cannot be changed after the initial channel handshake.
610 /// Default value: false.
612 pub extern "C" fn ChannelConfig_set_announced_channel(this_ptr: &mut ChannelConfig, mut val: bool) {
613 unsafe { &mut *this_ptr.inner }.announced_channel = val;
615 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
616 /// supports it, they will then enforce the mutual-close output to us matches what we provided
617 /// at intialization, preventing us from closing to an alternate pubkey.
619 /// This is set to true by default to provide a slight increase in security, though ultimately
620 /// any attacker who is able to take control of a channel can just as easily send the funds via
621 /// lightning payments, so we never require that our counterparties support this option.
623 /// This cannot be changed after a channel has been initialized.
625 /// Default value: true.
627 pub extern "C" fn ChannelConfig_get_commit_upfront_shutdown_pubkey(this_ptr: &ChannelConfig) -> bool {
628 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.commit_upfront_shutdown_pubkey;
631 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
632 /// supports it, they will then enforce the mutual-close output to us matches what we provided
633 /// at intialization, preventing us from closing to an alternate pubkey.
635 /// This is set to true by default to provide a slight increase in security, though ultimately
636 /// any attacker who is able to take control of a channel can just as easily send the funds via
637 /// lightning payments, so we never require that our counterparties support this option.
639 /// This cannot be changed after a channel has been initialized.
641 /// Default value: true.
643 pub extern "C" fn ChannelConfig_set_commit_upfront_shutdown_pubkey(this_ptr: &mut ChannelConfig, mut val: bool) {
644 unsafe { &mut *this_ptr.inner }.commit_upfront_shutdown_pubkey = val;
646 /// Constructs a new ChannelConfig given each field
649 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 {
650 ChannelConfig { inner: Box::into_raw(Box::new(nativeChannelConfig {
651 fee_proportional_millionths: fee_proportional_millionths_arg,
652 cltv_expiry_delta: cltv_expiry_delta_arg,
653 announced_channel: announced_channel_arg,
654 commit_upfront_shutdown_pubkey: commit_upfront_shutdown_pubkey_arg,
655 })), is_owned: true }
657 impl Clone for ChannelConfig {
658 fn clone(&self) -> Self {
660 inner: if <*mut nativeChannelConfig>::is_null(self.inner) { std::ptr::null_mut() } else {
661 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
667 /// Used only if an object of this type is returned as a trait impl by a method
668 pub(crate) extern "C" fn ChannelConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
669 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelConfig)).clone() })) as *mut c_void
672 /// Creates a copy of the ChannelConfig
673 pub extern "C" fn ChannelConfig_clone(orig: &ChannelConfig) -> ChannelConfig {
676 /// Creates a "default" ChannelConfig. See struct and individual field documentaiton for details on which values are used.
679 pub extern "C" fn ChannelConfig_default() -> ChannelConfig {
680 ChannelConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
683 /// Serialize the ChannelConfig object into a byte array which can be read by ChannelConfig_read
684 pub extern "C" fn ChannelConfig_write(obj: &ChannelConfig) -> crate::c_types::derived::CVec_u8Z {
685 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
688 pub(crate) extern "C" fn ChannelConfig_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
689 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelConfig) })
692 /// Read a ChannelConfig from a byte array, created by ChannelConfig_write
693 pub extern "C" fn ChannelConfig_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelConfigDecodeErrorZ {
694 let res = crate::c_types::deserialize_obj(ser);
695 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::util::config::ChannelConfig { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
699 use lightning::util::config::UserConfig as nativeUserConfigImport;
700 type nativeUserConfig = nativeUserConfigImport;
702 /// Top-level config which holds ChannelHandshakeLimits and ChannelConfig.
704 /// Default::default() provides sane defaults for most configurations
705 /// (but currently with 0 relay fees!)
708 pub struct UserConfig {
709 /// A pointer to the opaque Rust object.
711 /// Nearly everywhere, inner must be non-null, however in places where
712 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
713 pub inner: *mut nativeUserConfig,
714 /// Indicates that this is the only struct which contains the same pointer.
716 /// Rust functions which take ownership of an object provided via an argument require
717 /// this to be true and invalidate the object pointed to by inner.
721 impl Drop for UserConfig {
723 if self.is_owned && !<*mut nativeUserConfig>::is_null(self.inner) {
724 let _ = unsafe { Box::from_raw(self.inner) };
728 /// Frees any resources used by the UserConfig, if is_owned is set and inner is non-NULL.
730 pub extern "C" fn UserConfig_free(this_obj: UserConfig) { }
732 /// Used only if an object of this type is returned as a trait impl by a method
733 extern "C" fn UserConfig_free_void(this_ptr: *mut c_void) {
734 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUserConfig); }
737 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
739 pub(crate) fn take_inner(mut self) -> *mut nativeUserConfig {
740 assert!(self.is_owned);
741 let ret = self.inner;
742 self.inner = std::ptr::null_mut();
746 /// Channel config that we propose to our counterparty.
748 pub extern "C" fn UserConfig_get_own_channel_config(this_ptr: &UserConfig) -> crate::util::config::ChannelHandshakeConfig {
749 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.own_channel_config;
750 crate::util::config::ChannelHandshakeConfig { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
752 /// Channel config that we propose to our counterparty.
754 pub extern "C" fn UserConfig_set_own_channel_config(this_ptr: &mut UserConfig, mut val: crate::util::config::ChannelHandshakeConfig) {
755 unsafe { &mut *this_ptr.inner }.own_channel_config = *unsafe { Box::from_raw(val.take_inner()) };
757 /// Limits applied to our counterparty's proposed channel config settings.
759 pub extern "C" fn UserConfig_get_peer_channel_config_limits(this_ptr: &UserConfig) -> crate::util::config::ChannelHandshakeLimits {
760 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.peer_channel_config_limits;
761 crate::util::config::ChannelHandshakeLimits { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
763 /// Limits applied to our counterparty's proposed channel config settings.
765 pub extern "C" fn UserConfig_set_peer_channel_config_limits(this_ptr: &mut UserConfig, mut val: crate::util::config::ChannelHandshakeLimits) {
766 unsafe { &mut *this_ptr.inner }.peer_channel_config_limits = *unsafe { Box::from_raw(val.take_inner()) };
768 /// Channel config which affects behavior during channel lifetime.
770 pub extern "C" fn UserConfig_get_channel_options(this_ptr: &UserConfig) -> crate::util::config::ChannelConfig {
771 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_options;
772 crate::util::config::ChannelConfig { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
774 /// Channel config which affects behavior during channel lifetime.
776 pub extern "C" fn UserConfig_set_channel_options(this_ptr: &mut UserConfig, mut val: crate::util::config::ChannelConfig) {
777 unsafe { &mut *this_ptr.inner }.channel_options = *unsafe { Box::from_raw(val.take_inner()) };
779 /// Constructs a new UserConfig given each field
782 pub extern "C" fn UserConfig_new(mut own_channel_config_arg: crate::util::config::ChannelHandshakeConfig, mut peer_channel_config_limits_arg: crate::util::config::ChannelHandshakeLimits, mut channel_options_arg: crate::util::config::ChannelConfig) -> UserConfig {
783 UserConfig { inner: Box::into_raw(Box::new(nativeUserConfig {
784 own_channel_config: *unsafe { Box::from_raw(own_channel_config_arg.take_inner()) },
785 peer_channel_config_limits: *unsafe { Box::from_raw(peer_channel_config_limits_arg.take_inner()) },
786 channel_options: *unsafe { Box::from_raw(channel_options_arg.take_inner()) },
787 })), is_owned: true }
789 impl Clone for UserConfig {
790 fn clone(&self) -> Self {
792 inner: if <*mut nativeUserConfig>::is_null(self.inner) { std::ptr::null_mut() } else {
793 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
799 /// Used only if an object of this type is returned as a trait impl by a method
800 pub(crate) extern "C" fn UserConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
801 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUserConfig)).clone() })) as *mut c_void
804 /// Creates a copy of the UserConfig
805 pub extern "C" fn UserConfig_clone(orig: &UserConfig) -> UserConfig {
808 /// Creates a "default" UserConfig. See struct and individual field documentaiton for details on which values are used.
811 pub extern "C" fn UserConfig_default() -> UserConfig {
812 UserConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }