+
+ // Check that if we serialize the Router, we can deserialize it again.
+ {
+ let mut w = test_utils::TestVecWriter(Vec::new());
+ let network_graph_ser = self.net_graph_msg_handler.network_graph.read().unwrap();
+ network_graph_ser.write(&mut w).unwrap();
+ let network_graph_deser = <NetworkGraph>::read(&mut ::std::io::Cursor::new(&w.0)).unwrap();
+ assert!(network_graph_deser == *self.net_graph_msg_handler.network_graph.read().unwrap());
+ let net_graph_msg_handler = NetGraphMsgHandler::from_net_graph(
+ self.chain_monitor, self.logger, RwLock::new(network_graph_deser)
+ );
+ let mut chan_progress = 0;
+ loop {
+ let orig_announcements = self.net_graph_msg_handler.get_next_channel_announcements(chan_progress, 255);
+ let deserialized_announcements = net_graph_msg_handler.get_next_channel_announcements(chan_progress, 255);
+ assert!(orig_announcements == deserialized_announcements);
+ chan_progress = match orig_announcements.last() {
+ Some(announcement) => announcement.0.contents.short_channel_id + 1,
+ None => break,
+ };
+ }
+ let mut node_progress = None;
+ loop {
+ let orig_announcements = self.net_graph_msg_handler.get_next_node_announcements(node_progress.as_ref(), 255);
+ let deserialized_announcements = net_graph_msg_handler.get_next_node_announcements(node_progress.as_ref(), 255);
+ assert!(orig_announcements == deserialized_announcements);
+ node_progress = match orig_announcements.last() {
+ Some(announcement) => Some(announcement.contents.node_id),
+ None => break,
+ };
+ }
+ }
+
+ // Check that if we serialize and then deserialize all our channel monitors we get the
+ // same set of outputs to watch for on chain as we have now. Note that if we write
+ // tests that fully close channels and remove the monitors at some point this may break.
+ let feeest = test_utils::TestFeeEstimator { sat_per_kw: 253 };
+ let mut deserialized_monitors = Vec::new();
+ {
+ let old_monitors = self.chan_monitor.simple_monitor.monitors.lock().unwrap();
+ for (_, old_monitor) in old_monitors.iter() {
+ let mut w = test_utils::TestVecWriter(Vec::new());
+ old_monitor.write_for_disk(&mut w).unwrap();
+ let (_, deserialized_monitor) = <(BlockHash, ChannelMonitor<EnforcingChannelKeys>)>::read(
+ &mut ::std::io::Cursor::new(&w.0)).unwrap();
+ deserialized_monitors.push(deserialized_monitor);
+ }
+ }
+
+ // Before using all the new monitors to check the watch outpoints, use the full set of
+ // them to ensure we can write and reload our ChannelManager.
+ {
+ let mut channel_monitors = HashMap::new();
+ for monitor in deserialized_monitors.iter_mut() {
+ channel_monitors.insert(monitor.get_funding_txo(), monitor);
+ }
+
+ let mut w = test_utils::TestVecWriter(Vec::new());
+ self.node.write(&mut w).unwrap();
+ <(BlockHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestLogger>)>::read(&mut ::std::io::Cursor::new(w.0), ChannelManagerReadArgs {
+ default_config: UserConfig::default(),
+ keys_manager: self.keys_manager,
+ fee_estimator: &test_utils::TestFeeEstimator { sat_per_kw: 253 },
+ monitor: self.chan_monitor,
+ tx_broadcaster: self.tx_broadcaster.clone(),
+ logger: &test_utils::TestLogger::new(),
+ channel_monitors: &mut channel_monitors,
+ }).unwrap();
+ }
+
+ let chain_watch = chaininterface::ChainWatchInterfaceUtil::new(Network::Testnet);
+ let channel_monitor = test_utils::TestChannelMonitor::new(&chain_watch, self.tx_broadcaster.clone(), &self.logger, &feeest);
+ for deserialized_monitor in deserialized_monitors.drain(..) {
+ if let Err(_) = channel_monitor.add_monitor(deserialized_monitor.get_funding_txo(), deserialized_monitor) {
+ panic!();
+ }
+ }
+ if chain_watch != *self.chain_monitor {
+ panic!();
+ }