Skip to content

Commit

Permalink
use peers_to_dial correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrsantos committed Jan 24, 2025
1 parent b295bf4 commit 6d4bb6f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ impl<N: NetworkGlobalsProvider> Connectivity<N> {
}
}

pub fn next_peer_to_dial(&mut self) -> Option<Enr> {
self.peers_to_dial.pop()
}

/// Peers that have been returned by discovery requests that are suitable for dialing are
/// returned here.
///
Expand Down
16 changes: 1 addition & 15 deletions beacon_node/lighthouse_network/src/peer_manager/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Implementation of Lighthouse's peer management system.
use crate::discovery::enr_ext::EnrExt;
use crate::discovery::peer_id_to_node_id;
use crate::rpc::{GoodbyeReason, MetaData, Protocol, RPCError, RpcErrorResponse};
use crate::service::TARGET_SUBNET_PEERS;
Expand Down Expand Up @@ -86,8 +85,6 @@ pub struct PeerManager<E: EthSpec> {
status_peers: HashSetDelay<PeerId>,
/// The target number of peers we would like to connect to.
target_peers: usize,
/// Peers queued to be dialed.
peers_to_dial: Vec<Enr>,
/// The number of temporarily banned peers. This is used to prevent instantaneous
/// reconnection.
// NOTE: This just prevents re-connections. The state of the peer is otherwise unaffected. A
Expand Down Expand Up @@ -186,7 +183,6 @@ impl<E: EthSpec> PeerManager<E> {
Ok(PeerManager {
network_globals: network_globals.clone(),
events: SmallVec::new(),
peers_to_dial: Default::default(),
inbound_ping_peers: HashSetDelay::new(Duration::from_secs(ping_interval_inbound)),
outbound_ping_peers: HashSetDelay::new(Duration::from_secs(ping_interval_outbound)),
status_peers: HashSetDelay::new(Duration::from_secs(status_interval)),
Expand Down Expand Up @@ -392,17 +388,7 @@ impl<E: EthSpec> PeerManager<E> {
/// A peer is being dialed.
/// Returns true, if this peer will be dialed.
pub fn dial_peer(&mut self, peer: Enr) -> bool {
if self
.network_globals
.peers
.read()
.should_dial(&peer.peer_id())
{
self.peers_to_dial.push(peer);
true
} else {
false
}
self.connectivity.dial_peer(peer)
}

/// Reports if a peer is banned or not.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<E: EthSpec> NetworkBehaviour for PeerManager<E> {
self.events.shrink_to_fit();
}

if let Some(enr) = self.peers_to_dial.pop() {
if let Some(enr) = self.connectivity.next_peer_to_dial() {
self.inject_peer_connection(&enr.peer_id(), ConnectingType::Dialing, Some(enr.clone()));

// Prioritize Quic connections over Tcp ones.
Expand Down

0 comments on commit 6d4bb6f

Please sign in to comment.