Skip to content

Commit

Permalink
chore: dont gossip to disconnected nodes if there are no connected no…
Browse files Browse the repository at this point in the history
…des available
  • Loading branch information
njgheorghita committed Nov 27, 2023
1 parent e09953b commit e3adcda
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 39 deletions.
28 changes: 2 additions & 26 deletions portalnet/src/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn propagate_gossip_cross_thread<TContentKey: OverlayContentKey>(
) -> usize {
// Get all connected nodes from overlay routing table
let kbuckets = kbuckets.read();
let mut all_nodes: Vec<&kbucket::Node<NodeId, Node>> = kbuckets
let all_nodes: Vec<&kbucket::Node<NodeId, Node>> = kbuckets
.buckets_iter()
.flat_map(|kbucket| {
kbucket
Expand All @@ -52,18 +52,6 @@ pub fn propagate_gossip_cross_thread<TContentKey: OverlayContentKey>(
})
.collect();

if all_nodes.is_empty() {
warn!("No connected nodes, using disconnected nodes for gossip.");
all_nodes = kbuckets
.buckets_iter()
.flat_map(|kbucket| {
kbucket
.iter()
.collect::<Vec<&kbucket::Node<NodeId, Node>>>()
})
.collect();
}

if all_nodes.is_empty() {
// If there are no nodes whatsoever in the routing table the gossip cannot proceed.
warn!("No nodes in routing table, gossip cannot proceed.");
Expand Down Expand Up @@ -132,7 +120,7 @@ pub async fn trace_propagate_gossip_cross_thread<TContentKey: OverlayContentKey>
// Get all connected nodes from overlay routing table
let interested_enrs = {
let kbuckets = kbuckets.read();
let mut all_nodes: Vec<&kbucket::Node<NodeId, Node>> = kbuckets
let all_nodes: Vec<&kbucket::Node<NodeId, Node>> = kbuckets
.buckets_iter()
.flat_map(|kbucket| {
kbucket
Expand All @@ -142,18 +130,6 @@ pub async fn trace_propagate_gossip_cross_thread<TContentKey: OverlayContentKey>
})
.collect();

if all_nodes.is_empty() {
warn!("No connected nodes, using disconnected nodes for gossip.");
all_nodes = kbuckets
.buckets_iter()
.flat_map(|kbucket| {
kbucket
.iter()
.collect::<Vec<&kbucket::Node<NodeId, Node>>>()
})
.collect();
}

if all_nodes.is_empty() {
// If there are no nodes whatsoever in the routing table the gossip cannot proceed.
warn!("No nodes in routing table, gossip cannot proceed.");
Expand Down
14 changes: 1 addition & 13 deletions portalnet/src/overlay_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2527,19 +2527,7 @@ where
peer_timeout: self.query_peer_timeout,
};

let mut closest_enrs = self.closest_connected_nodes(&target_key, query_config.num_results);
if closest_enrs.is_empty() {
// If there are no connected nodes, use the closest nodes regardless of connectivity.
warn!("No connected nodes, using disconnected nodes for query.");
closest_enrs = self
.kbuckets
.write()
.closest_values(&target_key)
.map(|closest| closest.value.enr)
.take(query_config.num_results)
.collect();
}

let closest_enrs = self.closest_connected_nodes(&target_key, query_config.num_results);
if closest_enrs.is_empty() {
// If there are no nodes whatsoever in the routing table the query cannot proceed.
warn!("No nodes in routing table, query cannot proceed.");
Expand Down

0 comments on commit e3adcda

Please sign in to comment.