Skip to content

Commit 58cbb59

Browse files
committed
WIP: ChannelManager initialization docs with example
1 parent a71d8af commit 58cbb59

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

lightning/src/ln/channelmanager.rs

+61-1
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,67 @@ where
991991
///
992992
/// # Initialization
993993
///
994-
/// TODO
994+
/// Use [`ChannelManager::new`] with the most recent [`BlockHash`] when creating a fresh instance.
995+
/// Otherwise, if restarting, construct [`ChannelManagerReadArgs`] with the necessary parameters and
996+
/// references to any deserialized [`ChannelMonitor`]s that were previously persisted. Use this to
997+
/// deserialize the [`ChannelManager`] and feed it any new chain data since it was last online, as
998+
/// detailed in the [`ChannelManagerReadArgs`] documentation.
999+
///
1000+
/// ```
1001+
/// use bitcoin::BlockHash;
1002+
/// use bitcoin::network::constants::Network;
1003+
/// use lightning::chain::BestBlock;
1004+
/// # use lightning::chain::channelmonitor::ChannelMonitor;
1005+
/// use lightning::ln::channelmanager::{ChainParameters, ChannelManager, ChannelManagerReadArgs};
1006+
/// use lightning::util::config::UserConfig;
1007+
/// use lightning::util::ser::ReadableArgs;
1008+
///
1009+
/// # fn read_channel_monitors() -> Vec<ChannelMonitor<lightning::sign::InMemorySigner>> { vec![] }
1010+
/// # fn example<R: lightning::io::Read>(
1011+
/// # fee_estimator: &dyn lightning::chain::chaininterface::FeeEstimator,
1012+
/// # chain_monitor: &dyn lightning::chain::Watch<lightning::sign::InMemorySigner>,
1013+
/// # tx_broadcaster: &dyn lightning::chain::chaininterface::BroadcasterInterface,
1014+
/// # router: &dyn lightning::routing::router::Router,
1015+
/// # logger: &dyn lightning::util::logger::Logger,
1016+
/// # entropy_source: &dyn lightning::sign::EntropySource,
1017+
/// # node_signer: &dyn lightning::sign::NodeSigner,
1018+
/// # signer_provider: &dyn lightning::sign::SignerProvider<Signer = lightning::sign::InMemorySigner>,
1019+
/// # best_block: lightning::chain::BestBlock,
1020+
/// # current_timestamp: u32,
1021+
/// # mut reader: R,
1022+
/// # ) -> Result<(), lightning::ln::msgs::DecodeError> {
1023+
/// // Fresh start with no channels
1024+
/// let params = ChainParameters {
1025+
/// network: Network::Bitcoin,
1026+
/// best_block,
1027+
/// };
1028+
/// let default_config = UserConfig::default();
1029+
/// let channel_manager = ChannelManager::new(
1030+
/// fee_estimator, chain_monitor, tx_broadcaster, router, logger, entropy_source, node_signer,
1031+
/// signer_provider, default_config, params, current_timestamp
1032+
/// );
1033+
///
1034+
/// // Restart from deserialized data
1035+
/// let mut channel_monitors = read_channel_monitors();
1036+
/// let args = ChannelManagerReadArgs::new(
1037+
/// entropy_source, node_signer, signer_provider, fee_estimator, chain_monitor, tx_broadcaster,
1038+
/// router, logger, default_config, channel_monitors.iter_mut().collect()
1039+
/// );
1040+
/// let (block_hash, channel_manager) =
1041+
/// <(BlockHash, ChannelManager<_, _, _, _, _, _, _, _>)>::read(&mut reader, args)?;
1042+
///
1043+
/// // Update the ChannelManager and ChannelMonitors with the latest chain data
1044+
/// // ...
1045+
///
1046+
/// // Move the monitors to the ChannelManager's chain::Watch parameter
1047+
/// for monitor in channel_monitors {
1048+
/// chain_monitor.watch_channel(monitor.get_funding_txo().0, monitor);
1049+
/// }
1050+
/// # Ok(())
1051+
/// # }
1052+
/// ```
1053+
///
1054+
/// TODO: Consider re-writing ChannelManagerReadArgs docs and moving here.
9951055
///
9961056
/// # Operation
9971057
///

0 commit comments

Comments
 (0)