From: Matt Corallo Date: Mon, 24 Jun 2024 20:24:36 +0000 (+0000) Subject: Reliably deliver gossip messages from our `ChannelMessageHandler` X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=1b711ed15f426ce40f1aa6be83d930a01ab530ba;p=rust-lightning Reliably deliver gossip messages from our `ChannelMessageHandler` When our `ChannelMessageHandler` creates gossip broadcast `MessageSendEvent`s, we generally want these to be reliably delivered to all our peers, even if there's not much buffer space available. Here we do this by passing an extra flag to `forward_broadcast_msg` which indicates where the message came from, then ignoring the buffer-full criteria when the flag is set. --- diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index a18f8bf85..a2919aa94 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -1600,7 +1600,7 @@ impl>, msg: &wire::Message<<::Target as wire::CustomMessageReader>::CustomMessage>, except_node: Option<&PublicKey>) { + /// Forwards a gossip `msg` to `peers` excluding node(s) that generated the gossip message and + /// excluding `except_node`. + /// + /// If the message queue for a peer is somewhat full, the message will not be forwarded to them + /// unless `allow_large_buffer` is set, in which case the message will be treated as critical + /// and delivered no matter the available buffer space. + fn forward_broadcast_msg( + &self, peers: &HashMap>, + msg: &wire::Message<<::Target as wire::CustomMessageReader>::CustomMessage>, + except_node: Option<&PublicKey>, allow_large_buffer: bool, + ) { match msg { wire::Message::ChannelAnnouncement(ref msg) => { log_gossip!(self.logger, "Sending message to all peers except {:?} or the announced channel's counterparties: {:?}", except_node, msg); @@ -1961,7 +1971,7 @@ impl { @@ -2293,14 +2306,18 @@ impl { log_debug!(self.logger, "Handling BroadcastChannelAnnouncement event in peer_handler for short channel id {}", msg.contents.short_channel_id); match self.message_handler.route_handler.handle_channel_announcement(None, &msg) { - Ok(_) | Err(LightningError { action: msgs::ErrorAction::IgnoreDuplicateGossip, .. }) => - self.forward_broadcast_msg(peers, &wire::Message::ChannelAnnouncement(msg), None), + Ok(_) | Err(LightningError { action: msgs::ErrorAction::IgnoreDuplicateGossip, .. }) => { + let forward = wire::Message::ChannelAnnouncement(msg); + self.forward_broadcast_msg(peers, &forward, None, from_chan_handler); + }, _ => {}, } if let Some(msg) = update_msg { match self.message_handler.route_handler.handle_channel_update(None, &msg) { - Ok(_) | Err(LightningError { action: msgs::ErrorAction::IgnoreDuplicateGossip, .. }) => - self.forward_broadcast_msg(peers, &wire::Message::ChannelUpdate(msg), None), + Ok(_) | Err(LightningError { action: msgs::ErrorAction::IgnoreDuplicateGossip, .. }) => { + let forward = wire::Message::ChannelUpdate(msg); + self.forward_broadcast_msg(peers, &forward, None, from_chan_handler); + }, _ => {}, } } @@ -2308,16 +2325,20 @@ impl { log_debug!(self.logger, "Handling BroadcastChannelUpdate event in peer_handler for contents {:?}", msg.contents); match self.message_handler.route_handler.handle_channel_update(None, &msg) { - Ok(_) | Err(LightningError { action: msgs::ErrorAction::IgnoreDuplicateGossip, .. }) => - self.forward_broadcast_msg(peers, &wire::Message::ChannelUpdate(msg), None), + Ok(_) | Err(LightningError { action: msgs::ErrorAction::IgnoreDuplicateGossip, .. }) => { + let forward = wire::Message::ChannelUpdate(msg); + self.forward_broadcast_msg(peers, &forward, None, from_chan_handler); + }, _ => {}, } }, MessageSendEvent::BroadcastNodeAnnouncement { msg } => { log_debug!(self.logger, "Handling BroadcastNodeAnnouncement event in peer_handler for node {}", msg.contents.node_id); match self.message_handler.route_handler.handle_node_announcement(None, &msg) { - Ok(_) | Err(LightningError { action: msgs::ErrorAction::IgnoreDuplicateGossip, .. }) => - self.forward_broadcast_msg(peers, &wire::Message::NodeAnnouncement(msg), None), + Ok(_) | Err(LightningError { action: msgs::ErrorAction::IgnoreDuplicateGossip, .. }) => { + let forward = wire::Message::NodeAnnouncement(msg); + self.forward_broadcast_msg(peers, &forward, None, from_chan_handler); + }, _ => {}, } }, @@ -2689,7 +2710,7 @@ impl