From c427f41379a210774a086162828729687df825d3 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Wed, 22 Mar 2023 21:16:57 +0100 Subject: [PATCH] node: Fix periodic inventory announcement 1. We were announcing inventory every 30 seconds. This is now changed to 1 hour. 2. We were using a variable to track whether our inventory has been announced to the network, but this var was set based on what we tracked, not the inventory we had. This var has been removed. --- radicle-node/src/service.rs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/radicle-node/src/service.rs b/radicle-node/src/service.rs index ee89f8ec..e7cbd0fb 100644 --- a/radicle-node/src/service.rs +++ b/radicle-node/src/service.rs @@ -56,7 +56,7 @@ pub const TARGET_OUTBOUND_PEERS: usize = 8; /// How often to run the "idle" task. pub const IDLE_INTERVAL: LocalDuration = LocalDuration::from_secs(30); /// How often to run the "announce" task. -pub const ANNOUNCE_INTERVAL: LocalDuration = LocalDuration::from_secs(30); +pub const ANNOUNCE_INTERVAL: LocalDuration = LocalDuration::from_mins(60); /// How often to run the "sync" task. pub const SYNC_INTERVAL: LocalDuration = LocalDuration::from_secs(60); /// How often to run the "prune" task. @@ -186,8 +186,6 @@ pub struct Service { reactor: Reactor, /// Source of entropy. rng: Rng, - /// Whether our local inventory no long represents what we have announced to the network. - out_of_sync: bool, /// Fetch requests initiated by user, which are waiting for results. fetch_reqs: HashMap>, /// Current tracked repository bloom filter. @@ -253,7 +251,6 @@ where gossip: Gossip::default(), reactor: Reactor::default(), sessions, - out_of_sync: false, fetch_reqs: HashMap::new(), filter: Filter::empty(), last_idle: LocalTime::default(), @@ -274,10 +271,10 @@ where /// Track a repository. /// Returns whether or not the tracking policy was updated. pub fn track_repo(&mut self, id: &Id, scope: Scope) -> Result { - self.out_of_sync = self.tracking.track_repo(id, scope)?; + let updated = self.tracking.track_repo(id, scope)?; self.filter.insert(id); - Ok(self.out_of_sync) + Ok(updated) } /// Untrack a repository. @@ -427,14 +424,12 @@ where self.last_sync = now; } if now - self.last_announce >= ANNOUNCE_INTERVAL { - if self.out_of_sync { - if let Err(err) = self - .storage - .inventory() - .and_then(|i| self.announce_inventory(i)) - { - error!(target: "service", "Error announcing inventory: {}", err); - } + if let Err(err) = self + .storage + .inventory() + .and_then(|i| self.announce_inventory(i)) + { + error!(target: "service", "Error announcing inventory: {}", err); } self.reactor.wakeup(ANNOUNCE_INTERVAL); self.last_announce = now; @@ -1148,7 +1143,7 @@ where ) } - /// Sync, and if needed, announce our local inventory. + /// Update our routing table with our local node's inventory. fn sync_inventory(&mut self) -> Result, Error> { let inventory = self.storage.inventory()?; let updated = self.sync_routing(&inventory, self.node_id(), self.time())?;