@@ -1151,6 +1151,77 @@ where
1151
1151
/// setups. For instance, on-chain enforcement could be moved to a separate host or have added
1152
1152
/// redundancy, possibly as a watchtower. See [`chain::Watch`] for the relevant interface.
1153
1153
///
1154
+ /// # Initialization
1155
+ ///
1156
+ /// Use [`ChannelManager::new`] with the most recent [`BlockHash`] when creating a fresh instance.
1157
+ /// Otherwise, if restarting, construct [`ChannelManagerReadArgs`] with the necessary parameters and
1158
+ /// references to any deserialized [`ChannelMonitor`]s that were previously persisted. Use this to
1159
+ /// deserialize the [`ChannelManager`] and feed it any new chain data since it was last online, as
1160
+ /// detailed in the [`ChannelManagerReadArgs`] documentation.
1161
+ ///
1162
+ /// ```
1163
+ /// use bitcoin::BlockHash;
1164
+ /// use bitcoin::network::constants::Network;
1165
+ /// use lightning::chain::BestBlock;
1166
+ /// # use lightning::chain::channelmonitor::ChannelMonitor;
1167
+ /// use lightning::ln::channelmanager::{ChainParameters, ChannelManager, ChannelManagerReadArgs};
1168
+ /// # use lightning::routing::gossip::NetworkGraph;
1169
+ /// use lightning::util::config::UserConfig;
1170
+ /// use lightning::util::ser::ReadableArgs;
1171
+ ///
1172
+ /// # fn read_channel_monitors() -> Vec<ChannelMonitor<lightning::sign::InMemorySigner>> { vec![] }
1173
+ /// # fn example<
1174
+ /// # 'a,
1175
+ /// # L: lightning::util::logger::Logger,
1176
+ /// # ES: lightning::sign::EntropySource,
1177
+ /// # S: for <'b> lightning::routing::scoring::LockableScore<'b, ScoreLookUp = SL>,
1178
+ /// # SL: lightning::routing::scoring::ScoreLookUp<ScoreParams = SP>,
1179
+ /// # SP: Sized,
1180
+ /// # R: lightning::io::Read,
1181
+ /// # >(
1182
+ /// # fee_estimator: &dyn lightning::chain::chaininterface::FeeEstimator,
1183
+ /// # chain_monitor: &dyn lightning::chain::Watch<lightning::sign::InMemorySigner>,
1184
+ /// # tx_broadcaster: &dyn lightning::chain::chaininterface::BroadcasterInterface,
1185
+ /// # router: &lightning::routing::router::DefaultRouter<&NetworkGraph<&'a L>, &'a L, &ES, &S, SP, SL>,
1186
+ /// # logger: &L,
1187
+ /// # entropy_source: &ES,
1188
+ /// # node_signer: &dyn lightning::sign::NodeSigner,
1189
+ /// # signer_provider: &dyn lightning::sign::SignerProvider<EcdsaSigner = lightning::sign::InMemorySigner>,
1190
+ /// # best_block: lightning::chain::BestBlock,
1191
+ /// # current_timestamp: u32,
1192
+ /// # mut reader: R,
1193
+ /// # ) -> Result<(), lightning::ln::msgs::DecodeError> {
1194
+ /// // Fresh start with no channels
1195
+ /// let params = ChainParameters {
1196
+ /// network: Network::Bitcoin,
1197
+ /// best_block,
1198
+ /// };
1199
+ /// let default_config = UserConfig::default();
1200
+ /// let channel_manager = ChannelManager::new(
1201
+ /// fee_estimator, chain_monitor, tx_broadcaster, router, logger, entropy_source, node_signer,
1202
+ /// signer_provider, default_config, params, current_timestamp
1203
+ /// );
1204
+ ///
1205
+ /// // Restart from deserialized data
1206
+ /// let mut channel_monitors = read_channel_monitors();
1207
+ /// let args = ChannelManagerReadArgs::new(
1208
+ /// entropy_source, node_signer, signer_provider, fee_estimator, chain_monitor, tx_broadcaster,
1209
+ /// router, logger, default_config, channel_monitors.iter_mut().collect()
1210
+ /// );
1211
+ /// let (block_hash, channel_manager) =
1212
+ /// <(BlockHash, ChannelManager<_, _, _, _, _, _, _, _>)>::read(&mut reader, args)?;
1213
+ ///
1214
+ /// // Update the ChannelManager and ChannelMonitors with the latest chain data
1215
+ /// // ...
1216
+ ///
1217
+ /// // Move the monitors to the ChannelManager's chain::Watch parameter
1218
+ /// for monitor in channel_monitors {
1219
+ /// chain_monitor.watch_channel(monitor.get_funding_txo().0, monitor);
1220
+ /// }
1221
+ /// # Ok(())
1222
+ /// # }
1223
+ /// ```
1224
+ ///
1154
1225
/// # Persistence
1155
1226
///
1156
1227
/// Implements [`Writeable`] to write out all channel state to disk. Implies [`peer_disconnected`] for
0 commit comments