@@ -26,20 +26,28 @@ use std::thread::JoinHandle;
26
26
use std:: time:: { Duration , Instant } ;
27
27
use std:: ops:: Deref ;
28
28
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
30
30
/// Rust-Lightning running properly, and (2) either can or should be run in the background. Its
31
31
/// responsibilities are:
32
- /// * Monitoring whether the ChannelManager needs to be re-persisted to disk, and if so,
32
+ /// * Processing [`Event`]s with a user-provided [`EventHandler`].
33
+ /// * Monitoring whether the [`ChannelManager`] needs to be re-persisted to disk, and if so,
33
34
/// 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).
35
+ /// [`ChannelManager`] persistence should be done in the background.
36
+ /// * Calling [`ChannelManager::timer_tick_occurred`] and [`PeerManager::timer_tick_occurred`]
37
+ /// at the appropriate intervals.
38
38
///
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.
39
+ /// It will also call [`PeerManager::process_events`] periodically though this shouldn't be relied
40
+ /// upon as doing so may result in high latency.
41
+ ///
42
+ /// # Note
43
+ ///
44
+ /// If [`ChannelManager`] persistence fails and the persisted manager becomes out-of-date, then
45
+ /// there is a risk of channels force-closing on startup when the manager realizes it's outdated.
46
+ /// However, as long as [`ChannelMonitor`] backups are sound, no funds besides those used for
47
+ /// unilateral chain closure fees are at risk.
48
+ ///
49
+ /// [`ChannelMonitor`]: lightning::chain::channelmonitor::ChannelMonitor
50
+ /// [`Event`]: lightning::util::events::Event
43
51
#[ must_use = "BackgroundProcessor will immediately stop on drop. It should be stored until shutdown." ]
44
52
pub struct BackgroundProcessor {
45
53
stop_thread : Arc < AtomicBool > ,
@@ -99,21 +107,30 @@ impl BackgroundProcessor {
99
107
/// `persist_manager` returns an error. In case of an error, the error is retrieved by calling
100
108
/// either [`join`] or [`stop`].
101
109
///
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.
110
+ /// # Data Persistence
105
111
///
106
112
/// `persist_manager` is responsible for writing out the [`ChannelManager`] to disk, and/or
107
113
/// uploading to one or more backup services. See [`ChannelManager::write`] for writing out a
108
114
/// [`ChannelManager`]. See [`FilesystemPersister::persist_manager`] for Rust-Lightning's
109
115
/// provided implementation.
110
116
///
117
+ /// Typically, users should either implement [`ChannelManagerPersister`] to never return an
118
+ /// error or call [`join`] and handle any error that may arise. For the latter case,
119
+ /// `BackgroundProcessor` must be restarted by calling `start` again after handling the error.
120
+ ///
121
+ /// # Event Handling
122
+ ///
123
+ /// `event_handler` is responsible for handling events that users should be notified of (e.g.,
124
+ /// payment failed). A user's [`EventHandler`] may be decorated with other handlers to implement
125
+ /// common functionality. See individual [`Event`]s for further details.
126
+ ///
111
127
/// [top-level documentation]: Self
112
128
/// [`join`]: Self::join
113
129
/// [`stop`]: Self::stop
114
130
/// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
115
131
/// [`ChannelManager::write`]: lightning::ln::channelmanager::ChannelManager#impl-Writeable
116
132
/// [`FilesystemPersister::persist_manager`]: lightning_persister::FilesystemPersister::persist_manager
133
+ /// [`Event`]: lightning::util::events::Event
117
134
pub fn start <
118
135
Signer : ' static + Sign ,
119
136
CF : ' static + Deref + Send + Sync ,
0 commit comments