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

Skip recursive discovery query if no useful ENRs #6207

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions beacon_node/lighthouse_network/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ pub static DISCOVERY_SESSIONS: LazyLock<Result<IntGauge>> = LazyLock::new(|| {
"The number of active discovery sessions with peers",
)
});
pub static DISCOVERY_NO_USEFUL_ENRS: LazyLock<Result<IntCounter>> = LazyLock::new(|| {
try_create_int_counter(
"discovery_no_useful_enrs_found",
"Total number of counts a query returned no useful ENRs to dial",
)
});

pub static PEERS_PER_CLIENT: LazyLock<Result<IntGaugeVec>> = LazyLock::new(|| {
try_create_int_gauge_vec(
Expand Down
16 changes: 14 additions & 2 deletions beacon_node/lighthouse_network/src/peer_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ impl<E: EthSpec> PeerManager<E> {
#[allow(clippy::mutable_key_type)]
pub fn peers_discovered(&mut self, results: HashMap<Enr, Option<Instant>>) {
let mut to_dial_peers = 0;
let results_count = results.len();
jxs marked this conversation as resolved.
Show resolved Hide resolved
let connected_or_dialing = self.network_globals.connected_or_dialing_peers();
for (enr, min_ttl) in results {
// There are two conditions in deciding whether to dial this peer.
Expand Down Expand Up @@ -354,8 +355,19 @@ impl<E: EthSpec> PeerManager<E> {
}
}

// Queue another discovery if we need to
self.maintain_peer_count(to_dial_peers);
// The heartbeat will attempt new discovery queries every N seconds if the node needs more
// peers. As an optimization, this function can recursively trigger new discovery queries
// immediatelly if we don't fulfill our peers needs after completing a query. This
// recursiveness results in an infinite loop in networks where there not enough peers to
// reach out target. To prevent the infinite loop, if a query returns no useful peers, we
// will cancel the recursiveness and wait for the heartbeat to trigger another query latter.
if results_count > 0 && to_dial_peers == 0 {
debug!(self.log, "Skipping recursive discovery query after finding no useful results"; "results" => results_count);
metrics::inc_counter(&metrics::DISCOVERY_NO_USEFUL_ENRS);
} else {
// Queue another discovery if we need to
self.maintain_peer_count(to_dial_peers);
}
}

/// A STATUS message has been received from a peer. This resets the status timer.
Expand Down
Loading