Remove TestBroadcaster temporary dedup buffer
[rust-lightning] / lightning / src / ln / functional_test_utils.rs
index 25927a8ee4c8862f303b1e7e033e434f3d0365ed..a86fb527e946ee45290f92d4b468febbdd1c7940 100644 (file)
@@ -6,7 +6,7 @@ use chain::transaction::OutPoint;
 use chain::keysinterface::KeysInterface;
 use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentPreimage, PaymentHash};
 use ln::channelmonitor::{ChannelMonitor, ManyChannelMonitor};
-use ln::router::{Route, Router};
+use ln::router::{Route, Router, RouterReadArgs};
 use ln::features::InitFeatures;
 use ln::msgs;
 use ln::msgs::{ChannelMessageHandler,RoutingMessageHandler};
@@ -37,7 +37,7 @@ use std::cell::RefCell;
 use std::rc::Rc;
 use std::sync::{Arc, Mutex};
 use std::mem;
-use std::collections::{HashSet, HashMap};
+use std::collections::HashMap;
 
 pub const CHAN_CONFIRM_DEPTH: u32 = 100;
 pub fn confirm_transaction<'a, 'b: 'a>(notifier: &'a chaininterface::BlockNotifierRef<'b>, chain: &chaininterface::ChainWatchInterfaceUtil, tx: &Transaction, chan_id: u32) {
@@ -97,6 +97,36 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> {
                        assert!(self.node.get_and_clear_pending_events().is_empty());
                        assert!(self.chan_monitor.added_monitors.lock().unwrap().is_empty());
 
+                       // Check that if we serialize the Router, we can deserialize it again.
+                       {
+                               let mut w = test_utils::TestVecWriter(Vec::new());
+                               self.router.write(&mut w).unwrap();
+                               let deserialized_router = Router::read(&mut ::std::io::Cursor::new(&w.0), RouterReadArgs {
+                                       chain_monitor: Arc::clone(&self.chain_monitor) as Arc<chaininterface::ChainWatchInterface>,
+                                       logger: Arc::clone(&self.logger) as Arc<Logger>
+                               }).unwrap();
+                               let mut chan_progress = 0;
+                               loop {
+                                       let orig_announcements = self.router.get_next_channel_announcements(chan_progress, 255);
+                                       let deserialized_announcements = deserialized_router.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.router.get_next_node_announcements(node_progress.as_ref(), 255);
+                                       let deserialized_announcements = deserialized_router.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.
@@ -920,7 +950,7 @@ pub fn fail_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route:
 pub fn create_chanmon_cfgs(node_count: usize) -> Vec<TestChanMonCfg> {
        let mut chan_mon_cfgs = Vec::new();
        for _ in 0..node_count {
-               let tx_broadcaster = test_utils::TestBroadcaster{txn_broadcasted: Mutex::new(Vec::new()), broadcasted_txn: Mutex::new(HashSet::new())};
+               let tx_broadcaster = test_utils::TestBroadcaster{txn_broadcasted: Mutex::new(Vec::new())};
                let fee_estimator = test_utils::TestFeeEstimator { sat_per_kw: 253 };
                chan_mon_cfgs.push(TestChanMonCfg{ tx_broadcaster, fee_estimator });
        }