]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Remove peers from the `node_id_to_descriptor` even without init
authorMatt Corallo <git@bluematt.me>
Tue, 28 Feb 2023 21:28:13 +0000 (21:28 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 28 Feb 2023 21:40:20 +0000 (21:40 +0000)
When a peer has finished the noise handshake, but has not yet
completed the lightning `Init`-based handshake, they will be
present in the `node_id_to_descriptor` set, even though
`Peer::handshake_complete()` returns false. Thus, when we go to
disconnect such a peer, we must ensure that we remove it from the
descriptor set as well.

Failing to do so caused an `Inconsistent peers set state!` panic in
the C bindings network handler.

lightning/src/ln/peer_handler.rs

index e9eaf33e8840b021afe7fbcfc60afec3e0fa5b3d..5b5f7f827ed5ae16f13d7c412ad3c642aee9a6ca 100644 (file)
@@ -1951,11 +1951,10 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
                        },
                        Some(peer_lock) => {
                                let peer = peer_lock.lock().unwrap();
-                               if !peer.handshake_complete() { return; }
-                               debug_assert!(peer.their_node_id.is_some());
                                if let Some((node_id, _)) = peer.their_node_id {
                                        log_trace!(self.logger, "Handling disconnection of peer {}", log_pubkey!(node_id));
                                        self.node_id_to_descriptor.lock().unwrap().remove(&node_id);
+                                       if !peer.handshake_complete() { return; }
                                        self.message_handler.chan_handler.peer_disconnected(&node_id);
                                        self.message_handler.onion_message_handler.peer_disconnected(&node_id);
                                }