mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 00:42:42 +00:00
Skip recursive discovery query if no useful ENRs (#6207)
* Skip recursive discovery query if no useful ENRs
This commit is contained in:
@@ -77,6 +77,12 @@ pub static DISCOVERY_SESSIONS: LazyLock<Result<IntGauge>> = LazyLock::new(|| {
|
|||||||
"The number of active discovery sessions with peers",
|
"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(|| {
|
pub static PEERS_PER_CLIENT: LazyLock<Result<IntGaugeVec>> = LazyLock::new(|| {
|
||||||
try_create_int_gauge_vec(
|
try_create_int_gauge_vec(
|
||||||
|
|||||||
@@ -321,6 +321,7 @@ impl<E: EthSpec> PeerManager<E> {
|
|||||||
/// This function decides whether or not to dial these peers.
|
/// This function decides whether or not to dial these peers.
|
||||||
pub fn peers_discovered(&mut self, results: HashMap<Enr, Option<Instant>>) {
|
pub fn peers_discovered(&mut self, results: HashMap<Enr, Option<Instant>>) {
|
||||||
let mut to_dial_peers = 0;
|
let mut to_dial_peers = 0;
|
||||||
|
let results_count = results.len();
|
||||||
let connected_or_dialing = self.network_globals.connected_or_dialing_peers();
|
let connected_or_dialing = self.network_globals.connected_or_dialing_peers();
|
||||||
for (enr, min_ttl) in results {
|
for (enr, min_ttl) in results {
|
||||||
// There are two conditions in deciding whether to dial this peer.
|
// There are two conditions in deciding whether to dial this peer.
|
||||||
@@ -352,8 +353,19 @@ impl<E: EthSpec> PeerManager<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Queue another discovery if we need to
|
// The heartbeat will attempt new discovery queries every N seconds if the node needs more
|
||||||
self.maintain_peer_count(to_dial_peers);
|
// 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.
|
/// A STATUS message has been received from a peer. This resets the status timer.
|
||||||
|
|||||||
Reference in New Issue
Block a user