From: Matt Corallo Date: Tue, 28 Feb 2023 21:28:13 +0000 (+0000) Subject: Remove peers from the `node_id_to_descriptor` even without init X-Git-Tag: v0.0.114~9^2~2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=2c15bb437eeab20cc3cfd33026546b4337933550;p=rust-lightning Remove peers from the `node_id_to_descriptor` even without init 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. --- diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index e9eaf33e8..5b5f7f827 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -1951,11 +1951,10 @@ impl { 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); }