Various corrections pre-testnet (#1019)

* Correct sync log messaging

* Modify syncing logs

* Update discv5 bug

* Discv5 patch

* Re-word sync status message

* Correct discovery peer finding logic

* Remove debugging log

* Remove duplicates in CLI

* Correct fmt
This commit is contained in:
Age Manning
2020-04-19 20:45:25 +10:00
committed by GitHub
parent 7b86c9a08f
commit 489ad90536
9 changed files with 176 additions and 176 deletions

View File

@@ -58,6 +58,7 @@ pub fn spawn_notifier<T: BeaconChainTypes>(
let log = log_2.clone();
let connected_peer_count = network.connected_peers();
let sync_state = network.sync_state();
let head_info = beacon_chain.head_info()
.map_err(|e| error!(
@@ -67,7 +68,6 @@ pub fn spawn_notifier<T: BeaconChainTypes>(
))?;
let head_slot = head_info.slot;
let head_epoch = head_slot.epoch(T::EthSpec::slots_per_epoch());
let current_slot = beacon_chain.slot().map_err(|e| {
error!(
log,
@@ -101,15 +101,17 @@ pub fn spawn_notifier<T: BeaconChainTypes>(
"head_block" => format!("{}", head_root),
"head_slot" => head_slot,
"current_slot" => current_slot,
"sync_state" =>format!("{}", sync_state)
);
if head_epoch + 1 < current_epoch {
// Log if we are syncing
if sync_state.is_syncing() {
let distance = format!(
"{} slots ({})",
head_distance.as_u64(),
slot_distance_pretty(head_distance, slot_duration)
);
info!(
log,
"Syncing";
@@ -118,15 +120,21 @@ pub fn spawn_notifier<T: BeaconChainTypes>(
"speed" => sync_speed_pretty(speedo.slots_per_second()),
"est_time" => estimated_time_pretty(speedo.estimated_time_till_slot(current_slot)),
);
return Ok(());
};
macro_rules! not_quite_synced_log {
($message: expr) => {
} else {
if sync_state.is_synced() {
info!(
log_2,
$message;
"Synced";
"peers" => peer_count_pretty(connected_peer_count),
"finalized_root" => format!("{}", finalized_root),
"finalized_epoch" => finalized_epoch,
"epoch" => current_epoch,
"slot" => current_slot,
);
} else {
info!(
log_2,
"Searching for peers";
"peers" => peer_count_pretty(connected_peer_count),
"finalized_root" => format!("{}", finalized_root),
"finalized_epoch" => finalized_epoch,
@@ -135,23 +143,6 @@ pub fn spawn_notifier<T: BeaconChainTypes>(
);
}
}
if head_epoch + 1 == current_epoch {
not_quite_synced_log!("Synced to previous epoch")
} else if head_slot != current_slot {
not_quite_synced_log!("Synced to current epoch")
} else {
info!(
log_2,
"Synced";
"peers" => peer_count_pretty(connected_peer_count),
"finalized_root" => format!("{}", finalized_root),
"finalized_epoch" => finalized_epoch,
"epoch" => current_epoch,
"slot" => current_slot,
);
};
Ok(())
})
.then(move |result| {

View File

@@ -8,7 +8,7 @@ edition = "2018"
hex = "0.3"
# rust-libp2p is presently being sourced from a Sigma Prime fork of the
# `libp2p/rust-libp2p` repository.
libp2p = { git = "https://github.com/SigP/rust-libp2p", rev = "4e3003d5283040fee10da1299252dd060a838d97" }
libp2p = { git = "https://github.com/SigP/rust-libp2p", rev = "2b6d002161f142b1db350f6d1302b4a84a1d4234" }
types = { path = "../../eth2/types" }
hashmap_delay = { path = "../../eth2/utils/hashmap_delay" }
eth2_ssz_types = { path = "../../eth2/utils/ssz_types" }
@@ -33,6 +33,7 @@ parking_lot = "0.9.0"
sha2 = "0.8.0"
base64 = "0.11.0"
snap = "1"
void = "1.0.2"
[dev-dependencies]
slog-stdlog = "4.0.0"

View File

@@ -114,7 +114,8 @@ impl Default for Config {
.enr_update(true) // update IP based on PONG responses
.enr_peer_update_min(2) // prevents NAT's should be raised for mainnet
.query_parallelism(5)
.query_timeout(Duration::from_secs(2))
.query_timeout(Duration::from_secs(60))
.query_peer_timeout(Duration::from_secs(2))
.ip_limit(false) // limits /24 IP's in buckets. Enable for mainnet
.ping_interval(Duration::from_secs(300))
.build();

View File

@@ -13,10 +13,10 @@ use libp2p::discv5::enr::NodeId;
use libp2p::discv5::{Discv5, Discv5Event};
use libp2p::multiaddr::Protocol;
use libp2p::swarm::{NetworkBehaviour, NetworkBehaviourAction, PollParameters, ProtocolsHandler};
use slog::{crit, debug, info, trace, warn};
use slog::{crit, debug, info, warn};
use ssz::{Decode, Encode};
use ssz_types::BitVector;
use std::collections::HashSet;
use std::collections::{HashSet, VecDeque};
use std::net::SocketAddr;
use std::path::Path;
use std::sync::Arc;
@@ -37,6 +37,9 @@ const TARGET_SUBNET_PEERS: u64 = 3;
/// Lighthouse discovery behaviour. This provides peer management and discovery using the Discv5
/// libp2p protocol.
pub struct Discovery<TSubstream, TSpec: EthSpec> {
/// Events to be processed by the behaviour.
events: VecDeque<NetworkBehaviourAction<void::Void, Discv5Event>>,
/// The currently banned peers.
banned_peers: HashSet<PeerId>,
@@ -105,7 +108,7 @@ impl<TSubstream, TSpec: EthSpec> Discovery<TSubstream, TSpec> {
"peer_id" => format!("{}", bootnode_enr.peer_id()),
"ip" => format!("{:?}", bootnode_enr.ip()),
"udp" => format!("{:?}", bootnode_enr.udp()),
"tcp" => format!("{:?}", bootnode_enr.udp())
"tcp" => format!("{:?}", bootnode_enr.tcp())
);
let _ = discovery.add_enr(bootnode_enr).map_err(|e| {
warn!(
@@ -117,6 +120,7 @@ impl<TSubstream, TSpec: EthSpec> Discovery<TSubstream, TSpec> {
}
Ok(Self {
events: VecDeque::with_capacity(16),
banned_peers: HashSet::new(),
max_peers: config.max_peers,
peer_discovery_delay: Delay::new(Instant::now()),
@@ -409,16 +413,18 @@ where
match self.discovery.poll(params) {
Async::Ready(NetworkBehaviourAction::GenerateEvent(event)) => {
match event {
Discv5Event::Discovered(enr) => {
Discv5Event::Discovered(_enr) => {
// peers that get discovered during a query but are not contactable or
// don't match a predicate can end up here. For debugging purposes we
// log these to see if we are unnecessarily dropping discovered peers
/*
if enr.eth2() == self.local_enr().eth2() {
trace!(self.log, "Peer found in process of query"; "peer_id" => format!("{}", enr.peer_id()), "tcp_socket" => enr.tcp_socket());
} else {
// this is temporary warning for debugging the DHT
warn!(self.log, "Found peer during discovery not on correct fork"; "peer_id" => format!("{}", enr.peer_id()), "tcp_socket" => enr.tcp_socket());
}
*/
}
Discv5Event::SocketUpdated(socket) => {
info!(self.log, "Address updated"; "ip" => format!("{}",socket.ip()), "udp_port" => format!("{}", socket.port()));
@@ -449,18 +455,12 @@ where
// if we need more peers, attempt a connection
if self.network_globals.connected_peers() < self.max_peers
&& self
.network_globals
.peers
.read()
.peer_info(&peer_id)
.is_none()
&& !self.network_globals.peers.read().is_connected(&peer_id)
&& !self.banned_peers.contains(&peer_id)
{
debug!(self.log, "Peer discovered"; "peer_id"=> format!("{:?}", peer_id));
return Async::Ready(NetworkBehaviourAction::DialPeer {
peer_id,
});
self.events
.push_back(NetworkBehaviourAction::DialPeer { peer_id });
}
}
}
@@ -472,6 +472,12 @@ where
Async::NotReady => break,
}
}
// process any queued events
if let Some(event) = self.events.pop_front() {
return Async::Ready(event);
}
Async::NotReady
}
}

View File

@@ -148,6 +148,15 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
})
}
/// Returns if the peer is already connected.
pub fn is_connected(&self, peer_id: &PeerId) -> bool {
if let PeerConnectionStatus::Connected { .. } = self.connection_status(peer_id) {
true
} else {
false
}
}
/* Setters */
/// Sets a peer as connected with an ingoing connection

View File

@@ -252,14 +252,13 @@ impl<T: BeaconChainTypes> SyncManager<T> {
// Check if the peer is significantly behind us. If within `SLOT_IMPORT_TOLERANCE`
// treat them as a fully synced peer. If not, ignore them in the sync process
if local.head_slot.sub(remote.head_slot).as_usize() < SLOT_IMPORT_TOLERANCE {
// Add the peer to our RangeSync
self.range_sync
.add_peer(&mut self.network, peer_id.clone(), remote);
self.synced_peer(&peer_id, remote.head_slot);
} else {
self.behind_peer(&peer_id, remote.head_slot);
return;
}
// Add the peer to our RangeSync
self.range_sync.add_peer(&mut self.network, peer_id, remote);
}
/// The response to a `BlocksByRoot` request.

View File

@@ -109,7 +109,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
)
.arg(
Arg::with_name("disable-enr-auto-update")
.short("s")
.short("x")
.long("disable-enr-auto-update")
.help("Discovery automatically updates the nodes local ENR with an external IP address and port as seen by other peers on the network. \
This disables this feature, fixing the ENR's IP/PORT to those specified on boot.")