Skip to content

Commit 6fb48b4

Browse files
committed
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
1 parent 4aa06c9 commit 6fb48b4

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

beacon_node/eth2_libp2p/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = ["Sigma Prime <[email protected]>"]
55
edition = "2018"
66

77
[dependencies]
8-
discv5 = { version = "0.1.0-beta.4", features = ["libp2p"] }
8+
discv5 = { version = "0.1.0-beta.5", features = ["libp2p"] }
99
unsigned-varint = { version = "0.6.0", features = ["codec"] }
1010
types = { path = "../../consensus/types" }
1111
hashset_delay = { path = "../../common/hashset_delay" }

beacon_node/eth2_libp2p/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl Default for Config {
154154
// discv5 configuration
155155
let discv5_config = Discv5ConfigBuilder::new()
156156
.enable_packet_filter()
157-
.session_cache_capacity(1000)
157+
.session_cache_capacity(5000)
158158
.request_timeout(Duration::from_secs(1))
159159
.query_peer_timeout(Duration::from_secs(2))
160160
.query_timeout(Duration::from_secs(30))

beacon_node/eth2_libp2p/src/discovery/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
295295
self.cached_enrs.iter()
296296
}
297297

298+
/// Removes a cached ENR from the list.
299+
pub fn remove_cached_enr(&mut self, peer_id: &PeerId) -> Option<Enr> {
300+
self.cached_enrs.pop(peer_id)
301+
}
302+
298303
/// This adds a new `FindPeers` query to the queue if one doesn't already exist.
299304
pub fn discover_peers(&mut self) {
300305
// 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> {
502507
}
503508
}
504509

510+
/// Unbans the peer in discovery.
505511
pub fn unban_peer(&mut self, peer_id: &PeerId, ip_addresses: Vec<IpAddr>) {
506512
// first try and convert the peer_id to a node_id.
507513
if let Ok(node_id) = peer_id_to_node_id(peer_id) {
@@ -514,11 +520,15 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
514520
}
515521
}
516522

517-
// mark node as disconnected in DHT, freeing up space for other nodes
523+
/// Marks node as disconnected in the DHT, freeing up space for other nodes, this also removes
524+
/// nodes from the cached ENR list.
518525
pub fn disconnect_peer(&mut self, peer_id: &PeerId) {
519526
if let Ok(node_id) = peer_id_to_node_id(peer_id) {
520527
self.discv5.disconnect_node(&node_id);
521528
}
529+
// Remove the peer from the cached list, to prevent redialing disconnected
530+
// peers.
531+
self.cached_enrs.pop(peer_id);
522532
}
523533

524534
/* Internal Functions */

beacon_node/eth2_libp2p/src/peer_manager/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
580580
// ENR's may have multiple Multiaddrs. The multi-addr associated with the UDP
581581
// port is removed, which is assumed to be associated with the discv5 protocol (and
582582
// therefore irrelevant for other libp2p components).
583-
let mut out_list = enr.multiaddr();
584-
out_list.retain(|addr| !addr.iter().any(|v| matches!(v, MProtocol::Udp(_))));
585-
586-
out_list
583+
enr.multiaddr_tcp()
587584
} else {
588585
// PeerId is not known
589586
Vec::new()
@@ -674,6 +671,8 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
674671
.collect();
675672
for peer_id in &peers_to_dial {
676673
debug!(self.log, "Dialing cached ENR peer"; "peer_id" => %peer_id);
674+
// Remove the ENR from the cache to prevent continual re-dialing on disconnects
675+
self.discovery.remove_cached_enr(&peer_id);
677676
self.dial_peer(peer_id);
678677
}
679678
}

0 commit comments

Comments
 (0)