@@ -26,20 +26,27 @@ use std::thread::JoinHandle;
2626use std:: time:: { Duration , Instant } ;
2727use std:: ops:: Deref ;
2828
29- /// BackgroundProcessor takes care of tasks that (1) need to happen periodically to keep
29+ /// ` BackgroundProcessor` takes care of tasks that (1) need to happen periodically to keep
3030/// Rust-Lightning running properly, and (2) either can or should be run in the background. Its
3131/// responsibilities are:
32- /// * Monitoring whether the ChannelManager needs to be re-persisted to disk, and if so,
32+ /// * Processing [`MessageSendEvent`]s by calling [`PeerManager::process_events`].
33+ /// * Processing [`Event`]s with a user-provided [`EventHandler`].
34+ /// * Monitoring whether the [`ChannelManager`] needs to be re-persisted to disk, and if so,
3335/// writing it to disk/backups by invoking the callback given to it at startup.
34- /// ChannelManager persistence should be done in the background.
35- /// * Calling `ChannelManager::timer_tick_occurred()` and
36- /// `PeerManager::timer_tick_occurred()` every minute (can be done in the
37- /// background).
36+ /// [`ChannelManager`] persistence should be done in the background.
37+ /// * Calling [`ChannelManager::timer_tick_occurred`] and [`PeerManager::timer_tick_occurred`]
38+ /// at the appropriate intervals.
3839///
39- /// Note that if ChannelManager persistence fails and the persisted manager becomes out-of-date,
40- /// then there is a risk of channels force-closing on startup when the manager realizes it's
41- /// outdated. However, as long as `ChannelMonitor` backups are sound, no funds besides those used
42- /// for unilateral chain closure fees are at risk.
40+ /// # Note
41+ ///
42+ /// If [`ChannelManager`] persistence fails and the persisted manager becomes out-of-date, then
43+ /// there is a risk of channels force-closing on startup when the manager realizes it's outdated.
44+ /// However, as long as [`ChannelMonitor`] backups are sound, no funds besides those used for
45+ /// unilateral chain closure fees are at risk.
46+ ///
47+ /// [`ChannelMonitor`]: lightning::chain::channelmonitor::ChannelMonitor
48+ /// [`Event`]: lightning::util::events::Event
49+ /// [`MessageSendEvent`]: lightning::util::events::MessageSendEvent
4350#[ must_use = "BackgroundProcessor will immediately stop on drop. It should be stored until shutdown." ]
4451pub struct BackgroundProcessor {
4552 stop_thread : Arc < AtomicBool > ,
@@ -99,21 +106,30 @@ impl BackgroundProcessor {
99106 /// `persist_manager` returns an error. In case of an error, the error is retrieved by calling
100107 /// either [`join`] or [`stop`].
101108 ///
102- /// Typically, users should either implement [`ChannelManagerPersister`] to never return an
103- /// error or call [`join`] and handle any error that may arise. For the latter case, the
104- /// `BackgroundProcessor` must be restarted by calling `start` again after handling the error.
109+ /// # Data Persistence
105110 ///
106111 /// `persist_manager` is responsible for writing out the [`ChannelManager`] to disk, and/or
107112 /// uploading to one or more backup services. See [`ChannelManager::write`] for writing out a
108113 /// [`ChannelManager`]. See [`FilesystemPersister::persist_manager`] for Rust-Lightning's
109114 /// provided implementation.
110115 ///
116+ /// Typically, users should either implement [`ChannelManagerPersister`] to never return an
117+ /// error or call [`join`] and handle any error that may arise. For the latter case,
118+ /// `BackgroundProcessor` must be restarted by calling `start` again after handling the error.
119+ ///
120+ /// # Event Handling
121+ ///
122+ /// `event_handler` is responsible for handling events that users should be notified of (e.g.,
123+ /// payment failed). A user's [`EventHandler`] may be decorated with other handlers to implement
124+ /// common functionality. See individual [`Event`]s for further details.
125+ ///
111126 /// [top-level documentation]: Self
112127 /// [`join`]: Self::join
113128 /// [`stop`]: Self::stop
114129 /// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
115130 /// [`ChannelManager::write`]: lightning::ln::channelmanager::ChannelManager#impl-Writeable
116131 /// [`FilesystemPersister::persist_manager`]: lightning_persister::FilesystemPersister::persist_manager
132+ /// [`Event`]: lightning::util::events::Event
117133 pub fn start <
118134 Signer : ' static + Sign ,
119135 CF : ' static + Deref + Send + Sync ,
0 commit comments