From b0e79fd4a5afa4f8c503377b6c7b7f8e093c8698 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 16 Feb 2023 19:16:53 +0100 Subject: [PATCH] perf(disc): only remove node from table if its bucket is half full (#1412) --- crates/net/discv4/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/net/discv4/src/lib.rs b/crates/net/discv4/src/lib.rs index 39eef9cc93..2a0dc7eb6f 100644 --- a/crates/net/discv4/src/lib.rs +++ b/crates/net/discv4/src/lib.rs @@ -1255,7 +1255,16 @@ impl Discv4Service { _ => continue, }; + // if the node failed to respond anything useful multiple times, remove the node from + // the table, but only if there are enough other nodes in the bucket (bucket must be at + // least half full) if failures > (self.config.max_find_node_failures as usize) { + if let Some(bucket) = self.kbuckets.get_bucket(&key) { + if bucket.num_entries() < MAX_NODES_PER_BUCKET / 2 { + // skip half empty bucket + continue + } + } self.remove_node(node_id); } }