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 //! The logic to monitor for on-chain transactions and create the relevant claim responses lives
12 //! ChannelMonitor objects are generated by ChannelManager in response to relevant
13 //! messages/actions, and MUST be persisted to disk (and, preferably, remotely) before progress can
14 //! be made in responding to certain messages, see [`chain::Watch`] for more.
16 //! Note that ChannelMonitors are an important part of the lightning trust model and a copy of the
17 //! latest ChannelMonitor must always be actively monitoring for chain updates (and no out-of-date
18 //! ChannelMonitors should do so). Thus, if you're building rust-lightning into an HSM or other
19 //! security-domain-separated system design, you should consider having multiple paths for
20 //! ChannelMonitors to get out of the HSM and onto monitoring devices.
22 use alloc::str::FromStr;
23 use core::ffi::c_void;
24 use core::convert::Infallible;
25 use bitcoin::hashes::Hash;
26 use crate::c_types::*;
27 #[cfg(feature="no-std")]
28 use alloc::{vec::Vec, boxed::Box};
31 use lightning::chain::channelmonitor::ChannelMonitorUpdate as nativeChannelMonitorUpdateImport;
32 pub(crate) type nativeChannelMonitorUpdate = nativeChannelMonitorUpdateImport;
34 /// An update generated by the underlying channel itself which contains some new information the
35 /// [`ChannelMonitor`] should be made aware of.
37 /// Because this represents only a small number of updates to the underlying state, it is generally
38 /// much smaller than a full [`ChannelMonitor`]. However, for large single commitment transaction
39 /// updates (e.g. ones during which there are hundreds of HTLCs pending on the commitment
40 /// transaction), a single update may reach upwards of 1 MiB in serialized size.
43 pub struct ChannelMonitorUpdate {
44 /// A pointer to the opaque Rust object.
46 /// Nearly everywhere, inner must be non-null, however in places where
47 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
48 pub inner: *mut nativeChannelMonitorUpdate,
49 /// Indicates that this is the only struct which contains the same pointer.
51 /// Rust functions which take ownership of an object provided via an argument require
52 /// this to be true and invalidate the object pointed to by inner.
56 impl Drop for ChannelMonitorUpdate {
58 if self.is_owned && !<*mut nativeChannelMonitorUpdate>::is_null(self.inner) {
59 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
63 /// Frees any resources used by the ChannelMonitorUpdate, if is_owned is set and inner is non-NULL.
65 pub extern "C" fn ChannelMonitorUpdate_free(this_obj: ChannelMonitorUpdate) { }
67 /// Used only if an object of this type is returned as a trait impl by a method
68 pub(crate) extern "C" fn ChannelMonitorUpdate_free_void(this_ptr: *mut c_void) {
69 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelMonitorUpdate) };
72 impl ChannelMonitorUpdate {
73 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelMonitorUpdate {
74 unsafe { &*ObjOps::untweak_ptr(self.inner) }
76 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelMonitorUpdate {
77 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
79 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
80 pub(crate) fn take_inner(mut self) -> *mut nativeChannelMonitorUpdate {
81 assert!(self.is_owned);
82 let ret = ObjOps::untweak_ptr(self.inner);
83 self.inner = core::ptr::null_mut();
87 /// The sequence number of this update. Updates *must* be replayed in-order according to this
88 /// sequence number (and updates may panic if they are not). The update_id values are strictly
89 /// increasing and increase by one for each new update, with two exceptions specified below.
91 /// This sequence number is also used to track up to which points updates which returned
92 /// [`ChannelMonitorUpdateStatus::InProgress`] have been applied to all copies of a given
93 /// ChannelMonitor when ChannelManager::channel_monitor_updated is called.
95 /// The only instances we allow where update_id values are not strictly increasing have a
96 /// special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. This update ID is used for updates that
97 /// will force close the channel by broadcasting the latest commitment transaction or
98 /// special post-force-close updates, like providing preimages necessary to claim outputs on the
99 /// broadcast commitment transaction. See its docs for more details.
101 /// [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
103 pub extern "C" fn ChannelMonitorUpdate_get_update_id(this_ptr: &ChannelMonitorUpdate) -> u64 {
104 let mut inner_val = &mut this_ptr.get_native_mut_ref().update_id;
107 /// The sequence number of this update. Updates *must* be replayed in-order according to this
108 /// sequence number (and updates may panic if they are not). The update_id values are strictly
109 /// increasing and increase by one for each new update, with two exceptions specified below.
111 /// This sequence number is also used to track up to which points updates which returned
112 /// [`ChannelMonitorUpdateStatus::InProgress`] have been applied to all copies of a given
113 /// ChannelMonitor when ChannelManager::channel_monitor_updated is called.
115 /// The only instances we allow where update_id values are not strictly increasing have a
116 /// special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. This update ID is used for updates that
117 /// will force close the channel by broadcasting the latest commitment transaction or
118 /// special post-force-close updates, like providing preimages necessary to claim outputs on the
119 /// broadcast commitment transaction. See its docs for more details.
121 /// [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
123 pub extern "C" fn ChannelMonitorUpdate_set_update_id(this_ptr: &mut ChannelMonitorUpdate, mut val: u64) {
124 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.update_id = val;
126 impl Clone for ChannelMonitorUpdate {
127 fn clone(&self) -> Self {
129 inner: if <*mut nativeChannelMonitorUpdate>::is_null(self.inner) { core::ptr::null_mut() } else {
130 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
136 /// Used only if an object of this type is returned as a trait impl by a method
137 pub(crate) extern "C" fn ChannelMonitorUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
138 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelMonitorUpdate)).clone() })) as *mut c_void
141 /// Creates a copy of the ChannelMonitorUpdate
142 pub extern "C" fn ChannelMonitorUpdate_clone(orig: &ChannelMonitorUpdate) -> ChannelMonitorUpdate {
145 /// Checks if two ChannelMonitorUpdates contain equal inner contents.
146 /// This ignores pointers and is_owned flags and looks at the values in fields.
147 /// Two objects with NULL inner values will be considered "equal" here.
149 pub extern "C" fn ChannelMonitorUpdate_eq(a: &ChannelMonitorUpdate, b: &ChannelMonitorUpdate) -> bool {
150 if a.inner == b.inner { return true; }
151 if a.inner.is_null() || b.inner.is_null() { return false; }
152 if a.get_native_ref() == b.get_native_ref() { true } else { false }
154 /// The update ID used for a [`ChannelMonitorUpdate`] that is either:
156 ///\t(1) attempting to force close the channel by broadcasting our latest commitment transaction or
157 ///\t(2) providing a preimage (after the channel has been force closed) from a forward link that
158 ///\t\tallows us to spend an HTLC output on this channel's (the backward link's) broadcasted
159 ///\t\tcommitment transaction.
161 /// No other [`ChannelMonitorUpdate`]s are allowed after force-close.
164 pub static CLOSED_CHANNEL_UPDATE_ID: u64 = lightning::chain::channelmonitor::CLOSED_CHANNEL_UPDATE_ID;
166 /// Serialize the ChannelMonitorUpdate object into a byte array which can be read by ChannelMonitorUpdate_read
167 pub extern "C" fn ChannelMonitorUpdate_write(obj: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate) -> crate::c_types::derived::CVec_u8Z {
168 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
171 pub(crate) extern "C" fn ChannelMonitorUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
172 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitorUpdate) })
175 /// Read a ChannelMonitorUpdate from a byte array, created by ChannelMonitorUpdate_write
176 pub extern "C" fn ChannelMonitorUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelMonitorUpdateDecodeErrorZ {
177 let res: Result<lightning::chain::channelmonitor::ChannelMonitorUpdate, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
178 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::chain::channelmonitor::ChannelMonitorUpdate { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
181 /// An event to be processed by the ChannelManager.
185 pub enum MonitorEvent {
186 /// A monitor event containing an HTLCUpdate.
188 crate::lightning::chain::channelmonitor::HTLCUpdate),
189 /// A monitor event that the Channel's commitment transaction was confirmed.
190 CommitmentTxConfirmed(
191 crate::lightning::chain::transaction::OutPoint),
192 /// Indicates a [`ChannelMonitor`] update has completed. See
193 /// [`ChannelMonitorUpdateStatus::InProgress`] for more information on how this is used.
195 /// [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
197 /// The funding outpoint of the [`ChannelMonitor`] that was updated
198 funding_txo: crate::lightning::chain::transaction::OutPoint,
199 /// The Update ID from [`ChannelMonitorUpdate::update_id`] which was applied or
200 /// [`ChannelMonitor::get_latest_update_id`].
202 /// Note that this should only be set to a given update's ID if all previous updates for the
203 /// same [`ChannelMonitor`] have been applied and persisted.
204 monitor_update_id: u64,
206 /// Indicates a [`ChannelMonitor`] update has failed. See
207 /// [`ChannelMonitorUpdateStatus::PermanentFailure`] for more information on how this is used.
209 /// [`ChannelMonitorUpdateStatus::PermanentFailure`]: super::ChannelMonitorUpdateStatus::PermanentFailure
211 crate::lightning::chain::transaction::OutPoint),
213 use lightning::chain::channelmonitor::MonitorEvent as MonitorEventImport;
214 pub(crate) type nativeMonitorEvent = MonitorEventImport;
218 pub(crate) fn to_native(&self) -> nativeMonitorEvent {
220 MonitorEvent::HTLCEvent (ref a, ) => {
221 let mut a_nonref = Clone::clone(a);
222 nativeMonitorEvent::HTLCEvent (
223 *unsafe { Box::from_raw(a_nonref.take_inner()) },
226 MonitorEvent::CommitmentTxConfirmed (ref a, ) => {
227 let mut a_nonref = Clone::clone(a);
228 nativeMonitorEvent::CommitmentTxConfirmed (
229 *unsafe { Box::from_raw(a_nonref.take_inner()) },
232 MonitorEvent::Completed {ref funding_txo, ref monitor_update_id, } => {
233 let mut funding_txo_nonref = Clone::clone(funding_txo);
234 let mut monitor_update_id_nonref = Clone::clone(monitor_update_id);
235 nativeMonitorEvent::Completed {
236 funding_txo: *unsafe { Box::from_raw(funding_txo_nonref.take_inner()) },
237 monitor_update_id: monitor_update_id_nonref,
240 MonitorEvent::UpdateFailed (ref a, ) => {
241 let mut a_nonref = Clone::clone(a);
242 nativeMonitorEvent::UpdateFailed (
243 *unsafe { Box::from_raw(a_nonref.take_inner()) },
249 pub(crate) fn into_native(self) -> nativeMonitorEvent {
251 MonitorEvent::HTLCEvent (mut a, ) => {
252 nativeMonitorEvent::HTLCEvent (
253 *unsafe { Box::from_raw(a.take_inner()) },
256 MonitorEvent::CommitmentTxConfirmed (mut a, ) => {
257 nativeMonitorEvent::CommitmentTxConfirmed (
258 *unsafe { Box::from_raw(a.take_inner()) },
261 MonitorEvent::Completed {mut funding_txo, mut monitor_update_id, } => {
262 nativeMonitorEvent::Completed {
263 funding_txo: *unsafe { Box::from_raw(funding_txo.take_inner()) },
264 monitor_update_id: monitor_update_id,
267 MonitorEvent::UpdateFailed (mut a, ) => {
268 nativeMonitorEvent::UpdateFailed (
269 *unsafe { Box::from_raw(a.take_inner()) },
275 pub(crate) fn from_native(native: &nativeMonitorEvent) -> Self {
277 nativeMonitorEvent::HTLCEvent (ref a, ) => {
278 let mut a_nonref = Clone::clone(a);
279 MonitorEvent::HTLCEvent (
280 crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
283 nativeMonitorEvent::CommitmentTxConfirmed (ref a, ) => {
284 let mut a_nonref = Clone::clone(a);
285 MonitorEvent::CommitmentTxConfirmed (
286 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
289 nativeMonitorEvent::Completed {ref funding_txo, ref monitor_update_id, } => {
290 let mut funding_txo_nonref = Clone::clone(funding_txo);
291 let mut monitor_update_id_nonref = Clone::clone(monitor_update_id);
292 MonitorEvent::Completed {
293 funding_txo: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo_nonref), is_owned: true },
294 monitor_update_id: monitor_update_id_nonref,
297 nativeMonitorEvent::UpdateFailed (ref a, ) => {
298 let mut a_nonref = Clone::clone(a);
299 MonitorEvent::UpdateFailed (
300 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
306 pub(crate) fn native_into(native: nativeMonitorEvent) -> Self {
308 nativeMonitorEvent::HTLCEvent (mut a, ) => {
309 MonitorEvent::HTLCEvent (
310 crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(a), is_owned: true },
313 nativeMonitorEvent::CommitmentTxConfirmed (mut a, ) => {
314 MonitorEvent::CommitmentTxConfirmed (
315 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a), is_owned: true },
318 nativeMonitorEvent::Completed {mut funding_txo, mut monitor_update_id, } => {
319 MonitorEvent::Completed {
320 funding_txo: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo), is_owned: true },
321 monitor_update_id: monitor_update_id,
324 nativeMonitorEvent::UpdateFailed (mut a, ) => {
325 MonitorEvent::UpdateFailed (
326 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a), is_owned: true },
332 /// Frees any resources used by the MonitorEvent
334 pub extern "C" fn MonitorEvent_free(this_ptr: MonitorEvent) { }
335 /// Creates a copy of the MonitorEvent
337 pub extern "C" fn MonitorEvent_clone(orig: &MonitorEvent) -> MonitorEvent {
341 /// Utility method to constructs a new HTLCEvent-variant MonitorEvent
342 pub extern "C" fn MonitorEvent_htlcevent(a: crate::lightning::chain::channelmonitor::HTLCUpdate) -> MonitorEvent {
343 MonitorEvent::HTLCEvent(a, )
346 /// Utility method to constructs a new CommitmentTxConfirmed-variant MonitorEvent
347 pub extern "C" fn MonitorEvent_commitment_tx_confirmed(a: crate::lightning::chain::transaction::OutPoint) -> MonitorEvent {
348 MonitorEvent::CommitmentTxConfirmed(a, )
351 /// Utility method to constructs a new Completed-variant MonitorEvent
352 pub extern "C" fn MonitorEvent_completed(funding_txo: crate::lightning::chain::transaction::OutPoint, monitor_update_id: u64) -> MonitorEvent {
353 MonitorEvent::Completed {
359 /// Utility method to constructs a new UpdateFailed-variant MonitorEvent
360 pub extern "C" fn MonitorEvent_update_failed(a: crate::lightning::chain::transaction::OutPoint) -> MonitorEvent {
361 MonitorEvent::UpdateFailed(a, )
363 /// Checks if two MonitorEvents contain equal inner contents.
364 /// This ignores pointers and is_owned flags and looks at the values in fields.
366 pub extern "C" fn MonitorEvent_eq(a: &MonitorEvent, b: &MonitorEvent) -> bool {
367 if &a.to_native() == &b.to_native() { true } else { false }
370 /// Serialize the MonitorEvent object into a byte array which can be read by MonitorEvent_read
371 pub extern "C" fn MonitorEvent_write(obj: &crate::lightning::chain::channelmonitor::MonitorEvent) -> crate::c_types::derived::CVec_u8Z {
372 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
375 /// Read a MonitorEvent from a byte array, created by MonitorEvent_write
376 pub extern "C" fn MonitorEvent_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_MonitorEventZDecodeErrorZ {
377 let res: Result<Option<lightning::chain::channelmonitor::MonitorEvent>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
378 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_MonitorEventZ::None } else { crate::c_types::derived::COption_MonitorEventZ::Some( { crate::lightning::chain::channelmonitor::MonitorEvent::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
382 use lightning::chain::channelmonitor::HTLCUpdate as nativeHTLCUpdateImport;
383 pub(crate) type nativeHTLCUpdate = nativeHTLCUpdateImport;
385 /// Simple structure sent back by `chain::Watch` when an HTLC from a forward channel is detected on
386 /// chain. Used to update the corresponding HTLC in the backward channel. Failing to pass the
387 /// preimage claim backward will lead to loss of funds.
390 pub struct HTLCUpdate {
391 /// A pointer to the opaque Rust object.
393 /// Nearly everywhere, inner must be non-null, however in places where
394 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
395 pub inner: *mut nativeHTLCUpdate,
396 /// Indicates that this is the only struct which contains the same pointer.
398 /// Rust functions which take ownership of an object provided via an argument require
399 /// this to be true and invalidate the object pointed to by inner.
403 impl Drop for HTLCUpdate {
405 if self.is_owned && !<*mut nativeHTLCUpdate>::is_null(self.inner) {
406 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
410 /// Frees any resources used by the HTLCUpdate, if is_owned is set and inner is non-NULL.
412 pub extern "C" fn HTLCUpdate_free(this_obj: HTLCUpdate) { }
414 /// Used only if an object of this type is returned as a trait impl by a method
415 pub(crate) extern "C" fn HTLCUpdate_free_void(this_ptr: *mut c_void) {
416 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeHTLCUpdate) };
420 pub(crate) fn get_native_ref(&self) -> &'static nativeHTLCUpdate {
421 unsafe { &*ObjOps::untweak_ptr(self.inner) }
423 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHTLCUpdate {
424 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
426 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
427 pub(crate) fn take_inner(mut self) -> *mut nativeHTLCUpdate {
428 assert!(self.is_owned);
429 let ret = ObjOps::untweak_ptr(self.inner);
430 self.inner = core::ptr::null_mut();
434 impl Clone for HTLCUpdate {
435 fn clone(&self) -> Self {
437 inner: if <*mut nativeHTLCUpdate>::is_null(self.inner) { core::ptr::null_mut() } else {
438 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
444 /// Used only if an object of this type is returned as a trait impl by a method
445 pub(crate) extern "C" fn HTLCUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
446 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCUpdate)).clone() })) as *mut c_void
449 /// Creates a copy of the HTLCUpdate
450 pub extern "C" fn HTLCUpdate_clone(orig: &HTLCUpdate) -> HTLCUpdate {
453 /// Checks if two HTLCUpdates contain equal inner contents.
454 /// This ignores pointers and is_owned flags and looks at the values in fields.
455 /// Two objects with NULL inner values will be considered "equal" here.
457 pub extern "C" fn HTLCUpdate_eq(a: &HTLCUpdate, b: &HTLCUpdate) -> bool {
458 if a.inner == b.inner { return true; }
459 if a.inner.is_null() || b.inner.is_null() { return false; }
460 if a.get_native_ref() == b.get_native_ref() { true } else { false }
463 /// Serialize the HTLCUpdate object into a byte array which can be read by HTLCUpdate_read
464 pub extern "C" fn HTLCUpdate_write(obj: &crate::lightning::chain::channelmonitor::HTLCUpdate) -> crate::c_types::derived::CVec_u8Z {
465 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
468 pub(crate) extern "C" fn HTLCUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
469 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCUpdate) })
472 /// Read a HTLCUpdate from a byte array, created by HTLCUpdate_write
473 pub extern "C" fn HTLCUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCUpdateDecodeErrorZ {
474 let res: Result<lightning::chain::channelmonitor::HTLCUpdate, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
475 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
478 /// Number of blocks we wait on seeing a HTLC output being solved before we fail corresponding
479 /// inbound HTLCs. This prevents us from failing backwards and then getting a reorg resulting in us
482 /// Note that this is a library-wide security assumption. If a reorg deeper than this number of
483 /// blocks occurs, counterparties may be able to steal funds or claims made by and balances exposed
484 /// by a [`ChannelMonitor`] may be incorrect.
487 pub static ANTI_REORG_DELAY: u32 = lightning::chain::channelmonitor::ANTI_REORG_DELAY;
488 /// Details about the balance(s) available for spending once the channel appears on chain.
490 /// See [`ChannelMonitor::get_claimable_balances`] for more details on when these will or will not
496 /// The channel is not yet closed (or the commitment or closing transaction has not yet
497 /// appeared in a block). The given balance is claimable (less on-chain fees) if the channel is
498 /// force-closed now.
499 ClaimableOnChannelClose {
500 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
501 /// required to do so.
502 claimable_amount_satoshis: u64,
504 /// The channel has been closed, and the given balance is ours but awaiting confirmations until
505 /// we consider it spendable.
506 ClaimableAwaitingConfirmations {
507 /// The amount available to claim, in satoshis, possibly excluding the on-chain fees which
508 /// were spent in broadcasting the transaction.
509 claimable_amount_satoshis: u64,
510 /// The height at which an [`Event::SpendableOutputs`] event will be generated for this
512 confirmation_height: u32,
514 /// The channel has been closed, and the given balance should be ours but awaiting spending
515 /// transaction confirmation. If the spending transaction does not confirm in time, it is
516 /// possible our counterparty can take the funds by broadcasting an HTLC timeout on-chain.
518 /// Once the spending transaction confirms, before it has reached enough confirmations to be
519 /// considered safe from chain reorganizations, the balance will instead be provided via
520 /// [`Balance::ClaimableAwaitingConfirmations`].
521 ContentiousClaimable {
522 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
523 /// required to do so.
524 claimable_amount_satoshis: u64,
525 /// The height at which the counterparty may be able to claim the balance if we have not
529 /// HTLCs which we sent to our counterparty which are claimable after a timeout (less on-chain
530 /// fees) if the counterparty does not know the preimage for the HTLCs. These are somewhat
531 /// likely to be claimed by our counterparty before we do.
532 MaybeTimeoutClaimableHTLC {
533 /// The amount potentially available to claim, in satoshis, excluding the on-chain fees
534 /// which will be required to do so.
535 claimable_amount_satoshis: u64,
536 /// The height at which we will be able to claim the balance if our counterparty has not
538 claimable_height: u32,
540 /// HTLCs which we received from our counterparty which are claimable with a preimage which we
541 /// do not currently have. This will only be claimable if we receive the preimage from the node
542 /// to which we forwarded this HTLC before the timeout.
543 MaybePreimageClaimableHTLC {
544 /// The amount potentially available to claim, in satoshis, excluding the on-chain fees
545 /// which will be required to do so.
546 claimable_amount_satoshis: u64,
547 /// The height at which our counterparty will be able to claim the balance if we have not
548 /// yet received the preimage and claimed it ourselves.
551 /// The channel has been closed, and our counterparty broadcasted a revoked commitment
554 /// Thus, we're able to claim all outputs in the commitment transaction, one of which has the
555 /// following amount.
556 CounterpartyRevokedOutputClaimable {
557 /// The amount, in satoshis, of the output which we can claim.
559 /// Note that for outputs from HTLC balances this may be excluding some on-chain fees that
560 /// were already spent.
561 claimable_amount_satoshis: u64,
564 use lightning::chain::channelmonitor::Balance as BalanceImport;
565 pub(crate) type nativeBalance = BalanceImport;
569 pub(crate) fn to_native(&self) -> nativeBalance {
571 Balance::ClaimableOnChannelClose {ref claimable_amount_satoshis, } => {
572 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
573 nativeBalance::ClaimableOnChannelClose {
574 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
577 Balance::ClaimableAwaitingConfirmations {ref claimable_amount_satoshis, ref confirmation_height, } => {
578 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
579 let mut confirmation_height_nonref = Clone::clone(confirmation_height);
580 nativeBalance::ClaimableAwaitingConfirmations {
581 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
582 confirmation_height: confirmation_height_nonref,
585 Balance::ContentiousClaimable {ref claimable_amount_satoshis, ref timeout_height, } => {
586 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
587 let mut timeout_height_nonref = Clone::clone(timeout_height);
588 nativeBalance::ContentiousClaimable {
589 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
590 timeout_height: timeout_height_nonref,
593 Balance::MaybeTimeoutClaimableHTLC {ref claimable_amount_satoshis, ref claimable_height, } => {
594 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
595 let mut claimable_height_nonref = Clone::clone(claimable_height);
596 nativeBalance::MaybeTimeoutClaimableHTLC {
597 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
598 claimable_height: claimable_height_nonref,
601 Balance::MaybePreimageClaimableHTLC {ref claimable_amount_satoshis, ref expiry_height, } => {
602 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
603 let mut expiry_height_nonref = Clone::clone(expiry_height);
604 nativeBalance::MaybePreimageClaimableHTLC {
605 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
606 expiry_height: expiry_height_nonref,
609 Balance::CounterpartyRevokedOutputClaimable {ref claimable_amount_satoshis, } => {
610 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
611 nativeBalance::CounterpartyRevokedOutputClaimable {
612 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
618 pub(crate) fn into_native(self) -> nativeBalance {
620 Balance::ClaimableOnChannelClose {mut claimable_amount_satoshis, } => {
621 nativeBalance::ClaimableOnChannelClose {
622 claimable_amount_satoshis: claimable_amount_satoshis,
625 Balance::ClaimableAwaitingConfirmations {mut claimable_amount_satoshis, mut confirmation_height, } => {
626 nativeBalance::ClaimableAwaitingConfirmations {
627 claimable_amount_satoshis: claimable_amount_satoshis,
628 confirmation_height: confirmation_height,
631 Balance::ContentiousClaimable {mut claimable_amount_satoshis, mut timeout_height, } => {
632 nativeBalance::ContentiousClaimable {
633 claimable_amount_satoshis: claimable_amount_satoshis,
634 timeout_height: timeout_height,
637 Balance::MaybeTimeoutClaimableHTLC {mut claimable_amount_satoshis, mut claimable_height, } => {
638 nativeBalance::MaybeTimeoutClaimableHTLC {
639 claimable_amount_satoshis: claimable_amount_satoshis,
640 claimable_height: claimable_height,
643 Balance::MaybePreimageClaimableHTLC {mut claimable_amount_satoshis, mut expiry_height, } => {
644 nativeBalance::MaybePreimageClaimableHTLC {
645 claimable_amount_satoshis: claimable_amount_satoshis,
646 expiry_height: expiry_height,
649 Balance::CounterpartyRevokedOutputClaimable {mut claimable_amount_satoshis, } => {
650 nativeBalance::CounterpartyRevokedOutputClaimable {
651 claimable_amount_satoshis: claimable_amount_satoshis,
657 pub(crate) fn from_native(native: &nativeBalance) -> Self {
659 nativeBalance::ClaimableOnChannelClose {ref claimable_amount_satoshis, } => {
660 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
661 Balance::ClaimableOnChannelClose {
662 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
665 nativeBalance::ClaimableAwaitingConfirmations {ref claimable_amount_satoshis, ref confirmation_height, } => {
666 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
667 let mut confirmation_height_nonref = Clone::clone(confirmation_height);
668 Balance::ClaimableAwaitingConfirmations {
669 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
670 confirmation_height: confirmation_height_nonref,
673 nativeBalance::ContentiousClaimable {ref claimable_amount_satoshis, ref timeout_height, } => {
674 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
675 let mut timeout_height_nonref = Clone::clone(timeout_height);
676 Balance::ContentiousClaimable {
677 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
678 timeout_height: timeout_height_nonref,
681 nativeBalance::MaybeTimeoutClaimableHTLC {ref claimable_amount_satoshis, ref claimable_height, } => {
682 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
683 let mut claimable_height_nonref = Clone::clone(claimable_height);
684 Balance::MaybeTimeoutClaimableHTLC {
685 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
686 claimable_height: claimable_height_nonref,
689 nativeBalance::MaybePreimageClaimableHTLC {ref claimable_amount_satoshis, ref expiry_height, } => {
690 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
691 let mut expiry_height_nonref = Clone::clone(expiry_height);
692 Balance::MaybePreimageClaimableHTLC {
693 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
694 expiry_height: expiry_height_nonref,
697 nativeBalance::CounterpartyRevokedOutputClaimable {ref claimable_amount_satoshis, } => {
698 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
699 Balance::CounterpartyRevokedOutputClaimable {
700 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
706 pub(crate) fn native_into(native: nativeBalance) -> Self {
708 nativeBalance::ClaimableOnChannelClose {mut claimable_amount_satoshis, } => {
709 Balance::ClaimableOnChannelClose {
710 claimable_amount_satoshis: claimable_amount_satoshis,
713 nativeBalance::ClaimableAwaitingConfirmations {mut claimable_amount_satoshis, mut confirmation_height, } => {
714 Balance::ClaimableAwaitingConfirmations {
715 claimable_amount_satoshis: claimable_amount_satoshis,
716 confirmation_height: confirmation_height,
719 nativeBalance::ContentiousClaimable {mut claimable_amount_satoshis, mut timeout_height, } => {
720 Balance::ContentiousClaimable {
721 claimable_amount_satoshis: claimable_amount_satoshis,
722 timeout_height: timeout_height,
725 nativeBalance::MaybeTimeoutClaimableHTLC {mut claimable_amount_satoshis, mut claimable_height, } => {
726 Balance::MaybeTimeoutClaimableHTLC {
727 claimable_amount_satoshis: claimable_amount_satoshis,
728 claimable_height: claimable_height,
731 nativeBalance::MaybePreimageClaimableHTLC {mut claimable_amount_satoshis, mut expiry_height, } => {
732 Balance::MaybePreimageClaimableHTLC {
733 claimable_amount_satoshis: claimable_amount_satoshis,
734 expiry_height: expiry_height,
737 nativeBalance::CounterpartyRevokedOutputClaimable {mut claimable_amount_satoshis, } => {
738 Balance::CounterpartyRevokedOutputClaimable {
739 claimable_amount_satoshis: claimable_amount_satoshis,
745 /// Frees any resources used by the Balance
747 pub extern "C" fn Balance_free(this_ptr: Balance) { }
748 /// Creates a copy of the Balance
750 pub extern "C" fn Balance_clone(orig: &Balance) -> Balance {
754 /// Utility method to constructs a new ClaimableOnChannelClose-variant Balance
755 pub extern "C" fn Balance_claimable_on_channel_close(claimable_amount_satoshis: u64) -> Balance {
756 Balance::ClaimableOnChannelClose {
757 claimable_amount_satoshis,
761 /// Utility method to constructs a new ClaimableAwaitingConfirmations-variant Balance
762 pub extern "C" fn Balance_claimable_awaiting_confirmations(claimable_amount_satoshis: u64, confirmation_height: u32) -> Balance {
763 Balance::ClaimableAwaitingConfirmations {
764 claimable_amount_satoshis,
769 /// Utility method to constructs a new ContentiousClaimable-variant Balance
770 pub extern "C" fn Balance_contentious_claimable(claimable_amount_satoshis: u64, timeout_height: u32) -> Balance {
771 Balance::ContentiousClaimable {
772 claimable_amount_satoshis,
777 /// Utility method to constructs a new MaybeTimeoutClaimableHTLC-variant Balance
778 pub extern "C" fn Balance_maybe_timeout_claimable_htlc(claimable_amount_satoshis: u64, claimable_height: u32) -> Balance {
779 Balance::MaybeTimeoutClaimableHTLC {
780 claimable_amount_satoshis,
785 /// Utility method to constructs a new MaybePreimageClaimableHTLC-variant Balance
786 pub extern "C" fn Balance_maybe_preimage_claimable_htlc(claimable_amount_satoshis: u64, expiry_height: u32) -> Balance {
787 Balance::MaybePreimageClaimableHTLC {
788 claimable_amount_satoshis,
793 /// Utility method to constructs a new CounterpartyRevokedOutputClaimable-variant Balance
794 pub extern "C" fn Balance_counterparty_revoked_output_claimable(claimable_amount_satoshis: u64) -> Balance {
795 Balance::CounterpartyRevokedOutputClaimable {
796 claimable_amount_satoshis,
799 /// Checks if two Balances contain equal inner contents.
800 /// This ignores pointers and is_owned flags and looks at the values in fields.
802 pub extern "C" fn Balance_eq(a: &Balance, b: &Balance) -> bool {
803 if &a.to_native() == &b.to_native() { true } else { false }
806 use lightning::chain::channelmonitor::ChannelMonitor as nativeChannelMonitorImport;
807 pub(crate) type nativeChannelMonitor = nativeChannelMonitorImport<crate::lightning::chain::keysinterface::WriteableEcdsaChannelSigner>;
809 /// A ChannelMonitor handles chain events (blocks connected and disconnected) and generates
810 /// on-chain transactions to ensure no loss of funds occurs.
812 /// You MUST ensure that no ChannelMonitors for a given channel anywhere contain out-of-date
813 /// information and are actively monitoring the chain.
815 /// Pending Events or updated HTLCs which have not yet been read out by
816 /// get_and_clear_pending_monitor_events or get_and_clear_pending_events are serialized to disk and
817 /// reloaded at deserialize-time. Thus, you must ensure that, when handling events, all events
818 /// gotten are fully handled before re-serializing the new state.
820 /// Note that the deserializer is only implemented for (BlockHash, ChannelMonitor), which
821 /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
822 /// the \"reorg path\" (ie disconnecting blocks until you find a common ancestor from both the
823 /// returned block hash and the the current chain and then reconnecting blocks to get to the
824 /// best chain) upon deserializing the object!
827 pub struct ChannelMonitor {
828 /// A pointer to the opaque Rust object.
830 /// Nearly everywhere, inner must be non-null, however in places where
831 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
832 pub inner: *mut nativeChannelMonitor,
833 /// Indicates that this is the only struct which contains the same pointer.
835 /// Rust functions which take ownership of an object provided via an argument require
836 /// this to be true and invalidate the object pointed to by inner.
840 impl Drop for ChannelMonitor {
842 if self.is_owned && !<*mut nativeChannelMonitor>::is_null(self.inner) {
843 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
847 /// Frees any resources used by the ChannelMonitor, if is_owned is set and inner is non-NULL.
849 pub extern "C" fn ChannelMonitor_free(this_obj: ChannelMonitor) { }
851 /// Used only if an object of this type is returned as a trait impl by a method
852 pub(crate) extern "C" fn ChannelMonitor_free_void(this_ptr: *mut c_void) {
853 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelMonitor) };
856 impl ChannelMonitor {
857 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelMonitor {
858 unsafe { &*ObjOps::untweak_ptr(self.inner) }
860 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelMonitor {
861 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
863 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
864 pub(crate) fn take_inner(mut self) -> *mut nativeChannelMonitor {
865 assert!(self.is_owned);
866 let ret = ObjOps::untweak_ptr(self.inner);
867 self.inner = core::ptr::null_mut();
872 /// Serialize the ChannelMonitor object into a byte array which can be read by ChannelMonitor_read
873 pub extern "C" fn ChannelMonitor_write(obj: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_u8Z {
874 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
877 pub(crate) extern "C" fn ChannelMonitor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
878 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitor) })
880 /// Updates a ChannelMonitor on the basis of some new information provided by the Channel
883 /// panics if the given update is not the next update by update_id.
886 pub extern "C" fn ChannelMonitor_update_monitor(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, updates: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate, broadcaster: &crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, logger: &crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_NoneNoneZ {
887 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_monitor(updates.get_native_ref(), broadcaster, fee_estimator, logger);
888 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
892 /// Gets the update_id from the latest ChannelMonitorUpdate which was applied to this
896 pub extern "C" fn ChannelMonitor_get_latest_update_id(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> u64 {
897 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_latest_update_id();
901 /// Gets the funding transaction outpoint of the channel this ChannelMonitor is monitoring for.
904 pub extern "C" fn ChannelMonitor_get_funding_txo(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::C2Tuple_OutPointScriptZ {
905 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_funding_txo();
906 let (mut orig_ret_0, mut orig_ret_1) = ret; let mut local_ret = (crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(orig_ret_0), is_owned: true }, orig_ret_1.into_bytes().into()).into();
910 /// Gets a list of txids, with their output scripts (in the order they appear in the
911 /// transaction), which we must learn about spends of via block_connected().
914 pub extern "C" fn ChannelMonitor_get_outputs_to_watch(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_C2Tuple_TxidCVec_C2Tuple_u32ScriptZZZZ {
915 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_outputs_to_watch();
916 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { let (mut orig_orig_ret_0_1_0_0, mut orig_orig_ret_0_1_0_1) = item; let mut local_orig_ret_0_1_0 = (orig_orig_ret_0_1_0_0, orig_orig_ret_0_1_0_1.into_bytes().into()).into(); local_orig_ret_0_1_0 }); }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.into_inner() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); };
920 /// Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly
921 /// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs
922 /// have been registered.
924 pub extern "C" fn ChannelMonitor_load_outputs_to_watch(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, filter: &crate::lightning::chain::Filter) {
925 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.load_outputs_to_watch(filter)
928 /// Get the list of HTLCs who's status has been updated on chain. This should be called by
929 /// ChannelManager via [`chain::Watch::release_pending_monitor_events`].
932 pub extern "C" fn ChannelMonitor_get_and_clear_pending_monitor_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_MonitorEventZ {
933 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_and_clear_pending_monitor_events();
934 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::MonitorEvent::native_into(item) }); };
938 /// Gets the list of pending events which were generated by previous actions, clearing the list
941 /// This is called by the [`EventsProvider::process_pending_events`] implementation for
942 /// [`ChainMonitor`].
944 /// [`EventsProvider::process_pending_events`]: crate::events::EventsProvider::process_pending_events
945 /// [`ChainMonitor`]: crate::chain::chainmonitor::ChainMonitor
948 pub extern "C" fn ChannelMonitor_get_and_clear_pending_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_EventZ {
949 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_and_clear_pending_events();
950 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::events::Event::native_into(item) }); };
954 /// Gets the `node_id` of the counterparty for this channel.
956 /// Will be `None` for channels constructed on LDK versions prior to 0.0.110 and always `Some`
959 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
962 pub extern "C" fn ChannelMonitor_get_counterparty_node_id(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::PublicKey {
963 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_counterparty_node_id();
964 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
968 /// Used by ChannelManager deserialization to broadcast the latest holder state if its copy of
969 /// the Channel was out-of-date.
971 /// You may also use this to broadcast the latest local commitment transaction, either because
972 /// a monitor update failed with [`ChannelMonitorUpdateStatus::PermanentFailure`] or because we've
973 /// fallen behind (i.e. we've received proof that our counterparty side knows a revocation
974 /// secret we gave them that they shouldn't know).
976 /// Broadcasting these transactions in the second case is UNSAFE, as they allow counterparty
977 /// side to punish you. Nevertheless you may want to broadcast them if counterparty doesn't
978 /// close channel with their commitment transaction after a substantial amount of time. Best
979 /// may be to contact the other node operator out-of-band to coordinate other options available
980 /// to you. In any-case, the choice is up to you.
982 /// [`ChannelMonitorUpdateStatus::PermanentFailure`]: super::ChannelMonitorUpdateStatus::PermanentFailure
985 pub extern "C" fn ChannelMonitor_get_latest_holder_commitment_txn(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, logger: &crate::lightning::util::logger::Logger) -> crate::c_types::derived::CVec_TransactionZ {
986 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_latest_holder_commitment_txn(logger);
987 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::Transaction::from_bitcoin(&item) }); };
991 /// Processes transactions in a newly connected block, which may result in any of the following:
992 /// - update the monitor's state against resolved HTLCs
993 /// - punish the counterparty in the case of seeing a revoked commitment transaction
994 /// - force close the channel and claim/timeout incoming/outgoing HTLCs if near expiration
995 /// - detect settled outputs for later spending
996 /// - schedule and bump any in-flight claims
998 /// Returns any new outputs to watch from `txdata`; after called, these are also included in
999 /// [`get_outputs_to_watch`].
1001 /// [`get_outputs_to_watch`]: #method.get_outputs_to_watch
1004 pub extern "C" fn ChannelMonitor_block_connected(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, header: *const [u8; 80], mut txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ, mut height: u32, mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, mut logger: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CVec_TransactionOutputsZ {
1005 let mut local_txdata = Vec::new(); for mut item in txdata.into_rust().drain(..) { local_txdata.push( { let (mut orig_txdata_0_0, mut orig_txdata_0_1) = item.to_rust(); let mut local_txdata_0 = (orig_txdata_0_0, orig_txdata_0_1.into_bitcoin()); local_txdata_0 }); };
1006 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.block_connected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), &local_txdata.iter().map(|(a, b)| (*a, b)).collect::<Vec<_>>()[..], height, broadcaster, fee_estimator, logger);
1007 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { let (mut orig_orig_ret_0_1_0_0, mut orig_orig_ret_0_1_0_1) = item; let mut local_orig_ret_0_1_0 = (orig_orig_ret_0_1_0_0, crate::c_types::TxOut::from_rust(orig_orig_ret_0_1_0_1)).into(); local_orig_ret_0_1_0 }); }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.into_inner() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); };
1011 /// Determines if the disconnected block contained any transactions of interest and updates
1014 pub extern "C" fn ChannelMonitor_block_disconnected(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, header: *const [u8; 80], mut height: u32, mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, mut logger: crate::lightning::util::logger::Logger) {
1015 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height, broadcaster, fee_estimator, logger)
1018 /// Processes transactions confirmed in a block with the given header and height, returning new
1019 /// outputs to watch. See [`block_connected`] for details.
1021 /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
1022 /// blocks. See [`chain::Confirm`] for calling expectations.
1024 /// [`block_connected`]: Self::block_connected
1027 pub extern "C" fn ChannelMonitor_transactions_confirmed(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, header: *const [u8; 80], mut txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ, mut height: u32, mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, mut logger: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CVec_TransactionOutputsZ {
1028 let mut local_txdata = Vec::new(); for mut item in txdata.into_rust().drain(..) { local_txdata.push( { let (mut orig_txdata_0_0, mut orig_txdata_0_1) = item.to_rust(); let mut local_txdata_0 = (orig_txdata_0_0, orig_txdata_0_1.into_bitcoin()); local_txdata_0 }); };
1029 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.transactions_confirmed(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), &local_txdata.iter().map(|(a, b)| (*a, b)).collect::<Vec<_>>()[..], height, broadcaster, fee_estimator, logger);
1030 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { let (mut orig_orig_ret_0_1_0_0, mut orig_orig_ret_0_1_0_1) = item; let mut local_orig_ret_0_1_0 = (orig_orig_ret_0_1_0_0, crate::c_types::TxOut::from_rust(orig_orig_ret_0_1_0_1)).into(); local_orig_ret_0_1_0 }); }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.into_inner() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); };
1034 /// Processes a transaction that was reorganized out of the chain.
1036 /// Used instead of [`block_disconnected`] by clients that are notified of transactions rather
1037 /// than blocks. See [`chain::Confirm`] for calling expectations.
1039 /// [`block_disconnected`]: Self::block_disconnected
1041 pub extern "C" fn ChannelMonitor_transaction_unconfirmed(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, txid: *const [u8; 32], mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, mut logger: crate::lightning::util::logger::Logger) {
1042 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.transaction_unconfirmed(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap(), broadcaster, fee_estimator, logger)
1045 /// Updates the monitor with the current best chain tip, returning new outputs to watch. See
1046 /// [`block_connected`] for details.
1048 /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
1049 /// blocks. See [`chain::Confirm`] for calling expectations.
1051 /// [`block_connected`]: Self::block_connected
1054 pub extern "C" fn ChannelMonitor_best_block_updated(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, header: *const [u8; 80], mut height: u32, mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, mut logger: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CVec_TransactionOutputsZ {
1055 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.best_block_updated(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height, broadcaster, fee_estimator, logger);
1056 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { let (mut orig_orig_ret_0_1_0_0, mut orig_orig_ret_0_1_0_1) = item; let mut local_orig_ret_0_1_0 = (orig_orig_ret_0_1_0_0, crate::c_types::TxOut::from_rust(orig_orig_ret_0_1_0_1)).into(); local_orig_ret_0_1_0 }); }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.into_inner() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); };
1060 /// Returns the set of txids that should be monitored for re-organization out of the chain.
1063 pub extern "C" fn ChannelMonitor_get_relevant_txids(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_C2Tuple_TxidBlockHashZZ {
1064 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_relevant_txids();
1065 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = if orig_ret_0_1.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (orig_ret_0_1.unwrap()).into_inner() } } }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.into_inner() }, local_orig_ret_0_1).into(); local_ret_0 }); };
1069 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
1070 /// [`chain::Confirm`] interfaces.
1073 pub extern "C" fn ChannelMonitor_current_best_block(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::lightning::chain::BestBlock {
1074 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
1075 crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
1078 /// Triggers rebroadcasts/fee-bumps of pending claims from a force-closed channel. This is
1079 /// crucial in preventing certain classes of pinning attacks, detecting substantial mempool
1080 /// feerate changes between blocks, and ensuring reliability if broadcasting fails. We recommend
1081 /// invoking this every 30 seconds, or lower if running in an environment with spotty
1082 /// connections, like on mobile.
1084 pub extern "C" fn ChannelMonitor_rebroadcast_pending_claims(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, mut logger: crate::lightning::util::logger::Logger) {
1085 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.rebroadcast_pending_claims(broadcaster, fee_estimator, logger)
1088 /// Gets the balances in this channel which are either claimable by us if we were to
1089 /// force-close the channel now or which are claimable on-chain (possibly awaiting
1092 /// Any balances in the channel which are available on-chain (excluding on-chain fees) are
1093 /// included here until an [`Event::SpendableOutputs`] event has been generated for the
1094 /// balance, or until our counterparty has claimed the balance and accrued several
1095 /// confirmations on the claim transaction.
1097 /// Note that for `ChannelMonitors` which track a channel which went on-chain with versions of
1098 /// LDK prior to 0.0.111, balances may not be fully captured if our counterparty broadcasted
1099 /// a revoked state.
1101 /// See [`Balance`] for additional details on the types of claimable balances which
1102 /// may be returned here and their meanings.
1105 pub extern "C" fn ChannelMonitor_get_claimable_balances(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_BalanceZ {
1106 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_claimable_balances();
1107 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::Balance::native_into(item) }); };
1112 /// Read a C2Tuple_BlockHashChannelMonitorZ from a byte array, created by C2Tuple_BlockHashChannelMonitorZ_write
1113 pub extern "C" fn C2Tuple_BlockHashChannelMonitorZ_read(ser: crate::c_types::u8slice, arg_a: &crate::lightning::chain::keysinterface::EntropySource, arg_b: &crate::lightning::chain::keysinterface::SignerProvider) -> crate::c_types::derived::CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ {
1114 let arg_a_conv = arg_a;
1115 let arg_b_conv = arg_b;
1116 let arg_conv = (arg_a_conv, arg_b_conv);
1117 let res: Result<(bitcoin::hash_types::BlockHash, lightning::chain::channelmonitor::ChannelMonitor<crate::lightning::chain::keysinterface::WriteableEcdsaChannelSigner>), lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
1118 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_res_0_0, mut orig_res_0_1) = o; let mut local_res_0 = (crate::c_types::ThirtyTwoBytes { data: orig_res_0_0.into_inner() }, crate::lightning::chain::channelmonitor::ChannelMonitor { inner: ObjOps::heap_alloc(orig_res_0_1), is_owned: true }).into(); local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };