From: Matt Corallo Date: Thu, 12 Sep 2024 15:17:15 +0000 (+0000) Subject: Call `ChannelMessageHandler::message_received` without peer lock X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=d156b2e30e488539e49fe014cf31ebdb17fd026a;p=rust-lightning Call `ChannelMessageHandler::message_received` without peer lock While `message_received` purports to be called on every message, prior to the message, doing so on `Init` messages means we have to call `message_received` while holding the per-peer mutex, which can cause some lock contention. Instead, here, we call `message_received` after processing `Init` messages (which is probably more useful anyway - the peer isn't really "connected" until we've processed the `Init` messages), allowing us to call it unlocked. --- diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 3c0d724ad..6f0412ced 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -1618,14 +1618,15 @@ impl processed_message, - None => return Ok(None), - }; - self.do_handle_message_without_peer_lock(peer_mutex, message, their_node_id, &logger) + if let Some(message) = unprocessed_message { + self.do_handle_message_without_peer_lock(peer_mutex, message, their_node_id, &logger) + } else { + Ok(None) + } } // Conducts all message processing that requires us to hold the `peer_lock`.