mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user