Correctly handle sending announcement sigs on public 0conf channels
[rust-lightning] / lightning / src / ln / peer_handler.rs
index d4e6b4645b276a22da88cddfd7bc441b2a13d8b9..4b777b0b99446e0d4781e6029592b60ee0e24ff7 100644 (file)
@@ -15,7 +15,7 @@
 //! call into the provided message handlers (probably a ChannelManager and NetGraphmsgHandler) with messages
 //! they should handle, and encoding/sending response messages.
 
-use bitcoin::secp256k1::key::{SecretKey,PublicKey};
+use bitcoin::secp256k1::{SecretKey,PublicKey};
 
 use ln::features::InitFeatures;
 use ln::msgs;
@@ -258,8 +258,13 @@ pub trait SocketDescriptor : cmp::Eq + hash::Hash + Clone {
 /// descriptor.
 #[derive(Clone)]
 pub struct PeerHandleError {
-       /// Used to indicate that we probably can't make any future connections to this peer, implying
-       /// we should go ahead and force-close any channels we have with it.
+       /// Used to indicate that we probably can't make any future connections to this peer (e.g.
+       /// because we required features that our peer was missing, or vice versa).
+       ///
+       /// While LDK's [`ChannelManager`] will not do it automatically, you likely wish to force-close
+       /// any channels with this peer or check for new versions of LDK.
+       ///
+       /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
        pub no_connection_possible: bool,
 }
 impl fmt::Debug for PeerHandleError {
@@ -1833,13 +1838,13 @@ fn is_gossip_msg(type_id: u16) -> bool {
 #[cfg(test)]
 mod tests {
        use ln::peer_handler::{PeerManager, MessageHandler, SocketDescriptor, IgnoringMessageHandler, filter_addresses};
-       use ln::msgs;
+       use ln::{msgs, wire};
        use ln::msgs::NetAddress;
        use util::events;
        use util::test_utils;
 
        use bitcoin::secp256k1::Secp256k1;
-       use bitcoin::secp256k1::key::{SecretKey, PublicKey};
+       use bitcoin::secp256k1::{SecretKey, PublicKey};
 
        use prelude::*;
        use sync::{Arc, Mutex};
@@ -1946,6 +1951,48 @@ mod tests {
                assert_eq!(peers[0].peers.read().unwrap().len(), 0);
        }
 
+       #[test]
+       fn test_send_simple_msg() {
+               // Simple test which builds a network of PeerManager, connects and brings them to NoiseState::Finished and
+               // push a message from one peer to another.
+               let cfgs = create_peermgr_cfgs(2);
+               let a_chan_handler = test_utils::TestChannelMessageHandler::new();
+               let b_chan_handler = test_utils::TestChannelMessageHandler::new();
+               let mut peers = create_network(2, &cfgs);
+               let (fd_a, mut fd_b) = establish_connection(&peers[0], &peers[1]);
+               assert_eq!(peers[0].peers.read().unwrap().len(), 1);
+
+               let secp_ctx = Secp256k1::new();
+               let their_id = PublicKey::from_secret_key(&secp_ctx, &peers[1].our_node_secret);
+
+               let msg = msgs::Shutdown { channel_id: [42; 32], scriptpubkey: bitcoin::Script::new() };
+               a_chan_handler.pending_events.lock().unwrap().push(events::MessageSendEvent::SendShutdown {
+                       node_id: their_id, msg: msg.clone()
+               });
+               peers[0].message_handler.chan_handler = &a_chan_handler;
+
+               b_chan_handler.expect_receive_msg(wire::Message::Shutdown(msg));
+               peers[1].message_handler.chan_handler = &b_chan_handler;
+
+               peers[0].process_events();
+
+               let a_data = fd_a.outbound_data.lock().unwrap().split_off(0);
+               assert_eq!(peers[1].read_event(&mut fd_b, &a_data).unwrap(), false);
+       }
+
+       #[test]
+       fn test_disconnect_all_peer() {
+               // Simple test which builds a network of PeerManager, connects and brings them to NoiseState::Finished and
+               // then calls disconnect_all_peers
+               let cfgs = create_peermgr_cfgs(2);
+               let peers = create_network(2, &cfgs);
+               establish_connection(&peers[0], &peers[1]);
+               assert_eq!(peers[0].peers.read().unwrap().len(), 1);
+
+               peers[0].disconnect_all_peers();
+               assert_eq!(peers[0].peers.read().unwrap().len(), 0);
+       }
+
        #[test]
        fn test_timer_tick_occurred() {
                // Create peers, a vector of two peer managers, perform initial set up and check that peers[0] has one Peer.