1 //! Various user-configurable channel limits and settings which ChannelManager
5 use bitcoin::hashes::Hash;
9 use lightning::util::config::ChannelHandshakeConfig as nativeChannelHandshakeConfigImport;
10 type nativeChannelHandshakeConfig = nativeChannelHandshakeConfigImport;
12 /// Configuration we set when applicable.
14 /// Default::default() provides sane defaults.
17 pub struct ChannelHandshakeConfig {
18 /// A pointer to the opaque Rust object.
20 /// Nearly everywhere, inner must be non-null, however in places where
21 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
22 pub inner: *mut nativeChannelHandshakeConfig,
23 /// Indicates that this is the only struct which contains the same pointer.
25 /// Rust functions which take ownership of an object provided via an argument require
26 /// this to be true and invalidate the object pointed to by inner.
30 impl Drop for ChannelHandshakeConfig {
32 if self.is_owned && !<*mut nativeChannelHandshakeConfig>::is_null(self.inner) {
33 let _ = unsafe { Box::from_raw(self.inner) };
37 /// Frees any resources used by the ChannelHandshakeConfig, if is_owned is set and inner is non-NULL.
39 pub extern "C" fn ChannelHandshakeConfig_free(this_obj: ChannelHandshakeConfig) { }
41 /// Used only if an object of this type is returned as a trait impl by a method
42 extern "C" fn ChannelHandshakeConfig_free_void(this_ptr: *mut c_void) {
43 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelHandshakeConfig); }
46 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
47 impl ChannelHandshakeConfig {
48 pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeConfig {
49 assert!(self.is_owned);
51 self.inner = std::ptr::null_mut();
55 /// Confirmations we will wait for before considering the channel locked in.
56 /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
57 /// equivalent limit applied to outbound channels).
61 pub extern "C" fn ChannelHandshakeConfig_get_minimum_depth(this_ptr: &ChannelHandshakeConfig) -> u32 {
62 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.minimum_depth;
65 /// Confirmations we will wait for before considering the channel locked in.
66 /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
67 /// equivalent limit applied to outbound channels).
71 pub extern "C" fn ChannelHandshakeConfig_set_minimum_depth(this_ptr: &mut ChannelHandshakeConfig, mut val: u32) {
72 unsafe { &mut *this_ptr.inner }.minimum_depth = val;
74 /// Set to the amount of time we require our counterparty to wait to claim their money.
76 /// It's one of the main parameter of our security model. We (or one of our watchtowers) MUST
77 /// be online to check for peer having broadcast a revoked transaction to steal our funds
78 /// at least once every our_to_self_delay blocks.
80 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
81 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
84 /// Default value: BREAKDOWN_TIMEOUT (currently 144), we enforce it as a minimum at channel
85 /// opening so you can tweak config to ask for more security, not less.
87 pub extern "C" fn ChannelHandshakeConfig_get_our_to_self_delay(this_ptr: &ChannelHandshakeConfig) -> u16 {
88 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.our_to_self_delay;
91 /// Set to the amount of time we require our counterparty to wait to claim their money.
93 /// It's one of the main parameter of our security model. We (or one of our watchtowers) MUST
94 /// be online to check for peer having broadcast a revoked transaction to steal our funds
95 /// at least once every our_to_self_delay blocks.
97 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
98 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
101 /// Default value: BREAKDOWN_TIMEOUT (currently 144), we enforce it as a minimum at channel
102 /// opening so you can tweak config to ask for more security, not less.
104 pub extern "C" fn ChannelHandshakeConfig_set_our_to_self_delay(this_ptr: &mut ChannelHandshakeConfig, mut val: u16) {
105 unsafe { &mut *this_ptr.inner }.our_to_self_delay = val;
107 /// Set to the smallest value HTLC we will accept to process.
109 /// This value is sent to our counterparty on channel-open and we close the channel any time
110 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
112 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
115 pub extern "C" fn ChannelHandshakeConfig_get_our_htlc_minimum_msat(this_ptr: &ChannelHandshakeConfig) -> u64 {
116 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.our_htlc_minimum_msat;
119 /// Set to the smallest value HTLC we will accept to process.
121 /// This value is sent to our counterparty on channel-open and we close the channel any time
122 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
124 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
127 pub extern "C" fn ChannelHandshakeConfig_set_our_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeConfig, mut val: u64) {
128 unsafe { &mut *this_ptr.inner }.our_htlc_minimum_msat = val;
130 /// Constructs a new ChannelHandshakeConfig given each field
133 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 {
134 ChannelHandshakeConfig { inner: Box::into_raw(Box::new(nativeChannelHandshakeConfig {
135 minimum_depth: minimum_depth_arg,
136 our_to_self_delay: our_to_self_delay_arg,
137 our_htlc_minimum_msat: our_htlc_minimum_msat_arg,
138 })), is_owned: true }
140 impl Clone for ChannelHandshakeConfig {
141 fn clone(&self) -> Self {
143 inner: if <*mut nativeChannelHandshakeConfig>::is_null(self.inner) { std::ptr::null_mut() } else {
144 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
150 /// Used only if an object of this type is returned as a trait impl by a method
151 pub(crate) extern "C" fn ChannelHandshakeConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
152 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeConfig)).clone() })) as *mut c_void
155 /// Creates a copy of the ChannelHandshakeConfig
156 pub extern "C" fn ChannelHandshakeConfig_clone(orig: &ChannelHandshakeConfig) -> ChannelHandshakeConfig {
159 /// Creates a "default" ChannelHandshakeConfig. See struct and individual field documentaiton for details on which values are used.
162 pub extern "C" fn ChannelHandshakeConfig_default() -> ChannelHandshakeConfig {
163 ChannelHandshakeConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
166 use lightning::util::config::ChannelHandshakeLimits as nativeChannelHandshakeLimitsImport;
167 type nativeChannelHandshakeLimits = nativeChannelHandshakeLimitsImport;
169 /// Optional channel limits which are applied during channel creation.
171 /// These limits are only applied to our counterparty's limits, not our own.
173 /// Use 0/<type>::max_value() as appropriate to skip checking.
175 /// Provides sane defaults for most configurations.
177 /// Most additional limits are disabled except those with which specify a default in individual
178 /// field documentation. Note that this may result in barely-usable channels, but since they
179 /// are applied mostly only to incoming channels that's not much of a problem.
182 pub struct ChannelHandshakeLimits {
183 /// A pointer to the opaque Rust object.
185 /// Nearly everywhere, inner must be non-null, however in places where
186 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
187 pub inner: *mut nativeChannelHandshakeLimits,
188 /// Indicates that this is the only struct which contains the same pointer.
190 /// Rust functions which take ownership of an object provided via an argument require
191 /// this to be true and invalidate the object pointed to by inner.
195 impl Drop for ChannelHandshakeLimits {
197 if self.is_owned && !<*mut nativeChannelHandshakeLimits>::is_null(self.inner) {
198 let _ = unsafe { Box::from_raw(self.inner) };
202 /// Frees any resources used by the ChannelHandshakeLimits, if is_owned is set and inner is non-NULL.
204 pub extern "C" fn ChannelHandshakeLimits_free(this_obj: ChannelHandshakeLimits) { }
206 /// Used only if an object of this type is returned as a trait impl by a method
207 extern "C" fn ChannelHandshakeLimits_free_void(this_ptr: *mut c_void) {
208 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelHandshakeLimits); }
211 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
212 impl ChannelHandshakeLimits {
213 pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeLimits {
214 assert!(self.is_owned);
215 let ret = self.inner;
216 self.inner = std::ptr::null_mut();
220 /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
221 /// only applies to inbound channels.
223 /// Default value: 0.
225 pub extern "C" fn ChannelHandshakeLimits_get_min_funding_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
226 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_funding_satoshis;
229 /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
230 /// only applies to inbound channels.
232 /// Default value: 0.
234 pub extern "C" fn ChannelHandshakeLimits_set_min_funding_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
235 unsafe { &mut *this_ptr.inner }.min_funding_satoshis = val;
237 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
238 /// you to limit the maximum minimum-size they can require.
240 /// Default value: u64::max_value.
242 pub extern "C" fn ChannelHandshakeLimits_get_max_htlc_minimum_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
243 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_htlc_minimum_msat;
246 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
247 /// you to limit the maximum minimum-size they can require.
249 /// Default value: u64::max_value.
251 pub extern "C" fn ChannelHandshakeLimits_set_max_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
252 unsafe { &mut *this_ptr.inner }.max_htlc_minimum_msat = val;
254 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
255 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
257 /// Default value: 0.
259 pub extern "C" fn ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
260 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_max_htlc_value_in_flight_msat;
263 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
264 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
266 /// Default value: 0.
268 pub extern "C" fn ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
269 unsafe { &mut *this_ptr.inner }.min_max_htlc_value_in_flight_msat = val;
271 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
272 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
273 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
275 /// Default value: u64::max_value.
277 pub extern "C" fn ChannelHandshakeLimits_get_max_channel_reserve_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
278 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_channel_reserve_satoshis;
281 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
282 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
283 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
285 /// Default value: u64::max_value.
287 pub extern "C" fn ChannelHandshakeLimits_set_max_channel_reserve_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
288 unsafe { &mut *this_ptr.inner }.max_channel_reserve_satoshis = val;
290 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
291 /// time. This allows you to set a minimum such value.
293 /// Default value: 0.
295 pub extern "C" fn ChannelHandshakeLimits_get_min_max_accepted_htlcs(this_ptr: &ChannelHandshakeLimits) -> u16 {
296 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_max_accepted_htlcs;
299 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
300 /// time. This allows you to set a minimum such value.
302 /// Default value: 0.
304 pub extern "C" fn ChannelHandshakeLimits_set_min_max_accepted_htlcs(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
305 unsafe { &mut *this_ptr.inner }.min_max_accepted_htlcs = val;
307 /// Outputs below a certain value will not be added to on-chain transactions. The dust value is
308 /// required to always be higher than this value so this only applies to HTLC outputs (and
309 /// potentially to-self outputs before any payments have been made).
310 /// Thus, HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
311 /// This setting allows you to set a minimum dust limit for their commitment transactions,
312 /// reflecting the reality that tiny outputs are not considered standard transactions and will
313 /// not propagate through the Bitcoin network.
315 /// Default value: 546, the current dust limit on the Bitcoin network.
317 pub extern "C" fn ChannelHandshakeLimits_get_min_dust_limit_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
318 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_dust_limit_satoshis;
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_set_min_dust_limit_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
332 unsafe { &mut *this_ptr.inner }.min_dust_limit_satoshis = val;
334 /// Maximum allowed threshold above which outputs will not be generated in their commitment
336 /// HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
338 /// Default value: u64::max_value.
340 pub extern "C" fn ChannelHandshakeLimits_get_max_dust_limit_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
341 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_dust_limit_satoshis;
344 /// Maximum allowed threshold above which outputs will not be generated in their commitment
346 /// HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
348 /// Default value: u64::max_value.
350 pub extern "C" fn ChannelHandshakeLimits_set_max_dust_limit_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
351 unsafe { &mut *this_ptr.inner }.max_dust_limit_satoshis = val;
353 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
354 /// certain number of blocks, specified by the node which is not the funder (as the funder can
355 /// assume they aren't going to double-spend themselves).
356 /// This config allows you to set a limit on the maximum amount of time to wait.
358 /// Default value: 144, or roughly one day and only applies to outbound channels.
360 pub extern "C" fn ChannelHandshakeLimits_get_max_minimum_depth(this_ptr: &ChannelHandshakeLimits) -> u32 {
361 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_minimum_depth;
364 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
365 /// certain number of blocks, specified by the node which is not the funder (as the funder can
366 /// assume they aren't going to double-spend themselves).
367 /// This config allows you to set a limit on the maximum amount of time to wait.
369 /// Default value: 144, or roughly one day and only applies to outbound channels.
371 pub extern "C" fn ChannelHandshakeLimits_set_max_minimum_depth(this_ptr: &mut ChannelHandshakeLimits, mut val: u32) {
372 unsafe { &mut *this_ptr.inner }.max_minimum_depth = val;
374 /// Set to force the incoming channel to match our announced channel preference in
377 /// Default value: true, to make the default that no announced channels are possible (which is
378 /// appropriate for any nodes which are not online very reliably).
380 pub extern "C" fn ChannelHandshakeLimits_get_force_announced_channel_preference(this_ptr: &ChannelHandshakeLimits) -> bool {
381 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.force_announced_channel_preference;
384 /// Set to force the incoming channel to match our announced channel preference in
387 /// Default value: true, to make the default that no announced channels are possible (which is
388 /// appropriate for any nodes which are not online very reliably).
390 pub extern "C" fn ChannelHandshakeLimits_set_force_announced_channel_preference(this_ptr: &mut ChannelHandshakeLimits, mut val: bool) {
391 unsafe { &mut *this_ptr.inner }.force_announced_channel_preference = val;
393 /// Set to the amount of time we're willing to wait to claim money back to us.
395 /// Not checking this value would be a security issue, as our peer would be able to set it to
396 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
398 /// Default value: 2016, which we also enforce as a maximum value so you can tweak config to
399 /// reduce the loss of having useless locked funds (if your peer accepts)
401 pub extern "C" fn ChannelHandshakeLimits_get_their_to_self_delay(this_ptr: &ChannelHandshakeLimits) -> u16 {
402 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.their_to_self_delay;
405 /// Set to the amount of time we're willing to wait to claim money back to us.
407 /// Not checking this value would be a security issue, as our peer would be able to set it to
408 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
410 /// Default value: 2016, which we also enforce as a maximum value so you can tweak config to
411 /// reduce the loss of having useless locked funds (if your peer accepts)
413 pub extern "C" fn ChannelHandshakeLimits_set_their_to_self_delay(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
414 unsafe { &mut *this_ptr.inner }.their_to_self_delay = val;
416 /// Constructs a new ChannelHandshakeLimits given each field
419 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 {
420 ChannelHandshakeLimits { inner: Box::into_raw(Box::new(nativeChannelHandshakeLimits {
421 min_funding_satoshis: min_funding_satoshis_arg,
422 max_htlc_minimum_msat: max_htlc_minimum_msat_arg,
423 min_max_htlc_value_in_flight_msat: min_max_htlc_value_in_flight_msat_arg,
424 max_channel_reserve_satoshis: max_channel_reserve_satoshis_arg,
425 min_max_accepted_htlcs: min_max_accepted_htlcs_arg,
426 min_dust_limit_satoshis: min_dust_limit_satoshis_arg,
427 max_dust_limit_satoshis: max_dust_limit_satoshis_arg,
428 max_minimum_depth: max_minimum_depth_arg,
429 force_announced_channel_preference: force_announced_channel_preference_arg,
430 their_to_self_delay: their_to_self_delay_arg,
431 })), is_owned: true }
433 impl Clone for ChannelHandshakeLimits {
434 fn clone(&self) -> Self {
436 inner: if <*mut nativeChannelHandshakeLimits>::is_null(self.inner) { std::ptr::null_mut() } else {
437 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
443 /// Used only if an object of this type is returned as a trait impl by a method
444 pub(crate) extern "C" fn ChannelHandshakeLimits_clone_void(this_ptr: *const c_void) -> *mut c_void {
445 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeLimits)).clone() })) as *mut c_void
448 /// Creates a copy of the ChannelHandshakeLimits
449 pub extern "C" fn ChannelHandshakeLimits_clone(orig: &ChannelHandshakeLimits) -> ChannelHandshakeLimits {
452 /// Creates a "default" ChannelHandshakeLimits. See struct and individual field documentaiton for details on which values are used.
455 pub extern "C" fn ChannelHandshakeLimits_default() -> ChannelHandshakeLimits {
456 ChannelHandshakeLimits { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
459 use lightning::util::config::ChannelConfig as nativeChannelConfigImport;
460 type nativeChannelConfig = nativeChannelConfigImport;
462 /// Options which apply on a per-channel basis and may change at runtime or based on negotiation
463 /// with our counterparty.
466 pub struct ChannelConfig {
467 /// A pointer to the opaque Rust object.
469 /// Nearly everywhere, inner must be non-null, however in places where
470 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
471 pub inner: *mut nativeChannelConfig,
472 /// Indicates that this is the only struct which contains the same pointer.
474 /// Rust functions which take ownership of an object provided via an argument require
475 /// this to be true and invalidate the object pointed to by inner.
479 impl Drop for ChannelConfig {
481 if self.is_owned && !<*mut nativeChannelConfig>::is_null(self.inner) {
482 let _ = unsafe { Box::from_raw(self.inner) };
486 /// Frees any resources used by the ChannelConfig, if is_owned is set and inner is non-NULL.
488 pub extern "C" fn ChannelConfig_free(this_obj: ChannelConfig) { }
490 /// Used only if an object of this type is returned as a trait impl by a method
491 extern "C" fn ChannelConfig_free_void(this_ptr: *mut c_void) {
492 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelConfig); }
495 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
497 pub(crate) fn take_inner(mut self) -> *mut nativeChannelConfig {
498 assert!(self.is_owned);
499 let ret = self.inner;
500 self.inner = std::ptr::null_mut();
504 /// Amount (in millionths of a satoshi) the channel will charge per transferred satoshi.
505 /// This may be allowed to change at runtime in a later update, however doing so must result in
506 /// update messages sent to notify all nodes of our updated relay fee.
508 /// Default value: 0.
510 pub extern "C" fn ChannelConfig_get_fee_proportional_millionths(this_ptr: &ChannelConfig) -> u32 {
511 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fee_proportional_millionths;
514 /// Amount (in millionths of a satoshi) the channel will charge per transferred satoshi.
515 /// This may be allowed to change at runtime in a later update, however doing so must result in
516 /// update messages sent to notify all nodes of our updated relay fee.
518 /// Default value: 0.
520 pub extern "C" fn ChannelConfig_set_fee_proportional_millionths(this_ptr: &mut ChannelConfig, mut val: u32) {
521 unsafe { &mut *this_ptr.inner }.fee_proportional_millionths = val;
523 /// Set to announce the channel publicly and notify all nodes that they can route via this
526 /// This should only be set to true for nodes which expect to be online reliably.
528 /// As the node which funds a channel picks this value this will only apply for new outbound
529 /// channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set.
531 /// This cannot be changed after the initial channel handshake.
533 /// Default value: false.
535 pub extern "C" fn ChannelConfig_get_announced_channel(this_ptr: &ChannelConfig) -> bool {
536 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announced_channel;
539 /// Set to announce the channel publicly and notify all nodes that they can route via this
542 /// This should only be set to true for nodes which expect to be online reliably.
544 /// As the node which funds a channel picks this value this will only apply for new outbound
545 /// channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set.
547 /// This cannot be changed after the initial channel handshake.
549 /// Default value: false.
551 pub extern "C" fn ChannelConfig_set_announced_channel(this_ptr: &mut ChannelConfig, mut val: bool) {
552 unsafe { &mut *this_ptr.inner }.announced_channel = val;
554 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
555 /// supports it, they will then enforce the mutual-close output to us matches what we provided
556 /// at intialization, preventing us from closing to an alternate pubkey.
558 /// This is set to true by default to provide a slight increase in security, though ultimately
559 /// any attacker who is able to take control of a channel can just as easily send the funds via
560 /// lightning payments, so we never require that our counterparties support this option.
562 /// This cannot be changed after a channel has been initialized.
564 /// Default value: true.
566 pub extern "C" fn ChannelConfig_get_commit_upfront_shutdown_pubkey(this_ptr: &ChannelConfig) -> bool {
567 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.commit_upfront_shutdown_pubkey;
570 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
571 /// supports it, they will then enforce the mutual-close output to us matches what we provided
572 /// at intialization, preventing us from closing to an alternate pubkey.
574 /// This is set to true by default to provide a slight increase in security, though ultimately
575 /// any attacker who is able to take control of a channel can just as easily send the funds via
576 /// lightning payments, so we never require that our counterparties support this option.
578 /// This cannot be changed after a channel has been initialized.
580 /// Default value: true.
582 pub extern "C" fn ChannelConfig_set_commit_upfront_shutdown_pubkey(this_ptr: &mut ChannelConfig, mut val: bool) {
583 unsafe { &mut *this_ptr.inner }.commit_upfront_shutdown_pubkey = val;
585 /// Constructs a new ChannelConfig given each field
588 pub extern "C" fn ChannelConfig_new(mut fee_proportional_millionths_arg: u32, mut announced_channel_arg: bool, mut commit_upfront_shutdown_pubkey_arg: bool) -> ChannelConfig {
589 ChannelConfig { inner: Box::into_raw(Box::new(nativeChannelConfig {
590 fee_proportional_millionths: fee_proportional_millionths_arg,
591 announced_channel: announced_channel_arg,
592 commit_upfront_shutdown_pubkey: commit_upfront_shutdown_pubkey_arg,
593 })), is_owned: true }
595 impl Clone for ChannelConfig {
596 fn clone(&self) -> Self {
598 inner: if <*mut nativeChannelConfig>::is_null(self.inner) { std::ptr::null_mut() } else {
599 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
605 /// Used only if an object of this type is returned as a trait impl by a method
606 pub(crate) extern "C" fn ChannelConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
607 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelConfig)).clone() })) as *mut c_void
610 /// Creates a copy of the ChannelConfig
611 pub extern "C" fn ChannelConfig_clone(orig: &ChannelConfig) -> ChannelConfig {
614 /// Creates a "default" ChannelConfig. See struct and individual field documentaiton for details on which values are used.
617 pub extern "C" fn ChannelConfig_default() -> ChannelConfig {
618 ChannelConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
621 /// Serialize the ChannelConfig object into a byte array which can be read by ChannelConfig_read
622 pub extern "C" fn ChannelConfig_write(obj: &ChannelConfig) -> crate::c_types::derived::CVec_u8Z {
623 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
626 pub(crate) extern "C" fn ChannelConfig_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
627 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelConfig) })
630 /// Read a ChannelConfig from a byte array, created by ChannelConfig_write
631 pub extern "C" fn ChannelConfig_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelConfigDecodeErrorZ {
632 let res = crate::c_types::deserialize_obj(ser);
633 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() };
637 use lightning::util::config::UserConfig as nativeUserConfigImport;
638 type nativeUserConfig = nativeUserConfigImport;
640 /// Top-level config which holds ChannelHandshakeLimits and ChannelConfig.
642 /// Default::default() provides sane defaults for most configurations
643 /// (but currently with 0 relay fees!)
646 pub struct UserConfig {
647 /// A pointer to the opaque Rust object.
649 /// Nearly everywhere, inner must be non-null, however in places where
650 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
651 pub inner: *mut nativeUserConfig,
652 /// Indicates that this is the only struct which contains the same pointer.
654 /// Rust functions which take ownership of an object provided via an argument require
655 /// this to be true and invalidate the object pointed to by inner.
659 impl Drop for UserConfig {
661 if self.is_owned && !<*mut nativeUserConfig>::is_null(self.inner) {
662 let _ = unsafe { Box::from_raw(self.inner) };
666 /// Frees any resources used by the UserConfig, if is_owned is set and inner is non-NULL.
668 pub extern "C" fn UserConfig_free(this_obj: UserConfig) { }
670 /// Used only if an object of this type is returned as a trait impl by a method
671 extern "C" fn UserConfig_free_void(this_ptr: *mut c_void) {
672 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUserConfig); }
675 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
677 pub(crate) fn take_inner(mut self) -> *mut nativeUserConfig {
678 assert!(self.is_owned);
679 let ret = self.inner;
680 self.inner = std::ptr::null_mut();
684 /// Channel config that we propose to our counterparty.
686 pub extern "C" fn UserConfig_get_own_channel_config(this_ptr: &UserConfig) -> crate::util::config::ChannelHandshakeConfig {
687 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.own_channel_config;
688 crate::util::config::ChannelHandshakeConfig { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
690 /// Channel config that we propose to our counterparty.
692 pub extern "C" fn UserConfig_set_own_channel_config(this_ptr: &mut UserConfig, mut val: crate::util::config::ChannelHandshakeConfig) {
693 unsafe { &mut *this_ptr.inner }.own_channel_config = *unsafe { Box::from_raw(val.take_inner()) };
695 /// Limits applied to our counterparty's proposed channel config settings.
697 pub extern "C" fn UserConfig_get_peer_channel_config_limits(this_ptr: &UserConfig) -> crate::util::config::ChannelHandshakeLimits {
698 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.peer_channel_config_limits;
699 crate::util::config::ChannelHandshakeLimits { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
701 /// Limits applied to our counterparty's proposed channel config settings.
703 pub extern "C" fn UserConfig_set_peer_channel_config_limits(this_ptr: &mut UserConfig, mut val: crate::util::config::ChannelHandshakeLimits) {
704 unsafe { &mut *this_ptr.inner }.peer_channel_config_limits = *unsafe { Box::from_raw(val.take_inner()) };
706 /// Channel config which affects behavior during channel lifetime.
708 pub extern "C" fn UserConfig_get_channel_options(this_ptr: &UserConfig) -> crate::util::config::ChannelConfig {
709 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_options;
710 crate::util::config::ChannelConfig { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
712 /// Channel config which affects behavior during channel lifetime.
714 pub extern "C" fn UserConfig_set_channel_options(this_ptr: &mut UserConfig, mut val: crate::util::config::ChannelConfig) {
715 unsafe { &mut *this_ptr.inner }.channel_options = *unsafe { Box::from_raw(val.take_inner()) };
717 /// Constructs a new UserConfig given each field
720 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 {
721 UserConfig { inner: Box::into_raw(Box::new(nativeUserConfig {
722 own_channel_config: *unsafe { Box::from_raw(own_channel_config_arg.take_inner()) },
723 peer_channel_config_limits: *unsafe { Box::from_raw(peer_channel_config_limits_arg.take_inner()) },
724 channel_options: *unsafe { Box::from_raw(channel_options_arg.take_inner()) },
725 })), is_owned: true }
727 impl Clone for UserConfig {
728 fn clone(&self) -> Self {
730 inner: if <*mut nativeUserConfig>::is_null(self.inner) { std::ptr::null_mut() } else {
731 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
737 /// Used only if an object of this type is returned as a trait impl by a method
738 pub(crate) extern "C" fn UserConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
739 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUserConfig)).clone() })) as *mut c_void
742 /// Creates a copy of the UserConfig
743 pub extern "C" fn UserConfig_clone(orig: &UserConfig) -> UserConfig {
746 /// Creates a "default" UserConfig. See struct and individual field documentaiton for details on which values are used.
749 pub extern "C" fn UserConfig_default() -> UserConfig {
750 UserConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }