1 //! The logic to monitor for on-chain transactions and create the relevant claim responses lives
4 //! ChannelMonitor objects are generated by ChannelManager in response to relevant
5 //! messages/actions, and MUST be persisted to disk (and, preferably, remotely) before progress can
6 //! be made in responding to certain messages, see ManyChannelMonitor for more.
8 //! Note that ChannelMonitors are an important part of the lightning trust model and a copy of the
9 //! latest ChannelMonitor must always be actively monitoring for chain updates (and no out-of-date
10 //! ChannelMonitors should do so). Thus, if you're building rust-lightning into an HSM or other
11 //! security-domain-separated system design, you should consider having multiple paths for
12 //! ChannelMonitors to get out of the HSM and onto monitoring devices.
15 use bitcoin::hashes::Hash;
16 use crate::c_types::*;
19 use lightning::ln::channelmonitor::ChannelMonitorUpdate as nativeChannelMonitorUpdateImport;
20 type nativeChannelMonitorUpdate = nativeChannelMonitorUpdateImport;
22 /// An update generated by the underlying Channel itself which contains some new information the
23 /// ChannelMonitor should be made aware of.
26 pub struct ChannelMonitorUpdate {
27 /// Nearly everyhwere, inner must be non-null, however in places where
28 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
29 pub inner: *mut nativeChannelMonitorUpdate,
33 impl Drop for ChannelMonitorUpdate {
35 if self.is_owned && !self.inner.is_null() {
36 let _ = unsafe { Box::from_raw(self.inner) };
41 pub extern "C" fn ChannelMonitorUpdate_free(this_ptr: ChannelMonitorUpdate) { }
43 /// Used only if an object of this type is returned as a trait impl by a method
44 extern "C" fn ChannelMonitorUpdate_free_void(this_ptr: *mut c_void) {
45 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelMonitorUpdate); }
48 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
49 impl ChannelMonitorUpdate {
50 pub(crate) fn take_ptr(mut self) -> *mut nativeChannelMonitorUpdate {
51 assert!(self.is_owned);
53 self.inner = std::ptr::null_mut();
57 impl Clone for ChannelMonitorUpdate {
58 fn clone(&self) -> Self {
60 inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
66 /// Used only if an object of this type is returned as a trait impl by a method
67 pub(crate) extern "C" fn ChannelMonitorUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
68 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelMonitorUpdate)).clone() })) as *mut c_void
70 /// The sequence number of this update. Updates *must* be replayed in-order according to this
71 /// sequence number (and updates may panic if they are not). The update_id values are strictly
72 /// increasing and increase by one for each new update.
74 /// This sequence number is also used to track up to which points updates which returned
75 /// ChannelMonitorUpdateErr::TemporaryFailure have been applied to all copies of a given
76 /// ChannelMonitor when ChannelManager::channel_monitor_updated is called.
78 pub extern "C" fn ChannelMonitorUpdate_get_update_id(this_ptr: &ChannelMonitorUpdate) -> u64 {
79 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.update_id;
82 /// The sequence number of this update. Updates *must* be replayed in-order according to this
83 /// sequence number (and updates may panic if they are not). The update_id values are strictly
84 /// increasing and increase by one for each new update.
86 /// This sequence number is also used to track up to which points updates which returned
87 /// ChannelMonitorUpdateErr::TemporaryFailure have been applied to all copies of a given
88 /// ChannelMonitor when ChannelManager::channel_monitor_updated is called.
90 pub extern "C" fn ChannelMonitorUpdate_set_update_id(this_ptr: &mut ChannelMonitorUpdate, mut val: u64) {
91 unsafe { &mut *this_ptr.inner }.update_id = val;
94 pub extern "C" fn ChannelMonitorUpdate_write(obj: *const ChannelMonitorUpdate) -> crate::c_types::derived::CVec_u8Z {
95 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
98 pub extern "C" fn ChannelMonitorUpdate_read(ser: crate::c_types::u8slice) -> ChannelMonitorUpdate {
99 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
100 ChannelMonitorUpdate { inner: Box::into_raw(Box::new(res)), is_owned: true }
102 ChannelMonitorUpdate { inner: std::ptr::null_mut(), is_owned: true }
105 /// An error enum representing a failure to persist a channel monitor update.
109 pub enum ChannelMonitorUpdateErr {
110 /// Used to indicate a temporary failure (eg connection to a watchtower or remote backup of
111 /// our state failed, but is expected to succeed at some point in the future).
113 /// Such a failure will \"freeze\" a channel, preventing us from revoking old states or
114 /// submitting new commitment transactions to the remote party. Once the update(s) which failed
115 /// have been successfully applied, ChannelManager::channel_monitor_updated can be used to
116 /// restore the channel to an operational state.
118 /// Note that a given ChannelManager will *never* re-generate a given ChannelMonitorUpdate. If
119 /// you return a TemporaryFailure you must ensure that it is written to disk safely before
120 /// writing out the latest ChannelManager state.
122 /// Even when a channel has been \"frozen\" updates to the ChannelMonitor can continue to occur
123 /// (eg if an inbound HTLC which we forwarded was claimed upstream resulting in us attempting
124 /// to claim it on this channel) and those updates must be applied wherever they can be. At
125 /// least one such updated ChannelMonitor must be persisted otherwise PermanentFailure should
126 /// be returned to get things on-chain ASAP using only the in-memory copy. Obviously updates to
127 /// the channel which would invalidate previous ChannelMonitors are not made when a channel has
130 /// Note that even if updates made after TemporaryFailure succeed you must still call
131 /// channel_monitor_updated to ensure you have the latest monitor and re-enable normal channel
134 /// Note that the update being processed here will not be replayed for you when you call
135 /// ChannelManager::channel_monitor_updated, so you must store the update itself along
136 /// with the persisted ChannelMonitor on your own local disk prior to returning a
137 /// TemporaryFailure. You may, of course, employ a journaling approach, storing only the
138 /// ChannelMonitorUpdate on disk without updating the monitor itself, replaying the journal at
141 /// For deployments where a copy of ChannelMonitors and other local state are backed up in a
142 /// remote location (with local copies persisted immediately), it is anticipated that all
143 /// updates will return TemporaryFailure until the remote copies could be updated.
145 /// Used to indicate no further channel monitor updates will be allowed (eg we've moved on to a
146 /// different watchtower and cannot update with all watchtowers that were previously informed
147 /// of this channel). This will force-close the channel in question (which will generate one
148 /// final ChannelMonitorUpdate which must be delivered to at least one ChannelMonitor copy).
150 /// Should also be used to indicate a failure to update the local persisted copy of the channel
154 use lightning::ln::channelmonitor::ChannelMonitorUpdateErr as nativeChannelMonitorUpdateErr;
155 impl ChannelMonitorUpdateErr {
157 pub(crate) fn to_native(&self) -> nativeChannelMonitorUpdateErr {
159 ChannelMonitorUpdateErr::TemporaryFailure => nativeChannelMonitorUpdateErr::TemporaryFailure,
160 ChannelMonitorUpdateErr::PermanentFailure => nativeChannelMonitorUpdateErr::PermanentFailure,
164 pub(crate) fn into_native(self) -> nativeChannelMonitorUpdateErr {
166 ChannelMonitorUpdateErr::TemporaryFailure => nativeChannelMonitorUpdateErr::TemporaryFailure,
167 ChannelMonitorUpdateErr::PermanentFailure => nativeChannelMonitorUpdateErr::PermanentFailure,
171 pub(crate) fn from_native(native: &nativeChannelMonitorUpdateErr) -> Self {
173 nativeChannelMonitorUpdateErr::TemporaryFailure => ChannelMonitorUpdateErr::TemporaryFailure,
174 nativeChannelMonitorUpdateErr::PermanentFailure => ChannelMonitorUpdateErr::PermanentFailure,
178 pub(crate) fn native_into(native: nativeChannelMonitorUpdateErr) -> Self {
180 nativeChannelMonitorUpdateErr::TemporaryFailure => ChannelMonitorUpdateErr::TemporaryFailure,
181 nativeChannelMonitorUpdateErr::PermanentFailure => ChannelMonitorUpdateErr::PermanentFailure,
186 use lightning::ln::channelmonitor::MonitorUpdateError as nativeMonitorUpdateErrorImport;
187 type nativeMonitorUpdateError = nativeMonitorUpdateErrorImport;
189 /// General Err type for ChannelMonitor actions. Generally, this implies that the data provided is
190 /// inconsistent with the ChannelMonitor being called. eg for ChannelMonitor::update_monitor this
191 /// means you tried to update a monitor for a different channel or the ChannelMonitorUpdate was
193 /// Contains a human-readable error message.
196 pub struct MonitorUpdateError {
197 /// Nearly everyhwere, inner must be non-null, however in places where
198 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
199 pub inner: *mut nativeMonitorUpdateError,
203 impl Drop for MonitorUpdateError {
205 if self.is_owned && !self.inner.is_null() {
206 let _ = unsafe { Box::from_raw(self.inner) };
211 pub extern "C" fn MonitorUpdateError_free(this_ptr: MonitorUpdateError) { }
213 /// Used only if an object of this type is returned as a trait impl by a method
214 extern "C" fn MonitorUpdateError_free_void(this_ptr: *mut c_void) {
215 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMonitorUpdateError); }
218 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
219 impl MonitorUpdateError {
220 pub(crate) fn take_ptr(mut self) -> *mut nativeMonitorUpdateError {
221 assert!(self.is_owned);
222 let ret = self.inner;
223 self.inner = std::ptr::null_mut();
228 use lightning::ln::channelmonitor::MonitorEvent as nativeMonitorEventImport;
229 type nativeMonitorEvent = nativeMonitorEventImport;
231 /// An event to be processed by the ChannelManager.
234 pub struct MonitorEvent {
235 /// Nearly everyhwere, inner must be non-null, however in places where
236 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
237 pub inner: *mut nativeMonitorEvent,
241 impl Drop for MonitorEvent {
243 if self.is_owned && !self.inner.is_null() {
244 let _ = unsafe { Box::from_raw(self.inner) };
249 pub extern "C" fn MonitorEvent_free(this_ptr: MonitorEvent) { }
251 /// Used only if an object of this type is returned as a trait impl by a method
252 extern "C" fn MonitorEvent_free_void(this_ptr: *mut c_void) {
253 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMonitorEvent); }
256 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
258 pub(crate) fn take_ptr(mut self) -> *mut nativeMonitorEvent {
259 assert!(self.is_owned);
260 let ret = self.inner;
261 self.inner = std::ptr::null_mut();
266 use lightning::ln::channelmonitor::HTLCUpdate as nativeHTLCUpdateImport;
267 type nativeHTLCUpdate = nativeHTLCUpdateImport;
269 /// Simple structure send back by ManyChannelMonitor in case of HTLC detected onchain from a
270 /// forward channel and from which info are needed to update HTLC in a backward channel.
273 pub struct HTLCUpdate {
274 /// Nearly everyhwere, inner must be non-null, however in places where
275 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
276 pub inner: *mut nativeHTLCUpdate,
280 impl Drop for HTLCUpdate {
282 if self.is_owned && !self.inner.is_null() {
283 let _ = unsafe { Box::from_raw(self.inner) };
288 pub extern "C" fn HTLCUpdate_free(this_ptr: HTLCUpdate) { }
290 /// Used only if an object of this type is returned as a trait impl by a method
291 extern "C" fn HTLCUpdate_free_void(this_ptr: *mut c_void) {
292 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHTLCUpdate); }
295 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
297 pub(crate) fn take_ptr(mut self) -> *mut nativeHTLCUpdate {
298 assert!(self.is_owned);
299 let ret = self.inner;
300 self.inner = std::ptr::null_mut();
304 impl Clone for HTLCUpdate {
305 fn clone(&self) -> Self {
307 inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
313 /// Used only if an object of this type is returned as a trait impl by a method
314 pub(crate) extern "C" fn HTLCUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
315 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCUpdate)).clone() })) as *mut c_void
318 pub extern "C" fn HTLCUpdate_write(obj: *const HTLCUpdate) -> crate::c_types::derived::CVec_u8Z {
319 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
322 pub extern "C" fn HTLCUpdate_read(ser: crate::c_types::u8slice) -> HTLCUpdate {
323 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
324 HTLCUpdate { inner: Box::into_raw(Box::new(res)), is_owned: true }
326 HTLCUpdate { inner: std::ptr::null_mut(), is_owned: true }
330 use lightning::ln::channelmonitor::ChannelMonitor as nativeChannelMonitorImport;
331 type nativeChannelMonitor = nativeChannelMonitorImport<crate::chain::keysinterface::ChannelKeys>;
333 /// A ChannelMonitor handles chain events (blocks connected and disconnected) and generates
334 /// on-chain transactions to ensure no loss of funds occurs.
336 /// You MUST ensure that no ChannelMonitors for a given channel anywhere contain out-of-date
337 /// information and are actively monitoring the chain.
339 /// Pending Events or updated HTLCs which have not yet been read out by
340 /// get_and_clear_pending_monitor_events or get_and_clear_pending_events are serialized to disk and
341 /// reloaded at deserialize-time. Thus, you must ensure that, when handling events, all events
342 /// gotten are fully handled before re-serializing the new state.
345 pub struct ChannelMonitor {
346 /// Nearly everyhwere, inner must be non-null, however in places where
347 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
348 pub inner: *mut nativeChannelMonitor,
352 impl Drop for ChannelMonitor {
354 if self.is_owned && !self.inner.is_null() {
355 let _ = unsafe { Box::from_raw(self.inner) };
360 pub extern "C" fn ChannelMonitor_free(this_ptr: ChannelMonitor) { }
362 /// Used only if an object of this type is returned as a trait impl by a method
363 extern "C" fn ChannelMonitor_free_void(this_ptr: *mut c_void) {
364 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelMonitor); }
367 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
368 impl ChannelMonitor {
369 pub(crate) fn take_ptr(mut self) -> *mut nativeChannelMonitor {
370 assert!(self.is_owned);
371 let ret = self.inner;
372 self.inner = std::ptr::null_mut();
376 /// Simple trait indicating ability to track a set of ChannelMonitors and multiplex events between
377 /// them. Generally should be implemented by keeping a local SimpleManyChannelMonitor and passing
378 /// events to it, while also taking any add/update_monitor events and passing them to some remote
381 /// In general, you must always have at least one local copy in memory, which must never fail to
382 /// update (as it is responsible for broadcasting the latest state in case the channel is closed),
383 /// and then persist it to various on-disk locations. If, for some reason, the in-memory copy fails
384 /// to update (eg out-of-memory or some other condition), you must immediately shut down without
385 /// taking any further action such as writing the current state to disk. This should likely be
386 /// accomplished via panic!() or abort().
388 /// Note that any updates to a channel's monitor *must* be applied to each instance of the
389 /// channel's monitor everywhere (including remote watchtowers) *before* this function returns. If
390 /// an update occurs and a remote watchtower is left with old state, it may broadcast transactions
391 /// which we have revoked, allowing our counterparty to claim all funds in the channel!
393 /// User needs to notify implementors of ManyChannelMonitor when a new block is connected or
394 /// disconnected using their `block_connected` and `block_disconnected` methods. However, rather
395 /// than calling these methods directly, the user should register implementors as listeners to the
396 /// BlockNotifier and call the BlockNotifier's `block_(dis)connected` methods, which will notify
397 /// all registered listeners in one go.
399 pub struct ManyChannelMonitor {
400 pub this_arg: *mut c_void,
401 /// Adds a monitor for the given `funding_txo`.
403 /// Implementer must also ensure that the funding_txo txid *and* outpoint are registered with
404 /// any relevant ChainWatchInterfaces such that the provided monitor receives block_connected
405 /// callbacks with the funding transaction, or any spends of it.
407 /// Further, the implementer must also ensure that each output returned in
408 /// monitor.get_outputs_to_watch() is registered to ensure that the provided monitor learns about
409 /// any spends of any of the outputs.
411 /// Any spends of outputs which should have been registered which aren't passed to
412 /// ChannelMonitors via block_connected may result in FUNDS LOSS.
414 pub add_monitor: extern "C" fn (this_arg: *const c_void, funding_txo: crate::chain::transaction::OutPoint, monitor: crate::ln::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ,
415 /// Updates a monitor for the given `funding_txo`.
417 /// Implementer must also ensure that the funding_txo txid *and* outpoint are registered with
418 /// any relevant ChainWatchInterfaces such that the provided monitor receives block_connected
419 /// callbacks with the funding transaction, or any spends of it.
421 /// Further, the implementer must also ensure that each output returned in
422 /// monitor.get_watch_outputs() is registered to ensure that the provided monitor learns about
423 /// any spends of any of the outputs.
425 /// Any spends of outputs which should have been registered which aren't passed to
426 /// ChannelMonitors via block_connected may result in FUNDS LOSS.
428 pub update_monitor: extern "C" fn (this_arg: *const c_void, funding_txo: crate::chain::transaction::OutPoint, monitor: crate::ln::channelmonitor::ChannelMonitorUpdate) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ,
429 /// Used by ChannelManager to get list of HTLC resolved onchain and which needed to be updated
430 /// with success or failure.
432 /// You should probably just call through to
433 /// ChannelMonitor::get_and_clear_pending_monitor_events() for each ChannelMonitor and return
436 pub get_and_clear_pending_monitor_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MonitorEventZ,
437 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
439 unsafe impl Send for ManyChannelMonitor {}
440 unsafe impl Sync for ManyChannelMonitor {}
442 use lightning::ln::channelmonitor::ManyChannelMonitor as rustManyChannelMonitor;
443 impl rustManyChannelMonitor for ManyChannelMonitor {
444 type Keys = crate::chain::keysinterface::ChannelKeys;
445 fn add_monitor(&self, funding_txo: lightning::chain::transaction::OutPoint, monitor: lightning::ln::channelmonitor::ChannelMonitor<Self::Keys>) -> Result<(), lightning::ln::channelmonitor::ChannelMonitorUpdateErr> {
446 let mut ret = (self.add_monitor)(self.this_arg, crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(funding_txo)), is_owned: true }, crate::ln::channelmonitor::ChannelMonitor { inner: Box::into_raw(Box::new(monitor)), is_owned: true });
447 let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(ret.contents.result.take_ptr()) })*/ }), false => Err( { (*unsafe { Box::from_raw(ret.contents.err.take_ptr()) }).into_native() })};
450 fn update_monitor(&self, funding_txo: lightning::chain::transaction::OutPoint, monitor: lightning::ln::channelmonitor::ChannelMonitorUpdate) -> Result<(), lightning::ln::channelmonitor::ChannelMonitorUpdateErr> {
451 let mut ret = (self.update_monitor)(self.this_arg, crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(funding_txo)), is_owned: true }, crate::ln::channelmonitor::ChannelMonitorUpdate { inner: Box::into_raw(Box::new(monitor)), is_owned: true });
452 let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(ret.contents.result.take_ptr()) })*/ }), false => Err( { (*unsafe { Box::from_raw(ret.contents.err.take_ptr()) }).into_native() })};
455 fn get_and_clear_pending_monitor_events(&self) -> Vec<lightning::ln::channelmonitor::MonitorEvent> {
456 let mut ret = (self.get_and_clear_pending_monitor_events)(self.this_arg);
457 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { *unsafe { Box::from_raw(item.take_ptr()) } }); };
462 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
463 // directly as a Deref trait in higher-level structs:
464 impl std::ops::Deref for ManyChannelMonitor {
466 fn deref(&self) -> &Self {
470 /// Calls the free function if one is set
472 pub extern "C" fn ManyChannelMonitor_free(this_ptr: ManyChannelMonitor) { }
473 impl Drop for ManyChannelMonitor {
475 if let Some(f) = self.free {
480 /// Updates a ChannelMonitor on the basis of some new information provided by the Channel
483 /// panics if the given update is not the next update by update_id.
486 pub extern "C" fn ChannelMonitor_update_monitor(this_arg: &mut ChannelMonitor, mut updates: crate::ln::channelmonitor::ChannelMonitorUpdate, broadcaster: &crate::chain::chaininterface::BroadcasterInterface, logger: &crate::util::logger::Logger) -> crate::c_types::derived::CResult_NoneMonitorUpdateErrorZ {
487 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeChannelMonitor)) }.update_monitor(*unsafe { Box::from_raw(updates.take_ptr()) }, broadcaster, logger);
488 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::channelmonitor::MonitorUpdateError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) };
492 /// Gets the update_id from the latest ChannelMonitorUpdate which was applied to this
496 pub extern "C" fn ChannelMonitor_get_latest_update_id(this_arg: &ChannelMonitor) -> u64 {
497 let mut ret = unsafe { &*this_arg.inner }.get_latest_update_id();
501 /// Gets the funding transaction outpoint of the channel this ChannelMonitor is monitoring for.
504 pub extern "C" fn ChannelMonitor_get_funding_txo(this_arg: &ChannelMonitor) -> crate::c_types::derived::C2Tuple_OutPointScriptZ {
505 let mut ret = unsafe { &*this_arg.inner }.get_funding_txo();
506 let (ref orig_ret_0, ref orig_ret_1) = ret; let mut local_ret = (crate::chain::transaction::OutPoint { inner: unsafe { ( (&(*orig_ret_0) as *const _) as *mut _) }, is_owned: false }, orig_ret_1.clone().into_bytes().into()).into();
510 /// Get the list of HTLCs who's status has been updated on chain. This should be called by
511 /// ChannelManager via ManyChannelMonitor::get_and_clear_pending_monitor_events().
514 pub extern "C" fn ChannelMonitor_get_and_clear_pending_monitor_events(this_arg: &mut ChannelMonitor) -> crate::c_types::derived::CVec_MonitorEventZ {
515 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeChannelMonitor)) }.get_and_clear_pending_monitor_events();
516 let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { crate::ln::channelmonitor::MonitorEvent { inner: Box::into_raw(Box::new(item)), is_owned: true } }); };
520 /// Gets the list of pending events which were generated by previous actions, clearing the list
523 /// This is called by ManyChannelMonitor::get_and_clear_pending_events() and is equivalent to
524 /// EventsProvider::get_and_clear_pending_events() except that it requires &mut self as we do
525 /// no internal locking in ChannelMonitors.
528 pub extern "C" fn ChannelMonitor_get_and_clear_pending_events(this_arg: &mut ChannelMonitor) -> crate::c_types::derived::CVec_EventZ {
529 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeChannelMonitor)) }.get_and_clear_pending_events();
530 let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { crate::util::events::Event::native_into(item) }); };
534 /// Used by ChannelManager deserialization to broadcast the latest local state if its copy of
535 /// the Channel was out-of-date. You may use it to get a broadcastable local toxic tx in case of
536 /// fallen-behind, i.e when receiving a channel_reestablish with a proof that our remote side knows
537 /// a higher revocation secret than the local commitment number we are aware of. Broadcasting these
538 /// transactions are UNSAFE, as they allow remote side to punish you. Nevertheless you may want to
539 /// broadcast them if remote don't close channel with his higher commitment transaction after a
540 /// substantial amount of time (a month or even a year) to get back funds. Best may be to contact
541 /// out-of-band the other node operator to coordinate with him if option is available to you.
542 /// In any-case, choice is up to the user.
545 pub extern "C" fn ChannelMonitor_get_latest_holder_commitment_txn(this_arg: &mut ChannelMonitor, logger: &crate::util::logger::Logger) -> crate::c_types::derived::CVec_TransactionZ {
546 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeChannelMonitor)) }.get_latest_holder_commitment_txn(logger);
547 let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { let mut local_ret_0 = ::bitcoin::consensus::encode::serialize(&item); local_ret_0.into() }); };