Package org.ldk.structs
Class BackgroundProcessor
- java.lang.Object
-
- org.ldk.structs.BackgroundProcessor
-
public class BackgroundProcessor extends Object
`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: 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`], [`ChainMonitor::rebroadcast_pending_claims`] and [`PeerManager::timer_tick_occurred`] at the appropriate intervals. Calling [`NetworkGraph::remove_stale_channels_and_tracking`] (if a [`GossipSync`] with a [`NetworkGraph`] is provided to [`BackgroundProcessor::start`]). 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::events::Event BackgroundProcessor will immediately stop on drop. It should be stored until shutdown.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
finalize()
Result_NoneErrorZ
join()
Join `BackgroundProcessor`'s thread, returning any error that occurred while persisting [`ChannelManager`].static BackgroundProcessor
start(Persister persister, EventHandler event_handler, ChainMonitor chain_monitor, ChannelManager channel_manager, GossipSync gossip_sync, PeerManager peer_manager, Logger logger, Option_WriteableScoreZ scorer)
Start a background thread that takes care of responsibilities enumerated in the [top-level documentation].Result_NoneErrorZ
stop()
Stop `BackgroundProcessor`'s thread, returning any error that occurred while persisting [`ChannelManager`].
-
-
-
Method Detail
-
finalize
protected void finalize() throws Throwable
-
start
public static BackgroundProcessor start(Persister persister, EventHandler event_handler, ChainMonitor chain_monitor, ChannelManager channel_manager, GossipSync gossip_sync, PeerManager peer_manager, Logger logger, Option_WriteableScoreZ scorer)
Start a background thread that takes care of responsibilities enumerated in the [top-level documentation]. The thread runs indefinitely unless the object is dropped, [`stop`] is called, or [`Persister::persist_manager`] returns an error. In case of an error, the error is retrieved by calling either [`join`] or [`stop`]. # Data Persistence [`Persister::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 the `lightning-persister` crate for LDK's provided implementation. [`Persister::persist_graph`] is responsible for writing out the [`NetworkGraph`] to disk, if [`GossipSync`] is supplied. See [`NetworkGraph::write`] for writing out a [`NetworkGraph`]. See the `lightning-persister` crate for LDK's provided implementation. Typically, users should either implement [`Persister::persist_manager`] 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. [`P2PGossipSync`] if given will update the [`NetworkGraph`] based on payment failures. # Rapid Gossip Sync If rapid gossip sync is meant to run at startup, pass [`RapidGossipSync`] via `gossip_sync` to indicate that the [`BackgroundProcessor`] should not prune the [`NetworkGraph`] instance until the [`RapidGossipSync`] instance completes its first sync. [top-level documentation]: BackgroundProcessor [`join`]: Self::join [`stop`]: Self::stop [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager [`ChannelManager::write`]: lightning::ln::channelmanager::ChannelManager#impl-Writeable [`Persister::persist_manager`]: lightning::util::persist::Persister::persist_manager [`Persister::persist_graph`]: lightning::util::persist::Persister::persist_graph [`NetworkGraph`]: lightning::routing::gossip::NetworkGraph [`NetworkGraph::write`]: lightning::routing::gossip::NetworkGraph#impl-Writeable
-
join
public Result_NoneErrorZ join()
Join `BackgroundProcessor`'s thread, returning any error that occurred while persisting [`ChannelManager`]. # Panics This function panics if the background thread has panicked such as while persisting or handling events. [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
-
stop
public Result_NoneErrorZ stop()
Stop `BackgroundProcessor`'s thread, returning any error that occurred while persisting [`ChannelManager`]. # Panics This function panics if the background thread has panicked such as while persisting or handling events. [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
-
-