Skip to content

Commit

Permalink
fix: bootstrap node replacement only to be carried out once
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi committed Dec 13, 2024
1 parent f64a208 commit 9f036e0
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(&peer_id);
}
}
}

Expand Down

0 comments on commit 9f036e0

Please sign in to comment.