]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Send Init message immediately after handshake even if not initiator
authorDevrandom <c1.devrandom@niftybox.net>
Wed, 28 Apr 2021 13:22:34 +0000 (15:22 +0200)
committerDevrandom <c1.devrandom@niftybox.net>
Wed, 28 Apr 2021 13:22:34 +0000 (15:22 +0200)
We were waiting for the initiator, but the spec doesn't guarantee that they will send Init first, so we might theoretically wait forever.

Also, lnprototest expects this behavior.

lightning/src/ln/peer_handler.rs

index d4eb9eae5e7910f7a0b4de52ab6591794210f8ea..2559acfc2dd5370b93d59d1cdb47a591c80a1c56 100644 (file)
@@ -233,7 +233,6 @@ enum InitSyncTracker{
 
 struct Peer {
        channel_encryptor: PeerChannelEncryptor,
-       outbound: bool,
        their_node_id: Option<PublicKey>,
        their_features: Option<InitFeatures>,
 
@@ -465,7 +464,6 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
                let mut peers = self.peers.lock().unwrap();
                if peers.peers.insert(descriptor, Peer {
                        channel_encryptor: peer_encryptor,
-                       outbound: true,
                        their_node_id: None,
                        their_features: None,
 
@@ -502,7 +500,6 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
                let mut peers = self.peers.lock().unwrap();
                if peers.peers.insert(descriptor, Peer {
                        channel_encryptor: peer_encryptor,
-                       outbound: false,
                        their_node_id: None,
                        their_features: None,
 
@@ -744,6 +741,9 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
                                                                        peer.pending_read_is_header = true;
                                                                        peer.their_node_id = Some(their_node_id);
                                                                        insert_node_id!();
+                                                                       let features = InitFeatures::known();
+                                                                       let resp = msgs::Init { features };
+                                                                       self.enqueue_message(&mut peers.peers_needing_send, peer, peer_descriptor.clone(), &resp);
                                                                },
                                                                NextNoiseStep::NoiseComplete => {
                                                                        if peer.pending_read_is_header {
@@ -854,12 +854,6 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
                                        return Err(PeerHandleError{ no_connection_possible: true }.into());
                                }
 
-                               if !peer.outbound {
-                                       let features = InitFeatures::known();
-                                       let resp = msgs::Init { features };
-                                       self.enqueue_message(peers_needing_send, peer, peer_descriptor.clone(), &resp);
-                               }
-
                                self.message_handler.route_handler.sync_routing_table(&peer.their_node_id.unwrap(), &msg);
 
                                self.message_handler.chan_handler.peer_connected(&peer.their_node_id.unwrap(), &msg);