Skip to content

Commit 1b33a3e

Browse files
committed
Allow gossip messages to have 1KB of uninterpreted data and relay
1 parent 8dd08bd commit 1b33a3e

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

lightning/src/routing/network_graph.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ use std::collections::btree_map::Entry as BtreeEntry;
4040
use std::ops::Deref;
4141
use bitcoin::hashes::hex::ToHex;
4242

43+
/// The maximum number of extra bytes which we do not understand in a gossip message before we will
44+
/// refuse to relay the message.
45+
const MAX_EXCESS_BYTES_FOR_RELAY: usize = 1024;
46+
4347
/// Represents the network as nodes and channels between them
4448
#[derive(PartialEq)]
4549
pub struct NetworkGraph {
@@ -139,13 +143,15 @@ macro_rules! secp_verify_sig {
139143
impl<C: Deref + Sync + Send, L: Deref + Sync + Send> RoutingMessageHandler for NetGraphMsgHandler<C, L> where C::Target: chain::Access, L::Target: Logger {
140144
fn handle_node_announcement(&self, msg: &msgs::NodeAnnouncement) -> Result<bool, LightningError> {
141145
self.network_graph.write().unwrap().update_node_from_announcement(msg, &self.secp_ctx)?;
142-
Ok(msg.contents.excess_data.is_empty() && msg.contents.excess_address_data.is_empty())
146+
Ok(msg.contents.excess_data.len() > MAX_EXCESS_BYTES_FOR_RELAY ||
147+
msg.contents.excess_address_data.len() > MAX_EXCESS_BYTES_FOR_RELAY ||
148+
msg.contents.excess_data.len() + msg.contents.excess_address_data.len() > MAX_EXCESS_BYTES_FOR_RELAY)
143149
}
144150

145151
fn handle_channel_announcement(&self, msg: &msgs::ChannelAnnouncement) -> Result<bool, LightningError> {
146152
self.network_graph.write().unwrap().update_channel_from_announcement(msg, &self.chain_access, &self.secp_ctx)?;
147153
log_trace!(self.logger, "Added channel_announcement for {}{}", msg.contents.short_channel_id, if !msg.contents.excess_data.is_empty() { " with excess uninterpreted data!" } else { "" });
148-
Ok(msg.contents.excess_data.is_empty())
154+
Ok(msg.contents.excess_data.len() > MAX_EXCESS_BYTES_FOR_RELAY)
149155
}
150156

151157
fn handle_htlc_fail_channel_update(&self, update: &msgs::HTLCFailChannelUpdate) {
@@ -164,7 +170,7 @@ impl<C: Deref + Sync + Send, L: Deref + Sync + Send> RoutingMessageHandler for N
164170

165171
fn handle_channel_update(&self, msg: &msgs::ChannelUpdate) -> Result<bool, LightningError> {
166172
self.network_graph.write().unwrap().update_channel(msg, &self.secp_ctx)?;
167-
Ok(msg.contents.excess_data.is_empty())
173+
Ok(msg.contents.excess_data.len() > MAX_EXCESS_BYTES_FOR_RELAY)
168174
}
169175

170176
fn get_next_channel_announcements(&self, starting_point: u64, batch_amount: u8) -> Vec<(ChannelAnnouncement, Option<ChannelUpdate>, Option<ChannelUpdate>)> {
@@ -680,7 +686,10 @@ impl NetworkGraph {
680686
}
681687
}
682688

683-
let should_relay = msg.excess_data.is_empty() && msg.excess_address_data.is_empty();
689+
let should_relay =
690+
msg.excess_data.len() <= MAX_EXCESS_BYTES_FOR_RELAY &&
691+
msg.excess_address_data.len() <= MAX_EXCESS_BYTES_FOR_RELAY &&
692+
msg.excess_data.len() + msg.excess_address_data.len() <= MAX_EXCESS_BYTES_FOR_RELAY;
684693
node.announcement_info = Some(NodeAnnouncementInfo {
685694
features: msg.features.clone(),
686695
last_update: msg.timestamp,
@@ -773,7 +782,8 @@ impl NetworkGraph {
773782
node_two: msg.node_id_2.clone(),
774783
two_to_one: None,
775784
capacity_sats: utxo_value,
776-
announcement_message: if msg.excess_data.is_empty() { full_msg.cloned() } else { None },
785+
announcement_message: if msg.excess_data.len() <= MAX_EXCESS_BYTES_FOR_RELAY
786+
{ full_msg.cloned() } else { None },
777787
};
778788

779789
match self.channels.entry(msg.short_channel_id) {
@@ -902,7 +912,8 @@ impl NetworkGraph {
902912
chan_was_enabled = false;
903913
}
904914

905-
let last_update_message = if msg.excess_data.is_empty() { full_msg.cloned() } else { None };
915+
let last_update_message = if msg.excess_data.len() <= MAX_EXCESS_BYTES_FOR_RELAY
916+
{ full_msg.cloned() } else { None };
906917

907918
let updated_channel_dir_info = DirectionalChannelInfo {
908919
enabled: chan_enabled,

0 commit comments

Comments
 (0)