Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bootstrap node replacement only to be carried out once #2531

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading