From b8695b0c8347e5500ecd78a740247748669b3814 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 12 Sep 2024 15:13:11 +0000 Subject: [PATCH 1/2] Check that we aren't reading a second message in BOLT 12 retry test `creates_and_pays_for_offer_with_retry` intends to check that we re-send a BOLT 12 `invoice_request` in response to a `message_received` call, but doesn't actually test that there were no messages in the outbound buffer after the initial send, which we do here. --- lightning/src/ln/offers_tests.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/lightning/src/ln/offers_tests.rs b/lightning/src/ln/offers_tests.rs index 3b9317e4674..dd7ce4afb29 100644 --- a/lightning/src/ln/offers_tests.rs +++ b/lightning/src/ln/offers_tests.rs @@ -1100,6 +1100,7 @@ fn creates_and_pays_for_offer_with_retry() { expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id); let _lost_onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap(); + assert!(bob.onion_messenger.next_onion_message_for_peer(alice_id).is_none()); // Simulate a scenario where the original onion_message is lost before reaching Alice. // Use handle_message_received to regenerate the message. From d156b2e30e488539e49fe014cf31ebdb17fd026a Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 12 Sep 2024 15:17:15 +0000 Subject: [PATCH 2/2] 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. --- lightning/src/ln/peer_handler.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 3c0d724ad94..6f0412ced42 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`.