diff --git a/radicle-node/src/service.rs b/radicle-node/src/service.rs index d7c29775..4727fc21 100644 --- a/radicle-node/src/service.rs +++ b/radicle-node/src/service.rs @@ -2377,9 +2377,11 @@ where } let delta = count - self.config.limits.routing_max_size; + let nid = self.node_id(); self.db.routing_mut().prune( (*now - self.config.limits.routing_max_age).into(), Some(delta), + &nid, )?; Ok(()) } diff --git a/radicle/src/node/routing.rs b/radicle/src/node/routing.rs index c910a0b4..9973d6a8 100644 --- a/radicle/src/node/routing.rs +++ b/radicle/src/node/routing.rs @@ -64,7 +64,12 @@ pub trait Store { /// Get the total number of routing entries. fn len(&self) -> Result; /// Prune entries older than the given timestamp. - fn prune(&mut self, oldest: Timestamp, limit: Option) -> Result; + fn prune( + &mut self, + oldest: Timestamp, + limit: Option, + ignore: &NodeId, + ) -> Result; /// Count the number of routes for a specific repo RID. fn count(&self, id: &RepoId) -> Result; } @@ -210,18 +215,25 @@ impl Store for Database { Ok(count) } - fn prune(&mut self, oldest: Timestamp, limit: Option) -> Result { + fn prune( + &mut self, + oldest: Timestamp, + limit: Option, + ignore: &NodeId, + ) -> Result { let limit: i64 = limit .unwrap_or(i64::MAX as usize) .try_into() .map_err(|_| Error::UnitOverflow)?; let mut stmt = self.db.prepare( - "DELETE FROM routing WHERE rowid IN - (SELECT rowid FROM routing WHERE timestamp < ? LIMIT ?)", + "DELETE FROM routing + WHERE node <> ?1 AND rowid IN + (SELECT rowid FROM routing WHERE timestamp < ?2 ORDER BY timestamp LIMIT ?3)", )?; - stmt.bind((1, &oldest))?; - stmt.bind((2, limit))?; + stmt.bind((1, ignore))?; + stmt.bind((2, &oldest))?; + stmt.bind((3, limit))?; stmt.next()?; Ok(self.db.change_count()) @@ -479,7 +491,7 @@ mod test { .unwrap(); } - let pruned = db.prune(now.into(), None).unwrap(); + let pruned = db.prune(now.into(), None, &arbitrary::gen(1)).unwrap(); assert_eq!(pruned, ids.len() * nodes.len()); for id in &ids {