Send channel_{announcement,update} msgs on connection, not timer
[rust-lightning] / lightning / src / ln / functional_test_utils.rs
index 39efab5fd2d92eccf73f82dc7a3f708ee2f98bf3..833bff3dca9d64594698ff9dc1914acd61d63e51 100644 (file)
@@ -894,20 +894,7 @@ pub fn create_unannounced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(nodes: &
 pub fn update_nodes_with_chan_announce<'a, 'b, 'c, 'd>(nodes: &'a Vec<Node<'b, 'c, 'd>>, a: usize, b: usize, ann: &msgs::ChannelAnnouncement, upd_1: &msgs::ChannelUpdate, upd_2: &msgs::ChannelUpdate) {
        nodes[a].node.broadcast_node_announcement([0, 0, 0], [0; 32], Vec::new());
        let a_events = nodes[a].node.get_and_clear_pending_msg_events();
-       assert!(a_events.len() >= 2);
-
-       // ann should be re-generated by broadcast_node_announcement - check that we have it.
-       let mut found_ann_1 = false;
-       for event in a_events.iter() {
-               match event {
-                       MessageSendEvent::BroadcastChannelAnnouncement { ref msg, .. } => {
-                               if msg == ann { found_ann_1 = true; }
-                       },
-                       MessageSendEvent::BroadcastNodeAnnouncement { .. } => {},
-                       _ => panic!("Unexpected event {:?}", event),
-               }
-       }
-       assert!(found_ann_1);
+       assert_eq!(a_events.len(), 1);
 
        let a_node_announcement = match a_events.last().unwrap() {
                MessageSendEvent::BroadcastNodeAnnouncement { ref msg } => {
@@ -918,20 +905,7 @@ pub fn update_nodes_with_chan_announce<'a, 'b, 'c, 'd>(nodes: &'a Vec<Node<'b, '
 
        nodes[b].node.broadcast_node_announcement([1, 1, 1], [1; 32], Vec::new());
        let b_events = nodes[b].node.get_and_clear_pending_msg_events();
-       assert!(b_events.len() >= 2);
-
-       // ann should be re-generated by broadcast_node_announcement - check that we have it.
-       let mut found_ann_2 = false;
-       for event in b_events.iter() {
-               match event {
-                       MessageSendEvent::BroadcastChannelAnnouncement { ref msg, .. } => {
-                               if msg == ann { found_ann_2 = true; }
-                       },
-                       MessageSendEvent::BroadcastNodeAnnouncement { .. } => {},
-                       _ => panic!("Unexpected event"),
-               }
-       }
-       assert!(found_ann_2);
+       assert_eq!(b_events.len(), 1);
 
        let b_node_announcement = match b_events.last().unwrap() {
                MessageSendEvent::BroadcastNodeAnnouncement { ref msg } => {
@@ -2324,15 +2298,27 @@ macro_rules! get_channel_value_stat {
 macro_rules! get_chan_reestablish_msgs {
        ($src_node: expr, $dst_node: expr) => {
                {
+                       let mut announcements = $crate::prelude::HashSet::new();
                        let mut res = Vec::with_capacity(1);
                        for msg in $src_node.node.get_and_clear_pending_msg_events() {
                                if let MessageSendEvent::SendChannelReestablish { ref node_id, ref msg } = msg {
                                        assert_eq!(*node_id, $dst_node.node.get_our_node_id());
                                        res.push(msg.clone());
+                               } else if let MessageSendEvent::SendChannelAnnouncement { ref node_id, ref msg, .. } = msg {
+                                       assert_eq!(*node_id, $dst_node.node.get_our_node_id());
+                                       announcements.insert(msg.contents.short_channel_id);
                                } else {
                                        panic!("Unexpected event")
                                }
                        }
+                       for chan in $src_node.node.list_channels() {
+                               if chan.is_public && chan.counterparty.node_id != $dst_node.node.get_our_node_id() {
+                                       if let Some(scid) = chan.short_channel_id {
+                                               assert!(announcements.remove(&scid));
+                                       }
+                               }
+                       }
+                       assert!(announcements.is_empty());
                        res
                }
        }