Skip to content

Commit

Permalink
Call ChannelMessageHandler::message_received without peer lock
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheBlueMatt committed Sep 30, 2024
1 parent b8695b0 commit d156b2e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lightning/src/ln/peer_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1618,14 +1618,15 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
let their_node_id = peer_lock.their_node_id.expect("We know the peer's public key by the time we receive messages").0;
let logger = WithContext::from(&self.logger, Some(their_node_id), None, None);

let unprocessed_message = self.do_handle_message_holding_peer_lock(peer_lock, message, their_node_id, &logger)?;

self.message_handler.chan_handler.message_received();

let message = match self.do_handle_message_holding_peer_lock(peer_lock, message, their_node_id, &logger)? {
Some(processed_message) => 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`.
Expand Down

0 comments on commit d156b2e

Please sign in to comment.