Skip to content

Commit e9fbabc

Browse files
committed
Introduce handle_message_received in ChannelMessageHandler
- Introduce the `handle_message_received` function to manage the behavior when a message is received from any peer. - This function is used within `ChannelManager` to retry `InvoiceRequest` messages if we haven't received the corresponding invoice yet. - This change makes the offer communication more robust against sudden connection drops where the initial attempt to send the message might have failed.
1 parent 9b1e056 commit e9fbabc

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

lightning-net-tokio/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ mod tests {
658658
fn get_chain_hashes(&self) -> Option<Vec<ChainHash>> {
659659
Some(vec![ChainHash::using_genesis_block(Network::Testnet)])
660660
}
661+
fn handle_message_received(&self) {}
661662
}
662663
impl MessageSendEventsProvider for MsgHandler {
663664
fn get_and_clear_pending_msg_events(&self) -> Vec<MessageSendEvent> {

lightning/src/ln/channelmanager.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10706,6 +10706,28 @@ where
1070610706
"Dual-funded channels not supported".to_owned(),
1070710707
msg.channel_id.clone())), *counterparty_node_id);
1070810708
}
10709+
10710+
fn handle_message_received(&self) {
10711+
for (context, invoice_request) in self
10712+
.pending_outbound_payments
10713+
.release_invoice_request_awaiting_invoice()
10714+
{
10715+
match self.create_blinded_paths(context) {
10716+
Ok(reply_paths) => match self.enqueue_invoice_request(invoice_request, reply_paths) {
10717+
Ok(_) => {}
10718+
Err(_) => {
10719+
log_info!(self.logger, "Retry failed for an invoice request.");
10720+
}
10721+
},
10722+
Err(_) => {
10723+
log_info!(self.logger,
10724+
"Retry failed for an invoice request. \
10725+
Reason: router could not find a blinded path to include as the reply path",
10726+
);
10727+
}
10728+
}
10729+
}
10730+
}
1070910731
}
1071010732

1071110733
impl<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, L: Deref>

lightning/src/ln/msgs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,6 +1570,10 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider {
15701570
/// If it's `None`, then no particular network chain hash compatibility will be enforced when
15711571
/// connecting to peers.
15721572
fn get_chain_hashes(&self) -> Option<Vec<ChainHash>>;
1573+
1574+
/// Handles behavior which is triggered when any message from any peer for any handler
1575+
/// is received.
1576+
fn handle_message_received(&self);
15731577
}
15741578

15751579
/// A trait to describe an object which can receive routing messages.

lightning/src/ln/peer_handler.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ impl ChannelMessageHandler for ErroringMessageHandler {
387387
fn handle_tx_abort(&self, their_node_id: &PublicKey, msg: &msgs::TxAbort) {
388388
ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
389389
}
390+
391+
fn handle_message_received(&self) {}
390392
}
391393

392394
impl Deref for ErroringMessageHandler {
@@ -1750,6 +1752,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
17501752
log_trace!(logger, "Received message {:?} from {}", message, log_pubkey!(their_node_id));
17511753
}
17521754

1755+
self.message_handler.chan_handler.handle_message_received();
1756+
17531757
let mut should_forward = None;
17541758

17551759
match message {

lightning/src/util/test_utils.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,8 @@ impl msgs::ChannelMessageHandler for TestChannelMessageHandler {
936936
fn handle_tx_abort(&self, _their_node_id: &PublicKey, msg: &msgs::TxAbort) {
937937
self.received_msg(wire::Message::TxAbort(msg.clone()));
938938
}
939+
940+
fn handle_message_received(&self) {}
939941
}
940942

941943
impl events::MessageSendEventsProvider for TestChannelMessageHandler {

0 commit comments

Comments
 (0)