Update auto-generated bindings
[ldk-c-bindings] / lightning-c-bindings / src / lightning_background_processor.rs
index 5279e3aa3dbac22411b363a46b322fbc33f13678..c3c7ee3545abdca12332587d427771ecf1e346e8 100644 (file)
@@ -12,6 +12,7 @@
 
 use std::str::FromStr;
 use std::ffi::c_void;
+use core::convert::Infallible;
 use bitcoin::hashes::Hash;
 use crate::c_types::*;
 
@@ -19,20 +20,28 @@ use crate::c_types::*;
 use lightning_background_processor::BackgroundProcessor as nativeBackgroundProcessorImport;
 type nativeBackgroundProcessor = nativeBackgroundProcessorImport;
 
-/// BackgroundProcessor takes care of tasks that (1) need to happen periodically to keep
+/// `BackgroundProcessor` takes care of tasks that (1) need to happen periodically to keep
 /// Rust-Lightning running properly, and (2) either can or should be run in the background. Its
 /// responsibilities are:
-/// * Monitoring whether the ChannelManager needs to be re-persisted to disk, and if so,
+/// * Processing [`Event`]s with a user-provided [`EventHandler`].
+/// * Monitoring whether the [`ChannelManager`] needs to be re-persisted to disk, and if so,
 ///   writing it to disk/backups by invoking the callback given to it at startup.
-///   ChannelManager persistence should be done in the background.
-/// * Calling `ChannelManager::timer_tick_occurred()` and
-///   `PeerManager::timer_tick_occurred()` every minute (can be done in the
-///   background).
-///
-/// Note that if ChannelManager persistence fails and the persisted manager becomes out-of-date,
-/// then there is a risk of channels force-closing on startup when the manager realizes it's
-/// outdated. However, as long as `ChannelMonitor` backups are sound, no funds besides those used
-/// for unilateral chain closure fees are at risk.
+///   [`ChannelManager`] persistence should be done in the background.
+/// * Calling [`ChannelManager::timer_tick_occurred`] and [`PeerManager::timer_tick_occurred`]
+///   at the appropriate intervals.
+///
+/// It will also call [`PeerManager::process_events`] periodically though this shouldn't be relied
+/// upon as doing so may result in high latency.
+///
+/// # Note
+///
+/// If [`ChannelManager`] persistence fails and the persisted manager becomes out-of-date, then
+/// there is a risk of channels force-closing on startup when the manager realizes it's outdated.
+/// However, as long as [`ChannelMonitor`] backups are sound, no funds besides those used for
+/// unilateral chain closure fees are at risk.
+///
+/// [`ChannelMonitor`]: lightning::chain::channelmonitor::ChannelMonitor
+/// [`Event`]: lightning::util::events::Event
 ///BackgroundProcessor will immediately stop on drop. It should be stored until shutdown.
 #[must_use]
 #[repr(C)]
@@ -143,25 +152,38 @@ impl Drop for ChannelManagerPersister {
 /// `persist_manager` returns an error. In case of an error, the error is retrieved by calling
 /// either [`join`] or [`stop`].
 ///
-/// Typically, users should either implement [`ChannelManagerPersister`] to never return an
-/// error or call [`join`] and handle any error that may arise. For the latter case, the
-/// `BackgroundProcessor` must be restarted by calling `start` again after handling the error.
+/// # Data Persistence
 ///
 /// `persist_manager` is responsible for writing out the [`ChannelManager`] to disk, and/or
 /// uploading to one or more backup services. See [`ChannelManager::write`] for writing out a
 /// [`ChannelManager`]. See [`FilesystemPersister::persist_manager`] for Rust-Lightning's
 /// provided implementation.
 ///
+/// Typically, users should either implement [`ChannelManagerPersister`] to never return an
+/// error or call [`join`] and handle any error that may arise. For the latter case,
+/// `BackgroundProcessor` must be restarted by calling `start` again after handling the error.
+///
+/// # Event Handling
+///
+/// `event_handler` is responsible for handling events that users should be notified of (e.g.,
+/// payment failed). [`BackgroundProcessor`] may decorate the given [`EventHandler`] with common
+/// functionality implemented by other handlers.
+/// * [`NetGraphMsgHandler`] if given will update the [`NetworkGraph`] based on payment failures.
+///
 /// [top-level documentation]: Self
 /// [`join`]: Self::join
 /// [`stop`]: Self::stop
 /// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
 /// [`ChannelManager::write`]: lightning::ln::channelmanager::ChannelManager#impl-Writeable
 /// [`FilesystemPersister::persist_manager`]: lightning_persister::FilesystemPersister::persist_manager
+/// [`NetworkGraph`]: lightning::routing::network_graph::NetworkGraph
+///
+/// Note that net_graph_msg_handler (or a relevant inner pointer) may be NULL or all-0s to represent None
 #[must_use]
 #[no_mangle]
-pub extern "C" fn BackgroundProcessor_start(mut persister: crate::lightning_background_processor::ChannelManagerPersister, mut event_handler: crate::lightning::util::events::EventHandler, chain_monitor: &crate::lightning::chain::chainmonitor::ChainMonitor, channel_manager: &crate::lightning::ln::channelmanager::ChannelManager, peer_manager: &crate::lightning::ln::peer_handler::PeerManager, mut logger: crate::lightning::util::logger::Logger) -> BackgroundProcessor {
-       let mut ret = lightning_background_processor::BackgroundProcessor::start(persister, event_handler, chain_monitor.get_native_ref(), channel_manager.get_native_ref(), peer_manager.get_native_ref(), logger);
+pub extern "C" fn BackgroundProcessor_start(mut persister: crate::lightning_background_processor::ChannelManagerPersister, mut event_handler: crate::lightning::util::events::EventHandler, chain_monitor: &crate::lightning::chain::chainmonitor::ChainMonitor, channel_manager: &crate::lightning::ln::channelmanager::ChannelManager, mut net_graph_msg_handler: crate::lightning::routing::network_graph::NetGraphMsgHandler, peer_manager: &crate::lightning::ln::peer_handler::PeerManager, mut logger: crate::lightning::util::logger::Logger) -> BackgroundProcessor {
+       let mut local_net_graph_msg_handler = if net_graph_msg_handler.inner.is_null() { None } else { Some( { net_graph_msg_handler.get_native_ref() }) };
+       let mut ret = lightning_background_processor::BackgroundProcessor::start(persister, event_handler, chain_monitor.get_native_ref(), channel_manager.get_native_ref(), local_net_graph_msg_handler, peer_manager.get_native_ref(), logger);
        BackgroundProcessor { inner: ObjOps::heap_alloc(ret), is_owned: true }
 }