Skip to content

Commit

Permalink
Discovery patch (sigp#2382)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
AgeManning authored and paulhauner committed Jul 21, 2021
1 parent 264d5d8 commit 03e2ee6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion beacon_node/eth2_libp2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/eth2_libp2p/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
12 changes: 11 additions & 1 deletion beacon_node/eth2_libp2p/src/discovery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand All @@ -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 */
Expand Down
7 changes: 3 additions & 4 deletions beacon_node/eth2_libp2p/src/peer_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 03e2ee6

Please sign in to comment.