+//! Utilities that take 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. See docs for
+//! [`BackgroundProcessor`] for more details on the nitty-gritty.
+
+#![deny(broken_intra_doc_links)]
+#![deny(missing_docs)]
+#![deny(unsafe_code)]
+
#[macro_use] extern crate lightning;
use lightning::chain;
/// Start a background thread that takes care of responsibilities enumerated in the top-level
/// documentation.
///
- /// If `persist_manager` returns an error, then this thread will return said error (and `start()`
- /// will need to be called again to restart the `BackgroundProcessor`). Users should wait on
- /// [`thread_handle`]'s `join()` method to be able to tell if and when an error is returned, or
- /// implement `persist_manager` such that an error is never returned to the `BackgroundProcessor`
+ /// If `persist_manager` returns an error, then this thread will return said error (and
+ /// `start()` will need to be called again to restart the `BackgroundProcessor`). Users should
+ /// wait on [`thread_handle`]'s `join()` method to be able to tell if and when an error is
+ /// returned, or implement `persist_manager` such that an error is never returned to the
+ /// `BackgroundProcessor`
///
- /// `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.
+ /// `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.
///
- /// [`thread_handle`]: struct.BackgroundProcessor.html#structfield.thread_handle
- /// [`ChannelManager::write`]: ../lightning/ln/channelmanager/struct.ChannelManager.html#method.write
- /// [`FilesystemPersister::persist_manager`]: ../lightning_persister/struct.FilesystemPersister.html#impl
+ /// [`thread_handle`]: BackgroundProcessor::thread_handle
+ /// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
+ /// [`ChannelManager::write`]: lightning::ln::channelmanager::ChannelManager#impl-Writeable
+ /// [`FilesystemPersister::persist_manager`]: lightning_persister::FilesystemPersister::persist_manager
pub fn start<PM, Signer, M, T, K, F, L>(persist_manager: PM, manager: Arc<ChannelManager<Signer, Arc<M>, Arc<T>, Arc<K>, Arc<F>, Arc<L>>>, logger: Arc<L>) -> Self
where Signer: 'static + Sign,
- M: 'static + chain::Watch<ChanSigner=Signer>,
+ M: 'static + chain::Watch<Signer>,
T: 'static + BroadcasterInterface,
K: 'static + KeysInterface<Signer=Signer>,
F: 'static + FeeEstimator,
let handle = thread::spawn(move || -> Result<(), std::io::Error> {
let mut current_time = Instant::now();
loop {
- let updates_available = manager.wait_timeout(Duration::from_millis(100));
+ let updates_available = manager.await_persistable_update_timeout(Duration::from_millis(100));
if updates_available {
persist_manager(&*manager)?;
}
use lightning::chain::keysinterface::{Sign, InMemorySigner, KeysInterface, KeysManager};
use lightning::chain::transaction::OutPoint;
use lightning::get_event_msg;
- use lightning::ln::channelmanager::{ChannelManager, SimpleArcChannelManager};
+ use lightning::ln::channelmanager::{ChainParameters, ChannelManager, SimpleArcChannelManager};
use lightning::ln::features::InitFeatures;
use lightning::ln::msgs::ChannelMessageHandler;
use lightning::util::config::UserConfig;
type ChainMonitor = chainmonitor::ChainMonitor<InMemorySigner, Arc<test_utils::TestChainSource>, Arc<test_utils::TestBroadcaster>, Arc<test_utils::TestFeeEstimator>, Arc<test_utils::TestLogger>, Arc<FilesystemPersister>>;
struct Node {
- node: SimpleArcChannelManager<ChainMonitor, test_utils::TestBroadcaster, test_utils::TestFeeEstimator, test_utils::TestLogger>,
+ node: Arc<SimpleArcChannelManager<ChainMonitor, test_utils::TestBroadcaster, test_utils::TestFeeEstimator, test_utils::TestLogger>>,
persister: Arc<FilesystemPersister>,
logger: Arc<test_utils::TestLogger>,
}
let persister = Arc::new(FilesystemPersister::new(format!("{}_persister_{}", persist_dir, i)));
let seed = [i as u8; 32];
let network = Network::Testnet;
- let now = Duration::from_secs(genesis_block(network).header.time as u64);
+ let genesis_block = genesis_block(network);
+ let now = Duration::from_secs(genesis_block.header.time as u64);
let keys_manager = Arc::new(KeysManager::new(&seed, now.as_secs(), now.subsec_nanos()));
let chain_monitor = Arc::new(chainmonitor::ChainMonitor::new(Some(chain_source.clone()), tx_broadcaster.clone(), logger.clone(), fee_estimator.clone(), persister.clone()));
- let manager = Arc::new(ChannelManager::new(Network::Testnet, fee_estimator.clone(), chain_monitor.clone(), tx_broadcaster, logger.clone(), keys_manager.clone(), UserConfig::default(), i));
+ let params = ChainParameters {
+ network,
+ latest_hash: genesis_block.block_hash(),
+ latest_height: 0,
+ };
+ let manager = Arc::new(ChannelManager::new(fee_estimator.clone(), chain_monitor.clone(), tx_broadcaster, logger.clone(), keys_manager.clone(), UserConfig::default(), params));
let node = Node { node: manager, persister, logger };
nodes.push(node);
}
loop {
let log_entries = nodes[0].logger.lines.lock().unwrap();
let desired_log = "Calling manager's timer_chan_freshness_every_min".to_string();
- if log_entries.get(&("background_processor".to_string(), desired_log)).is_some() {
+ if log_entries.get(&("lightning_background_processor".to_string(), desired_log)).is_some() {
break
}
}
// Test that if we encounter an error during manager persistence, the thread panics.
fn persist_manager<Signer, M, T, K, F, L>(_data: &ChannelManager<Signer, Arc<M>, Arc<T>, Arc<K>, Arc<F>, Arc<L>>) -> Result<(), std::io::Error>
where Signer: 'static + Sign,
- M: 'static + chain::Watch<ChanSigner=Signer>,
+ M: 'static + chain::Watch<Signer>,
T: 'static + BroadcasterInterface,
K: 'static + KeysInterface<Signer=Signer>,
F: 'static + FeeEstimator,