Skip to content

Commit 902ae6c

Browse files
authored
Better handle nodes in propagate gossip cross thread when none are connected (#901)
* Better handle nodes in propagate gossip cross thread * resolved PR comment
1 parent ccbb159 commit 902ae6c

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

portalnet/src/overlay_service.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2502,7 +2502,7 @@ pub fn propagate_gossip_cross_thread<TContentKey: OverlayContentKey>(
25022502
) -> usize {
25032503
// Get all connected nodes from overlay routing table
25042504
let kbuckets = kbuckets.read();
2505-
let all_nodes: Vec<&kbucket::Node<NodeId, Node>> = kbuckets
2505+
let mut all_nodes: Vec<&kbucket::Node<NodeId, Node>> = kbuckets
25062506
.buckets_iter()
25072507
.flat_map(|kbucket| {
25082508
kbucket
@@ -2512,6 +2512,24 @@ pub fn propagate_gossip_cross_thread<TContentKey: OverlayContentKey>(
25122512
})
25132513
.collect();
25142514

2515+
if all_nodes.is_empty() {
2516+
warn!("No connected nodes, using disconnected nodes for gossip.");
2517+
all_nodes = kbuckets
2518+
.buckets_iter()
2519+
.flat_map(|kbucket| {
2520+
kbucket
2521+
.iter()
2522+
.collect::<Vec<&kbucket::Node<NodeId, Node>>>()
2523+
})
2524+
.collect();
2525+
}
2526+
2527+
if all_nodes.is_empty() {
2528+
// If there are no nodes whatsoever in the routing table the gossip cannot proceed.
2529+
warn!("No nodes in routing table, gossip cannot proceed.");
2530+
return 0;
2531+
}
2532+
25152533
// HashMap to temporarily store all interested ENRs and the content.
25162534
// Key is base64 string of node's ENR.
25172535
let mut enrs_and_content: HashMap<String, Vec<(RawContentKey, Vec<u8>)>> = HashMap::new();

0 commit comments

Comments
 (0)