From 818ceaec4d6ae00a0f5aa0e848b59503d2475c29 Mon Sep 17 00:00:00 2001 From: lunar-mining Date: Thu, 18 Jan 2024 13:51:34 +0100 Subject: [PATCH] store: don't remove from greylist or whitelist on anchorlist upgrade because of the refinery running in the background, if we remove a peer from the white or greylist on upgrade it can create an index error in when seperate threads execute this code at the same time: refinery: upgrades node to whitelist, removes from greylist upgrade_host: upgrades node to anchorlist, removes from greylist leaving a "safe" peer on the grey or whitelist is not a problem. the only impact is that we risk selecting a peer from the whitelist that we are already connected as an anchor, but p2p checks exist to protect from this. equally, if we remove from the greylist or whitelist on upgrade_host this can happen: upgrade_host: upgrades node to anchorlist, removes from greylist protocol_addr: recv Addr do we have this node? no, add to greylist refinery: promotes to whitelist, etc the above scenario makes removing the host in this case redundant. --- src/net/hosts/store.rs | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/src/net/hosts/store.rs b/src/net/hosts/store.rs index f2d9a8e5e..59324587f 100644 --- a/src/net/hosts/store.rs +++ b/src/net/hosts/store.rs @@ -259,30 +259,9 @@ impl Hosts { None } - /// Upgrade a connection to the anchorlist and remove it from the white or greylist. - /// Called after a connection has been successfully established in Outbound and Manual - /// sessions. + /// Upgrade a connection to the anchorlist. Called after a connection has been successfully + /// established in Outbound and Manual sessions. pub async fn upgrade_host(&self, addr: &Url) { - // Remove channel from whitelist - if self.whitelist_contains(addr).await { - let index = self - .get_whitelist_index_at_addr(addr.clone()) - .await - .expect("Expected whitelist entry to exist"); - - self.whitelist_remove(addr, index).await; - } - - // Remove channel from greylist - if self.greylist_contains(addr).await { - let index = self - .get_greylist_index_at_addr(addr.clone()) - .await - .expect("Expected greylist entry to exist"); - self.greylist_remove(addr, index).await; - } - - // Add channel to anchorlist let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs(); self.anchorlist_store_or_update(&[(addr.clone(), last_seen)]).await; }