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 /// Nearly everywhere, inner must be non-null, however in places where
19 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
20 pub inner: *mut nativeChannelHandshakeConfig,
24 impl Drop for ChannelHandshakeConfig {
26 if self.is_owned && !self.inner.is_null() {
27 let _ = unsafe { Box::from_raw(self.inner) };
32 pub extern "C" fn ChannelHandshakeConfig_free(this_ptr: ChannelHandshakeConfig) { }
34 /// Used only if an object of this type is returned as a trait impl by a method
35 extern "C" fn ChannelHandshakeConfig_free_void(this_ptr: *mut c_void) {
36 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelHandshakeConfig); }
39 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
40 impl ChannelHandshakeConfig {
41 pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeConfig {
42 assert!(self.is_owned);
44 self.inner = std::ptr::null_mut();
48 impl Clone for ChannelHandshakeConfig {
49 fn clone(&self) -> Self {
51 inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
57 /// Used only if an object of this type is returned as a trait impl by a method
58 pub(crate) extern "C" fn ChannelHandshakeConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
59 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeConfig)).clone() })) as *mut c_void
62 pub extern "C" fn ChannelHandshakeConfig_clone(orig: &ChannelHandshakeConfig) -> ChannelHandshakeConfig {
63 ChannelHandshakeConfig { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
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_get_minimum_depth(this_ptr: &ChannelHandshakeConfig) -> u32 {
72 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.minimum_depth;
75 /// Confirmations we will wait for before considering the channel locked in.
76 /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
77 /// equivalent limit applied to outbound channels).
81 pub extern "C" fn ChannelHandshakeConfig_set_minimum_depth(this_ptr: &mut ChannelHandshakeConfig, mut val: u32) {
82 unsafe { &mut *this_ptr.inner }.minimum_depth = val;
84 /// Set to the amount of time we require our counterparty to wait to claim their money.
86 /// It's one of the main parameter of our security model. We (or one of our watchtowers) MUST
87 /// be online to check for peer having broadcast a revoked transaction to steal our funds
88 /// at least once every our_to_self_delay blocks.
90 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
91 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
94 /// Default value: BREAKDOWN_TIMEOUT (currently 144), we enforce it as a minimum at channel
95 /// opening so you can tweak config to ask for more security, not less.
97 pub extern "C" fn ChannelHandshakeConfig_get_our_to_self_delay(this_ptr: &ChannelHandshakeConfig) -> u16 {
98 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.our_to_self_delay;
101 /// Set to the amount of time we require our counterparty to wait to claim their money.
103 /// It's one of the main parameter of our security model. We (or one of our watchtowers) MUST
104 /// be online to check for peer having broadcast a revoked transaction to steal our funds
105 /// at least once every our_to_self_delay blocks.
107 /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
108 /// case of an honest unilateral channel close, which implicitly decrease the economic value of
111 /// Default value: BREAKDOWN_TIMEOUT (currently 144), we enforce it as a minimum at channel
112 /// opening so you can tweak config to ask for more security, not less.
114 pub extern "C" fn ChannelHandshakeConfig_set_our_to_self_delay(this_ptr: &mut ChannelHandshakeConfig, mut val: u16) {
115 unsafe { &mut *this_ptr.inner }.our_to_self_delay = val;
117 /// Set to the smallest value HTLC we will accept to process.
119 /// This value is sent to our counterparty on channel-open and we close the channel any time
120 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
122 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
125 pub extern "C" fn ChannelHandshakeConfig_get_our_htlc_minimum_msat(this_ptr: &ChannelHandshakeConfig) -> u64 {
126 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.our_htlc_minimum_msat;
129 /// Set to the smallest value HTLC we will accept to process.
131 /// This value is sent to our counterparty on channel-open and we close the channel any time
132 /// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
134 /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
137 pub extern "C" fn ChannelHandshakeConfig_set_our_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeConfig, mut val: u64) {
138 unsafe { &mut *this_ptr.inner }.our_htlc_minimum_msat = val;
142 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 {
143 ChannelHandshakeConfig { inner: Box::into_raw(Box::new(nativeChannelHandshakeConfig {
144 minimum_depth: minimum_depth_arg,
145 our_to_self_delay: our_to_self_delay_arg,
146 our_htlc_minimum_msat: our_htlc_minimum_msat_arg,
147 })), is_owned: true }
151 pub extern "C" fn ChannelHandshakeConfig_default() -> ChannelHandshakeConfig {
152 ChannelHandshakeConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
155 use lightning::util::config::ChannelHandshakeLimits as nativeChannelHandshakeLimitsImport;
156 type nativeChannelHandshakeLimits = nativeChannelHandshakeLimitsImport;
158 /// Optional channel limits which are applied during channel creation.
160 /// These limits are only applied to our counterparty's limits, not our own.
162 /// Use 0/<type>::max_value() as appropriate to skip checking.
164 /// Provides sane defaults for most configurations.
166 /// Most additional limits are disabled except those with which specify a default in individual
167 /// field documentation. Note that this may result in barely-usable channels, but since they
168 /// are applied mostly only to incoming channels that's not much of a problem.
171 pub struct ChannelHandshakeLimits {
172 /// Nearly everywhere, inner must be non-null, however in places where
173 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
174 pub inner: *mut nativeChannelHandshakeLimits,
178 impl Drop for ChannelHandshakeLimits {
180 if self.is_owned && !self.inner.is_null() {
181 let _ = unsafe { Box::from_raw(self.inner) };
186 pub extern "C" fn ChannelHandshakeLimits_free(this_ptr: ChannelHandshakeLimits) { }
188 /// Used only if an object of this type is returned as a trait impl by a method
189 extern "C" fn ChannelHandshakeLimits_free_void(this_ptr: *mut c_void) {
190 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelHandshakeLimits); }
193 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
194 impl ChannelHandshakeLimits {
195 pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeLimits {
196 assert!(self.is_owned);
197 let ret = self.inner;
198 self.inner = std::ptr::null_mut();
202 impl Clone for ChannelHandshakeLimits {
203 fn clone(&self) -> Self {
205 inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
211 /// Used only if an object of this type is returned as a trait impl by a method
212 pub(crate) extern "C" fn ChannelHandshakeLimits_clone_void(this_ptr: *const c_void) -> *mut c_void {
213 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeLimits)).clone() })) as *mut c_void
216 pub extern "C" fn ChannelHandshakeLimits_clone(orig: &ChannelHandshakeLimits) -> ChannelHandshakeLimits {
217 ChannelHandshakeLimits { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
219 /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
220 /// only applies to inbound channels.
222 /// Default value: 0.
224 pub extern "C" fn ChannelHandshakeLimits_get_min_funding_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
225 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_funding_satoshis;
228 /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
229 /// only applies to inbound channels.
231 /// Default value: 0.
233 pub extern "C" fn ChannelHandshakeLimits_set_min_funding_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
234 unsafe { &mut *this_ptr.inner }.min_funding_satoshis = val;
236 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
237 /// you to limit the maximum minimum-size they can require.
239 /// Default value: u64::max_value.
241 pub extern "C" fn ChannelHandshakeLimits_get_max_htlc_minimum_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
242 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_htlc_minimum_msat;
245 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
246 /// you to limit the maximum minimum-size they can require.
248 /// Default value: u64::max_value.
250 pub extern "C" fn ChannelHandshakeLimits_set_max_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
251 unsafe { &mut *this_ptr.inner }.max_htlc_minimum_msat = val;
253 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
254 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
256 /// Default value: 0.
258 pub extern "C" fn ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(this_ptr: &ChannelHandshakeLimits) -> u64 {
259 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_max_htlc_value_in_flight_msat;
262 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
263 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
265 /// Default value: 0.
267 pub extern "C" fn ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
268 unsafe { &mut *this_ptr.inner }.min_max_htlc_value_in_flight_msat = val;
270 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
271 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
272 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
274 /// Default value: u64::max_value.
276 pub extern "C" fn ChannelHandshakeLimits_get_max_channel_reserve_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
277 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_channel_reserve_satoshis;
280 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
281 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
282 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
284 /// Default value: u64::max_value.
286 pub extern "C" fn ChannelHandshakeLimits_set_max_channel_reserve_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
287 unsafe { &mut *this_ptr.inner }.max_channel_reserve_satoshis = val;
289 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
290 /// time. This allows you to set a minimum such value.
292 /// Default value: 0.
294 pub extern "C" fn ChannelHandshakeLimits_get_min_max_accepted_htlcs(this_ptr: &ChannelHandshakeLimits) -> u16 {
295 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_max_accepted_htlcs;
298 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
299 /// time. This allows you to set a minimum such value.
301 /// Default value: 0.
303 pub extern "C" fn ChannelHandshakeLimits_set_min_max_accepted_htlcs(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
304 unsafe { &mut *this_ptr.inner }.min_max_accepted_htlcs = val;
306 /// Outputs below a certain value will not be added to on-chain transactions. The dust value is
307 /// required to always be higher than this value so this only applies to HTLC outputs (and
308 /// potentially to-self outputs before any payments have been made).
309 /// Thus, HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
310 /// This setting allows you to set a minimum dust limit for their commitment transactions,
311 /// reflecting the reality that tiny outputs are not considered standard transactions and will
312 /// not propagate through the Bitcoin network.
314 /// Default value: 546, the current dust limit on the Bitcoin network.
316 pub extern "C" fn ChannelHandshakeLimits_get_min_dust_limit_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
317 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_dust_limit_satoshis;
320 /// Outputs below a certain value will not be added to on-chain transactions. The dust value is
321 /// required to always be higher than this value so this only applies to HTLC outputs (and
322 /// potentially to-self outputs before any payments have been made).
323 /// Thus, HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
324 /// This setting allows you to set a minimum dust limit for their commitment transactions,
325 /// reflecting the reality that tiny outputs are not considered standard transactions and will
326 /// not propagate through the Bitcoin network.
328 /// Default value: 546, the current dust limit on the Bitcoin network.
330 pub extern "C" fn ChannelHandshakeLimits_set_min_dust_limit_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
331 unsafe { &mut *this_ptr.inner }.min_dust_limit_satoshis = val;
333 /// Maximum allowed threshold above which outputs will not be generated in their commitment
335 /// HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
337 /// Default value: u64::max_value.
339 pub extern "C" fn ChannelHandshakeLimits_get_max_dust_limit_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 {
340 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_dust_limit_satoshis;
343 /// Maximum allowed threshold above which outputs will not be generated in their commitment
345 /// HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
347 /// Default value: u64::max_value.
349 pub extern "C" fn ChannelHandshakeLimits_set_max_dust_limit_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) {
350 unsafe { &mut *this_ptr.inner }.max_dust_limit_satoshis = val;
352 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
353 /// certain number of blocks, specified by the node which is not the funder (as the funder can
354 /// assume they aren't going to double-spend themselves).
355 /// This config allows you to set a limit on the maximum amount of time to wait.
357 /// Default value: 144, or roughly one day and only applies to outbound channels.
359 pub extern "C" fn ChannelHandshakeLimits_get_max_minimum_depth(this_ptr: &ChannelHandshakeLimits) -> u32 {
360 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_minimum_depth;
363 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
364 /// certain number of blocks, specified by the node which is not the funder (as the funder can
365 /// assume they aren't going to double-spend themselves).
366 /// This config allows you to set a limit on the maximum amount of time to wait.
368 /// Default value: 144, or roughly one day and only applies to outbound channels.
370 pub extern "C" fn ChannelHandshakeLimits_set_max_minimum_depth(this_ptr: &mut ChannelHandshakeLimits, mut val: u32) {
371 unsafe { &mut *this_ptr.inner }.max_minimum_depth = val;
373 /// Set to force the incoming channel to match our announced channel preference in
376 /// Default value: true, to make the default that no announced channels are possible (which is
377 /// appropriate for any nodes which are not online very reliably).
379 pub extern "C" fn ChannelHandshakeLimits_get_force_announced_channel_preference(this_ptr: &ChannelHandshakeLimits) -> bool {
380 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.force_announced_channel_preference;
383 /// Set to force the incoming channel to match our announced channel preference in
386 /// Default value: true, to make the default that no announced channels are possible (which is
387 /// appropriate for any nodes which are not online very reliably).
389 pub extern "C" fn ChannelHandshakeLimits_set_force_announced_channel_preference(this_ptr: &mut ChannelHandshakeLimits, mut val: bool) {
390 unsafe { &mut *this_ptr.inner }.force_announced_channel_preference = val;
392 /// Set to the amount of time we're willing to wait to claim money back to us.
394 /// Not checking this value would be a security issue, as our peer would be able to set it to
395 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
397 /// Default value: MAX_LOCAL_BREAKDOWN_TIMEOUT (1008), which we also enforce as a maximum value
398 /// so you can tweak config to reduce the loss of having useless locked funds (if your peer accepts)
400 pub extern "C" fn ChannelHandshakeLimits_get_their_to_self_delay(this_ptr: &ChannelHandshakeLimits) -> u16 {
401 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.their_to_self_delay;
404 /// Set to the amount of time we're willing to wait to claim money back to us.
406 /// Not checking this value would be a security issue, as our peer would be able to set it to
407 /// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time.
409 /// Default value: MAX_LOCAL_BREAKDOWN_TIMEOUT (1008), which we also enforce as a maximum value
410 /// so you can tweak config to reduce the loss of having useless locked funds (if your peer accepts)
412 pub extern "C" fn ChannelHandshakeLimits_set_their_to_self_delay(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) {
413 unsafe { &mut *this_ptr.inner }.their_to_self_delay = val;
417 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 {
418 ChannelHandshakeLimits { inner: Box::into_raw(Box::new(nativeChannelHandshakeLimits {
419 min_funding_satoshis: min_funding_satoshis_arg,
420 max_htlc_minimum_msat: max_htlc_minimum_msat_arg,
421 min_max_htlc_value_in_flight_msat: min_max_htlc_value_in_flight_msat_arg,
422 max_channel_reserve_satoshis: max_channel_reserve_satoshis_arg,
423 min_max_accepted_htlcs: min_max_accepted_htlcs_arg,
424 min_dust_limit_satoshis: min_dust_limit_satoshis_arg,
425 max_dust_limit_satoshis: max_dust_limit_satoshis_arg,
426 max_minimum_depth: max_minimum_depth_arg,
427 force_announced_channel_preference: force_announced_channel_preference_arg,
428 their_to_self_delay: their_to_self_delay_arg,
429 })), is_owned: true }
433 pub extern "C" fn ChannelHandshakeLimits_default() -> ChannelHandshakeLimits {
434 ChannelHandshakeLimits { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
437 use lightning::util::config::ChannelConfig as nativeChannelConfigImport;
438 type nativeChannelConfig = nativeChannelConfigImport;
440 /// Options which apply on a per-channel basis and may change at runtime or based on negotiation
441 /// with our counterparty.
444 pub struct ChannelConfig {
445 /// Nearly everywhere, inner must be non-null, however in places where
446 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
447 pub inner: *mut nativeChannelConfig,
451 impl Drop for ChannelConfig {
453 if self.is_owned && !self.inner.is_null() {
454 let _ = unsafe { Box::from_raw(self.inner) };
459 pub extern "C" fn ChannelConfig_free(this_ptr: ChannelConfig) { }
461 /// Used only if an object of this type is returned as a trait impl by a method
462 extern "C" fn ChannelConfig_free_void(this_ptr: *mut c_void) {
463 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelConfig); }
466 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
468 pub(crate) fn take_inner(mut self) -> *mut nativeChannelConfig {
469 assert!(self.is_owned);
470 let ret = self.inner;
471 self.inner = std::ptr::null_mut();
475 impl Clone for ChannelConfig {
476 fn clone(&self) -> Self {
478 inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
484 /// Used only if an object of this type is returned as a trait impl by a method
485 pub(crate) extern "C" fn ChannelConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
486 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelConfig)).clone() })) as *mut c_void
489 pub extern "C" fn ChannelConfig_clone(orig: &ChannelConfig) -> ChannelConfig {
490 ChannelConfig { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
492 /// Amount (in millionths of a satoshi) the channel will charge per transferred satoshi.
493 /// This may be allowed to change at runtime in a later update, however doing so must result in
494 /// update messages sent to notify all nodes of our updated relay fee.
496 /// Default value: 0.
498 pub extern "C" fn ChannelConfig_get_fee_proportional_millionths(this_ptr: &ChannelConfig) -> u32 {
499 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fee_proportional_millionths;
502 /// Amount (in millionths of a satoshi) the channel will charge per transferred satoshi.
503 /// This may be allowed to change at runtime in a later update, however doing so must result in
504 /// update messages sent to notify all nodes of our updated relay fee.
506 /// Default value: 0.
508 pub extern "C" fn ChannelConfig_set_fee_proportional_millionths(this_ptr: &mut ChannelConfig, mut val: u32) {
509 unsafe { &mut *this_ptr.inner }.fee_proportional_millionths = val;
511 /// Set to announce the channel publicly and notify all nodes that they can route via this
514 /// This should only be set to true for nodes which expect to be online reliably.
516 /// As the node which funds a channel picks this value this will only apply for new outbound
517 /// channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set.
519 /// This cannot be changed after the initial channel handshake.
521 /// Default value: false.
523 pub extern "C" fn ChannelConfig_get_announced_channel(this_ptr: &ChannelConfig) -> bool {
524 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announced_channel;
527 /// Set to announce the channel publicly and notify all nodes that they can route via this
530 /// This should only be set to true for nodes which expect to be online reliably.
532 /// As the node which funds a channel picks this value this will only apply for new outbound
533 /// channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set.
535 /// This cannot be changed after the initial channel handshake.
537 /// Default value: false.
539 pub extern "C" fn ChannelConfig_set_announced_channel(this_ptr: &mut ChannelConfig, mut val: bool) {
540 unsafe { &mut *this_ptr.inner }.announced_channel = val;
542 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
543 /// supports it, they will then enforce the mutual-close output to us matches what we provided
544 /// at intialization, preventing us from closing to an alternate pubkey.
546 /// This is set to true by default to provide a slight increase in security, though ultimately
547 /// any attacker who is able to take control of a channel can just as easily send the funds via
548 /// lightning payments, so we never require that our counterparties support this option.
550 /// This cannot be changed after a channel has been initialized.
552 /// Default value: true.
554 pub extern "C" fn ChannelConfig_get_commit_upfront_shutdown_pubkey(this_ptr: &ChannelConfig) -> bool {
555 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.commit_upfront_shutdown_pubkey;
558 /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
559 /// supports it, they will then enforce the mutual-close output to us matches what we provided
560 /// at intialization, preventing us from closing to an alternate pubkey.
562 /// This is set to true by default to provide a slight increase in security, though ultimately
563 /// any attacker who is able to take control of a channel can just as easily send the funds via
564 /// lightning payments, so we never require that our counterparties support this option.
566 /// This cannot be changed after a channel has been initialized.
568 /// Default value: true.
570 pub extern "C" fn ChannelConfig_set_commit_upfront_shutdown_pubkey(this_ptr: &mut ChannelConfig, mut val: bool) {
571 unsafe { &mut *this_ptr.inner }.commit_upfront_shutdown_pubkey = val;
575 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 {
576 ChannelConfig { inner: Box::into_raw(Box::new(nativeChannelConfig {
577 fee_proportional_millionths: fee_proportional_millionths_arg,
578 announced_channel: announced_channel_arg,
579 commit_upfront_shutdown_pubkey: commit_upfront_shutdown_pubkey_arg,
580 })), is_owned: true }
584 pub extern "C" fn ChannelConfig_default() -> ChannelConfig {
585 ChannelConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }
588 pub extern "C" fn ChannelConfig_write(obj: *const ChannelConfig) -> crate::c_types::derived::CVec_u8Z {
589 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
592 pub(crate) extern "C" fn ChannelConfig_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
593 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelConfig) })
596 pub extern "C" fn ChannelConfig_read(ser: crate::c_types::u8slice) -> ChannelConfig {
597 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
598 ChannelConfig { inner: Box::into_raw(Box::new(res)), is_owned: true }
600 ChannelConfig { inner: std::ptr::null_mut(), is_owned: true }
604 use lightning::util::config::UserConfig as nativeUserConfigImport;
605 type nativeUserConfig = nativeUserConfigImport;
607 /// Top-level config which holds ChannelHandshakeLimits and ChannelConfig.
609 /// Default::default() provides sane defaults for most configurations
610 /// (but currently with 0 relay fees!)
613 pub struct UserConfig {
614 /// Nearly everywhere, inner must be non-null, however in places where
615 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
616 pub inner: *mut nativeUserConfig,
620 impl Drop for UserConfig {
622 if self.is_owned && !self.inner.is_null() {
623 let _ = unsafe { Box::from_raw(self.inner) };
628 pub extern "C" fn UserConfig_free(this_ptr: UserConfig) { }
630 /// Used only if an object of this type is returned as a trait impl by a method
631 extern "C" fn UserConfig_free_void(this_ptr: *mut c_void) {
632 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUserConfig); }
635 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
637 pub(crate) fn take_inner(mut self) -> *mut nativeUserConfig {
638 assert!(self.is_owned);
639 let ret = self.inner;
640 self.inner = std::ptr::null_mut();
644 impl Clone for UserConfig {
645 fn clone(&self) -> Self {
647 inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
653 /// Used only if an object of this type is returned as a trait impl by a method
654 pub(crate) extern "C" fn UserConfig_clone_void(this_ptr: *const c_void) -> *mut c_void {
655 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUserConfig)).clone() })) as *mut c_void
658 pub extern "C" fn UserConfig_clone(orig: &UserConfig) -> UserConfig {
659 UserConfig { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
661 /// Channel config that we propose to our counterparty.
663 pub extern "C" fn UserConfig_get_own_channel_config(this_ptr: &UserConfig) -> crate::util::config::ChannelHandshakeConfig {
664 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.own_channel_config;
665 crate::util::config::ChannelHandshakeConfig { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
667 /// Channel config that we propose to our counterparty.
669 pub extern "C" fn UserConfig_set_own_channel_config(this_ptr: &mut UserConfig, mut val: crate::util::config::ChannelHandshakeConfig) {
670 unsafe { &mut *this_ptr.inner }.own_channel_config = *unsafe { Box::from_raw(val.take_inner()) };
672 /// Limits applied to our counterparty's proposed channel config settings.
674 pub extern "C" fn UserConfig_get_peer_channel_config_limits(this_ptr: &UserConfig) -> crate::util::config::ChannelHandshakeLimits {
675 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.peer_channel_config_limits;
676 crate::util::config::ChannelHandshakeLimits { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
678 /// Limits applied to our counterparty's proposed channel config settings.
680 pub extern "C" fn UserConfig_set_peer_channel_config_limits(this_ptr: &mut UserConfig, mut val: crate::util::config::ChannelHandshakeLimits) {
681 unsafe { &mut *this_ptr.inner }.peer_channel_config_limits = *unsafe { Box::from_raw(val.take_inner()) };
683 /// Channel config which affects behavior during channel lifetime.
685 pub extern "C" fn UserConfig_get_channel_options(this_ptr: &UserConfig) -> crate::util::config::ChannelConfig {
686 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_options;
687 crate::util::config::ChannelConfig { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
689 /// Channel config which affects behavior during channel lifetime.
691 pub extern "C" fn UserConfig_set_channel_options(this_ptr: &mut UserConfig, mut val: crate::util::config::ChannelConfig) {
692 unsafe { &mut *this_ptr.inner }.channel_options = *unsafe { Box::from_raw(val.take_inner()) };
696 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 {
697 UserConfig { inner: Box::into_raw(Box::new(nativeUserConfig {
698 own_channel_config: *unsafe { Box::from_raw(own_channel_config_arg.take_inner()) },
699 peer_channel_config_limits: *unsafe { Box::from_raw(peer_channel_config_limits_arg.take_inner()) },
700 channel_options: *unsafe { Box::from_raw(channel_options_arg.take_inner()) },
701 })), is_owned: true }
705 pub extern "C" fn UserConfig_default() -> UserConfig {
706 UserConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true }