mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2024-12-25 13:07:18 +00:00
Discovery patch (#2382)
* Upgrade libp2p and unstable gossip * Network protocol upgrades * Correct dependencies, reduce incoming bucket limit * Clean up dirty DHT entries before repopulating * Update cargo lock * Update lockfile * Update ENR dep * Update deps to specific versions * Update test dependencies * Update docker rust, and remote signer tests * More remote signer test fixes * Temp commit * Update discovery * Remove cached enrs after dialing * Increase the session capacity, for improved efficiency
This commit is contained in:
parent
4aa06c9555
commit
6fb48b45fa
@ -5,7 +5,7 @@ authors = ["Sigma Prime <contact@sigmaprime.io>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
discv5 = { version = "0.1.0-beta.4", features = ["libp2p"] }
|
||||
discv5 = { version = "0.1.0-beta.5", features = ["libp2p"] }
|
||||
unsigned-varint = { version = "0.6.0", features = ["codec"] }
|
||||
types = { path = "../../consensus/types" }
|
||||
hashset_delay = { path = "../../common/hashset_delay" }
|
||||
|
@ -154,7 +154,7 @@ impl Default for Config {
|
||||
// discv5 configuration
|
||||
let discv5_config = Discv5ConfigBuilder::new()
|
||||
.enable_packet_filter()
|
||||
.session_cache_capacity(1000)
|
||||
.session_cache_capacity(5000)
|
||||
.request_timeout(Duration::from_secs(1))
|
||||
.query_peer_timeout(Duration::from_secs(2))
|
||||
.query_timeout(Duration::from_secs(30))
|
||||
|
@ -295,6 +295,11 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
|
||||
self.cached_enrs.iter()
|
||||
}
|
||||
|
||||
/// Removes a cached ENR from the list.
|
||||
pub fn remove_cached_enr(&mut self, peer_id: &PeerId) -> Option<Enr> {
|
||||
self.cached_enrs.pop(peer_id)
|
||||
}
|
||||
|
||||
/// This adds a new `FindPeers` query to the queue if one doesn't already exist.
|
||||
pub fn discover_peers(&mut self) {
|
||||
// If the discv5 service isn't running or we are in the process of a query, don't bother queuing a new one.
|
||||
@ -502,6 +507,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Unbans the peer in discovery.
|
||||
pub fn unban_peer(&mut self, peer_id: &PeerId, ip_addresses: Vec<IpAddr>) {
|
||||
// first try and convert the peer_id to a node_id.
|
||||
if let Ok(node_id) = peer_id_to_node_id(peer_id) {
|
||||
@ -514,11 +520,15 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
|
||||
}
|
||||
}
|
||||
|
||||
// mark node as disconnected in DHT, freeing up space for other nodes
|
||||
/// Marks node as disconnected in the DHT, freeing up space for other nodes, this also removes
|
||||
/// nodes from the cached ENR list.
|
||||
pub fn disconnect_peer(&mut self, peer_id: &PeerId) {
|
||||
if let Ok(node_id) = peer_id_to_node_id(peer_id) {
|
||||
self.discv5.disconnect_node(&node_id);
|
||||
}
|
||||
// Remove the peer from the cached list, to prevent redialing disconnected
|
||||
// peers.
|
||||
self.cached_enrs.pop(peer_id);
|
||||
}
|
||||
|
||||
/* Internal Functions */
|
||||
|
@ -580,10 +580,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
|
||||
// ENR's may have multiple Multiaddrs. The multi-addr associated with the UDP
|
||||
// port is removed, which is assumed to be associated with the discv5 protocol (and
|
||||
// therefore irrelevant for other libp2p components).
|
||||
let mut out_list = enr.multiaddr();
|
||||
out_list.retain(|addr| !addr.iter().any(|v| matches!(v, MProtocol::Udp(_))));
|
||||
|
||||
out_list
|
||||
enr.multiaddr_tcp()
|
||||
} else {
|
||||
// PeerId is not known
|
||||
Vec::new()
|
||||
@ -674,6 +671,8 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
|
||||
.collect();
|
||||
for peer_id in &peers_to_dial {
|
||||
debug!(self.log, "Dialing cached ENR peer"; "peer_id" => %peer_id);
|
||||
// Remove the ENR from the cache to prevent continual re-dialing on disconnects
|
||||
self.discovery.remove_cached_enr(&peer_id);
|
||||
self.dial_peer(peer_id);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user