Skip to content

Commit e2f088c

Browse files
committed
Expand and format BackgroundProcessor docs
1 parent ba2c00b commit e2f088c

File tree

1 file changed

+30
-13
lines changed
  • lightning-background-processor/src

1 file changed

+30
-13
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,28 @@ use std::thread::JoinHandle;
2626
use std::time::{Duration, Instant};
2727
use 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 [`Event`]s with a user-provided [`EventHandler`].
33+
/// * Monitoring whether the [`ChannelManager`] needs to be re-persisted to disk, and if so,
3334
/// 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.
3838
///
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
4351
#[must_use = "BackgroundProcessor will immediately stop on drop. It should be stored until shutdown."]
4452
pub struct BackgroundProcessor {
4553
stop_thread: Arc<AtomicBool>,
@@ -99,21 +107,30 @@ impl BackgroundProcessor {
99107
/// `persist_manager` returns an error. In case of an error, the error is retrieved by calling
100108
/// either [`join`] or [`stop`].
101109
///
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
105111
///
106112
/// `persist_manager` is responsible for writing out the [`ChannelManager`] to disk, and/or
107113
/// uploading to one or more backup services. See [`ChannelManager::write`] for writing out a
108114
/// [`ChannelManager`]. See [`FilesystemPersister::persist_manager`] for Rust-Lightning's
109115
/// provided implementation.
110116
///
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+
///
111127
/// [top-level documentation]: Self
112128
/// [`join`]: Self::join
113129
/// [`stop`]: Self::stop
114130
/// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
115131
/// [`ChannelManager::write`]: lightning::ln::channelmanager::ChannelManager#impl-Writeable
116132
/// [`FilesystemPersister::persist_manager`]: lightning_persister::FilesystemPersister::persist_manager
133+
/// [`Event`]: lightning::util::events::Event
117134
pub fn start<
118135
Signer: 'static + Sign,
119136
CF: 'static + Deref + Send + Sync,

0 commit comments

Comments
 (0)