Discovery update (#1349)

* Improve logging

* Discovery update
This commit is contained in:
Age Manning
2020-07-11 12:35:59 +10:00
committed by GitHub
parent 9ae218bfac
commit e6a8635b38
6 changed files with 105 additions and 95 deletions

View File

@@ -2,7 +2,7 @@ use crate::peer_manager::{score::PeerAction, PeerManager, PeerManagerEvent};
use crate::rpc::*;
use crate::types::{GossipEncoding, GossipKind, GossipTopic};
use crate::Eth2Enr;
use crate::{error, Enr, NetworkConfig, NetworkGlobals, PubsubMessage, TopicHash};
use crate::{error, metrics, Enr, NetworkConfig, NetworkGlobals, PubsubMessage, TopicHash};
use futures::prelude::*;
use handler::{BehaviourHandler, BehaviourHandlerIn, BehaviourHandlerOut, DelegateIn, DelegateOut};
use libp2p::{
@@ -696,6 +696,15 @@ impl<TSpec: EthSpec> NetworkBehaviour for Behaviour<TSpec> {
self.peer_manager.notify_disconnect(&peer_id);
// Inform the application.
self.add_event(BehaviourEvent::PeerDisconnected(peer_id.clone()));
// Update the prometheus metrics
metrics::inc_counter(&metrics::PEER_DISCONNECT_EVENT_COUNT);
metrics::set_gauge(
&metrics::PEERS_CONNECTED,
self.network_globals.connected_peers() as i64,
);
// Inform the behaviour.
delegate_to_behaviours!(self, inject_disconnected, peer_id);
}
@@ -734,8 +743,7 @@ impl<TSpec: EthSpec> NetworkBehaviour for Behaviour<TSpec> {
debug!(self.log, "Connection established"; "peer_id" => peer_id.to_string(), "connection" => "Dialed");
}
}
// report the event to the application
// report the event to the behaviour
delegate_to_behaviours!(
self,
inject_connection_established,
@@ -752,6 +760,14 @@ impl<TSpec: EthSpec> NetworkBehaviour for Behaviour<TSpec> {
if self.peer_manager.is_banned(peer_id) {
return;
}
// increment prometheus metrics
metrics::inc_counter(&metrics::PEER_CONNECT_EVENT_COUNT);
metrics::set_gauge(
&metrics::PEERS_CONNECTED,
self.network_globals.connected_peers() as i64,
);
delegate_to_behaviours!(self, inject_connected, peer_id);
}

View File

@@ -15,7 +15,7 @@ use futures::prelude::*;
use futures::stream::FuturesUnordered;
use libp2p::core::PeerId;
use lru::LruCache;
use slog::{crit, debug, info, trace, warn};
use slog::{crit, debug, info, warn};
use ssz::{Decode, Encode};
use ssz_types::BitVector;
use std::{
@@ -242,7 +242,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
// If there is not already a find peer's query queued, add one
let query = QueryType::FindPeers;
if !self.queued_queries.contains(&query) {
trace!(self.log, "Queuing a peer discovery request");
debug!(self.log, "Queuing a peer discovery request");
self.queued_queries.push_back(query);
// update the metrics
metrics::set_gauge(&metrics::DISCOVERY_QUEUE, self.queued_queries.len() as i64);
@@ -407,8 +407,9 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
retries,
};
// update the metrics and insert into the queue.
metrics::set_gauge(&metrics::DISCOVERY_QUEUE, self.queued_queries.len() as i64);
debug!(self.log, "Queuing subnet query"; "subnet" => *subnet_id, "retries" => retries);
self.queued_queries.push_back(query);
metrics::set_gauge(&metrics::DISCOVERY_QUEUE, self.queued_queries.len() as i64);
}
}
@@ -430,7 +431,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
continue;
}
// This is a regular request to find additional peers
debug!(self.log, "Searching for new peers");
debug!(self.log, "Discovery query started");
self.find_peer_active = true;
self.start_query(QueryType::FindPeers, FIND_NODE_QUERY_CLOSEST_PEERS);
}
@@ -480,12 +481,13 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
}
let target_peers = TARGET_SUBNET_PEERS - peers_on_subnet;
debug!(self.log, "Searching for peers for subnet";
debug!(self.log, "Discovery query started for subnet";
"subnet_id" => *subnet_id,
"connected_peers_on_subnet" => peers_on_subnet,
"target_subnet_peers" => TARGET_SUBNET_PEERS,
"peers_to_find" => target_peers,
"attempt" => retries,
"min_ttl" => format!("{:?}", min_ttl),
);
// start the query, and update the queries map if necessary

View File

@@ -669,6 +669,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
let peer_count = self.network_globals.connected_or_dialing_peers();
if peer_count < self.target_peers {
// If we need more peers, queue a discovery lookup.
debug!(self.log, "Starting a new peer discovery query"; "connected_peers" => peer_count, "target_peers" => self.target_peers);
self.discovery.discover_peers();
}