Skip to content

Commit 4bdc22c

Browse files
committed
fix(l1): make contact lookup and mutation cover replacement lists
KBucket::get_mut and get_contact only searched the main contact list, so any state mutation (set_disposable, ping tracking, find_node count, mark_knows_us) silently failed for contacts in the replacement list. Since iter_contacts and do_get_contact_to_initiate now return replacement contacts, this caused phantom contacts that were visible to selection but invisible to updates. Update get_contact to use get_any (main + replacements) and get_mut to search both lists, ensuring all contact state mutations work regardless of which list holds the contact.
1 parent 3430ab4 commit 4bdc22c

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

crates/networking/p2p/peer_table.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@ impl KBucket {
8686
})
8787
}
8888

89-
/// Find a mutable reference to a contact by node ID within this bucket.
89+
/// Find a mutable reference to a contact by node ID (main or replacement list).
9090
fn get_mut(&mut self, node_id: &H256) -> Option<&mut Contact> {
91-
self.contacts
91+
if let Some((_, c)) = self.contacts.iter_mut().find(|(id, _)| id == node_id) {
92+
return Some(c);
93+
}
94+
self.replacements
9295
.iter_mut()
9396
.find(|(id, _)| id == node_id)
9497
.map(|(_, c)| c)
@@ -909,10 +912,10 @@ impl PeerTableServer {
909912
bucket_index(&self.local_node_id, node_id)
910913
}
911914

912-
/// Look up a contact by node ID (O(K) within the bucket).
915+
/// Look up a contact by node ID in main or replacement list (O(K) within the bucket).
913916
fn get_contact(&self, node_id: &H256) -> Option<&Contact> {
914917
let idx = self.bucket_for(node_id)?;
915-
self.buckets[idx].get(node_id)
918+
self.buckets[idx].get_any(node_id)
916919
}
917920

918921
/// Look up a mutable reference to a contact by node ID.

0 commit comments

Comments
 (0)