node: Fix node announcements not being received

Since node announcements are stored and retrieved from disk (due to the
PoW), the timestamp on it is never updated. This means it can be too old
to cache and not sent/received by nodes. Fix this by having a max age.
This commit is contained in:
cloudhead 2023-12-13 14:37:04 +01:00
parent 9ada30255b
commit 99aeae19ea
No known key found for this signature in database
1 changed files with 12 additions and 0 deletions

View File

@ -155,6 +155,18 @@ impl Runtime {
let announcement = if let Some(ann) = fs::read(node_dir.join(node::NODE_ANNOUNCEMENT_FILE))
.ok()
.and_then(|ann| NodeAnnouncement::decode(&mut ann.as_slice()).ok())
.and_then(|ann| {
// If our announcement was made some time ago, the timestamp on it will be old,
// and it might not get gossiped to new nodes since it will be purged from caches.
// Therefore, we make sure it's never too old.
if clock.as_millis() - ann.timestamp
<= config.limits.gossip_max_age.as_millis() as u64
{
Some(ann)
} else {
None
}
})
.and_then(|ann| {
if config.features() == ann.features
&& config.alias == ann.alias