Просмотр исходного кода

store: don't store whitelist entries in greylist on stop()

Previously we had decided on forcing whitelist entries through the
refinery on each new run, by writing them to the greylist on stop.

However, this is a bad design for the following reasons:

1. It deletes the work performed by the refinery, which is valuable and
   should be preserved. The whitelist is expensive (i.e. 15s/ peer + bandwidth),
   whereas the greylist is cheap (costs nothing to create). Therefore it's
   important to retain the distinction even on stop().

2. It means that when we start a node, since we have no memory of white
   hosts, the node will always try to connect to peers from the greylist.
   Probably safe peers (white) are mixed with potentially hostile peers (grey),
   so the node will struggle to form connections and DAG sync will fail.

3. Whitelist peers will be downgraded to Greylist if we cannot connect to
    them in Outbound Session, so forcing them through the refinery is redundant.
draoi 2 лет назад
Родитель
Сommit
afde25dd1d
1 измененных файлов с 6 добавлено и 20 удалено
  1. 6 20
      src/net/hosts/store.rs

+ 6 - 20
src/net/hosts/store.rs

@@ -700,32 +700,18 @@ impl HostContainer {
         Ok(())
     }
 
-    /// Save the hostlist to a file. Whitelist gets written to the greylist
-    /// to force whitelist entries through the refinery on start.
+    /// Save the hostlist to a file.
     pub async fn save_all(&self, path: &str) -> Result<()> {
         let path = expand_path(path)?;
 
         let mut tsv = String::new();
-        let mut white = vec![];
-        let mut greygold: HashMap<String, Vec<(Url, u64)>> = HashMap::new();
+        let mut hostlist: HashMap<String, Vec<(Url, u64)>> = HashMap::new();
 
-        // First gather all the whitelist entries we don't have in greylist.
-        for (url, last_seen) in self.fetch_all(HostColor::White).await {
-            if !self.contains(HostColor::Grey as usize, &url).await {
-                white.push((url, last_seen))
-            }
-        }
+        hostlist.insert("gold".to_string(), self.fetch_all(HostColor::Gold).await);
+        hostlist.insert("white".to_string(), self.fetch_all(HostColor::White).await);
+        hostlist.insert("grey".to_string(), self.fetch_all(HostColor::Grey).await);
 
-        // Then gather the greylist and anchorlist entries.
-        greygold.insert("anchorlist".to_string(), self.fetch_all(HostColor::Gold).await);
-        greygold.insert("greylist".to_string(), self.fetch_all(HostColor::Grey).await);
-
-        // We write whitelist entries to the greylist on p2p.stop() to force
-        // them through the refinery on start().
-        for (name, mut list) in greygold {
-            if name == *"greylist".to_string() {
-                list.append(&mut white)
-            }
+        for (name, list) in hostlist {
             for (url, last_seen) in list {
                 tsv.push_str(&format!("{}\t{}\t{}\n", name, url, last_seen));
             }