Skip to content

Commit

Permalink
Merge pull request #2531 from maqi/only_prune_bootstrap_once
Browse files Browse the repository at this point in the history
fix: bootstrap node replacement only to be carried out once
  • Loading branch information
jacderida authored Dec 14, 2024
2 parents f64a208 + 06de31e commit 7fc2f20
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ant-networking/src/event/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,12 @@ impl SwarmDriver {
fn remove_bootstrap_from_full(&mut self, peer_id: PeerId) {
let mut shall_removed = None;

let mut bucket_index = Some(0);

if let Some(kbucket) = self.swarm.behaviour_mut().kademlia.kbucket(peer_id) {
if kbucket.num_entries() >= K_VALUE.into() {
if let Some(peers) = self.bootstrap_peers.get(&kbucket.range().0.ilog2()) {
bucket_index = kbucket.range().0.ilog2();
if let Some(peers) = self.bootstrap_peers.get(&bucket_index) {
for peer_entry in kbucket.iter() {
if peers.contains(peer_entry.node.key.preimage()) {
shall_removed = Some(*peer_entry.node.key.preimage());
Expand All @@ -649,6 +652,13 @@ impl SwarmDriver {
if let Some(removed_peer) = entry {
self.update_on_peer_removal(*removed_peer.node.key.preimage());
}

// With the switch to using bootstrap cache, workload is distributed already.
// to avoid peers keeps being replaced by each other,
// there shall be just one time of removal to be undertaken.
if let Some(peers) = self.bootstrap_peers.get_mut(&bucket_index) {
let _ = peers.remove(&to_be_removed_bootstrap);
}
}
}

Expand Down

0 comments on commit 7fc2f20

Please sign in to comment.