Delay creating outbound ChannelMonitor until funding_signed rcpt
[rust-lightning] / lightning / src / ln / functional_test_utils.rs
index cf0dc1832d8598c3a2220d9856cfc4a8326abaf8..55f734a32af5e3e2231b888bd63a0da53f480fd5 100644 (file)
@@ -148,7 +148,7 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> {
                        {
                                let mut channel_monitors = HashMap::new();
                                for monitor in deserialized_monitors.iter_mut() {
-                                       channel_monitors.insert(monitor.get_funding_txo().unwrap(), monitor);
+                                       channel_monitors.insert(monitor.get_funding_txo(), monitor);
                                }
 
                                let mut w = test_utils::TestVecWriter(Vec::new());
@@ -167,7 +167,7 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> {
                        let chain_watch = Arc::new(chaininterface::ChainWatchInterfaceUtil::new(Network::Testnet, Arc::clone(&self.logger) as Arc<Logger>));
                        let channel_monitor = test_utils::TestChannelMonitor::new(chain_watch.clone(), self.tx_broadcaster.clone(), self.logger.clone(), &feeest);
                        for deserialized_monitor in deserialized_monitors.drain(..) {
-                               if let Err(_) = channel_monitor.add_monitor(deserialized_monitor.get_funding_txo().unwrap(), deserialized_monitor) {
+                               if let Err(_) = channel_monitor.add_monitor(deserialized_monitor.get_funding_txo(), deserialized_monitor) {
                                        panic!();
                                }
                        }
@@ -295,6 +295,16 @@ macro_rules! unwrap_send_err {
        }
 }
 
+macro_rules! check_added_monitors {
+       ($node: expr, $count: expr) => {
+               {
+                       let mut added_monitors = $node.chan_monitor.added_monitors.lock().unwrap();
+                       assert_eq!(added_monitors.len(), $count);
+                       added_monitors.clear();
+               }
+       }
+}
+
 pub fn create_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, expected_chan_value: u64, expected_user_chan_id: u64) -> ([u8; 32], Transaction, OutPoint) {
        let chan_id = *node.network_chan_count.borrow();
 
@@ -322,13 +332,8 @@ pub fn create_chan_between_nodes_with_value_init<'a, 'b, 'c>(node_a: &Node<'a, '
 
        let (temporary_channel_id, tx, funding_output) = create_funding_transaction(node_a, channel_value, 42);
 
-       {
-               node_a.node.funding_transaction_generated(&temporary_channel_id, funding_output);
-               let mut added_monitors = node_a.chan_monitor.added_monitors.lock().unwrap();
-               assert_eq!(added_monitors.len(), 1);
-               assert_eq!(added_monitors[0].0, funding_output);
-               added_monitors.clear();
-       }
+       node_a.node.funding_transaction_generated(&temporary_channel_id, funding_output);
+       check_added_monitors!(node_a, 0);
 
        node_b.node.handle_funding_created(&node_a.node.get_our_node_id(), &get_event_msg!(node_a, MessageSendEvent::SendFundingCreated, node_b.node.get_our_node_id()));
        {
@@ -620,16 +625,6 @@ impl SendEvent {
        }
 }
 
-macro_rules! check_added_monitors {
-       ($node: expr, $count: expr) => {
-               {
-                       let mut added_monitors = $node.chan_monitor.added_monitors.lock().unwrap();
-                       assert_eq!(added_monitors.len(), $count);
-                       added_monitors.clear();
-               }
-       }
-}
-
 macro_rules! commitment_signed_dance {
        ($node_a: expr, $node_b: expr, $commitment_signed: expr, $fail_backwards: expr, true /* skip last step */) => {
                {