node: Always try to relay node announcements

They are cached and will often be old. They should still be relayed.
This commit is contained in:
cloudhead 2024-04-29 12:28:30 +02:00
parent 97b1a5de53
commit a815640a3b
No known key found for this signature in database
2 changed files with 11 additions and 4 deletions

View File

@ -1338,11 +1338,14 @@ where
let now = self.clock; let now = self.clock;
let timestamp = message.timestamp(); let timestamp = message.timestamp();
// To avoid spamming peers on startup with historical gossip messages, // To avoid spamming peers on startup with historical gossip messages,
// don't relay messages that are too old. // don't relay messages that are too old. We make an exception for node announcements,
let relay = if now - timestamp.to_local_time() > MAX_TIME_DELTA { // since they are cached, and will hence often carry old timestamps.
false let relay = if message.is_node_announcement()
} else { || now - timestamp.to_local_time() <= MAX_TIME_DELTA
{
self.config.relay self.config.relay
} else {
false
}; };
// Don't allow messages from too far in the future. // Don't allow messages from too far in the future.

View File

@ -274,6 +274,10 @@ impl AnnouncementMessage {
Self::Node(NodeAnnouncement { timestamp, .. }) => *timestamp, Self::Node(NodeAnnouncement { timestamp, .. }) => *timestamp,
} }
} }
pub fn is_node_announcement(&self) -> bool {
matches!(self, Self::Node(_))
}
} }
impl From<NodeAnnouncement> for AnnouncementMessage { impl From<NodeAnnouncement> for AnnouncementMessage {