mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-31 21:27:12 +00:00
Update Rust Edition to 2024 (#7766)
* #7749 Thanks @dknopik and @michaelsproul for your help!
This commit is contained in:
@@ -4,7 +4,7 @@ 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;
|
||||
use crate::{metrics, Gossipsub, NetworkGlobals, PeerId, Subnet, SubnetDiscovery};
|
||||
use crate::{Gossipsub, NetworkGlobals, PeerId, Subnet, SubnetDiscovery, metrics};
|
||||
use delay_map::HashSetDelay;
|
||||
use discv5::Enr;
|
||||
use libp2p::identify::Info as IdentifyInfo;
|
||||
@@ -31,11 +31,11 @@ pub use peerdb::peer_info::{
|
||||
};
|
||||
use peerdb::score::{PeerAction, ReportSource};
|
||||
pub use peerdb::sync_status::{SyncInfo, SyncStatus};
|
||||
use std::collections::{hash_map::Entry, HashMap, HashSet};
|
||||
use std::collections::{HashMap, HashSet, hash_map::Entry};
|
||||
use std::net::IpAddr;
|
||||
use strum::IntoEnumIterator;
|
||||
use types::data_column_custody_group::{
|
||||
compute_subnets_from_custody_group, get_custody_groups, CustodyIndex,
|
||||
CustodyIndex, compute_subnets_from_custody_group, get_custody_groups,
|
||||
};
|
||||
|
||||
pub mod config;
|
||||
@@ -1141,7 +1141,7 @@ impl<E: EthSpec> PeerManager<E> {
|
||||
if !peers_on_subnet.is_empty() {
|
||||
// Order the peers by the number of subnets they are long-lived
|
||||
// subscribed too, shuffle equal peers.
|
||||
peers_on_subnet.shuffle(&mut rand::thread_rng());
|
||||
peers_on_subnet.shuffle(&mut rand::rng());
|
||||
peers_on_subnet.sort_by_key(|(_, info)| info.long_lived_subnet_count());
|
||||
|
||||
// Try and find a candidate peer to remove from the subnet.
|
||||
@@ -1525,8 +1525,8 @@ enum ConnectingType {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::rpc::MetaDataV3;
|
||||
use crate::NetworkConfig;
|
||||
use crate::rpc::MetaDataV3;
|
||||
use types::{ChainSpec, ForkName, MainnetEthSpec as E};
|
||||
|
||||
async fn build_peer_manager(target_peer_count: usize) -> PeerManager<E> {
|
||||
@@ -1619,32 +1619,40 @@ mod tests {
|
||||
// Check that one outbound-only peer was removed because it had the worst score
|
||||
// and that we did not disconnect the other outbound peer due to the minimum outbound quota.
|
||||
assert_eq!(peer_manager.network_globals.connected_or_dialing_peers(), 3);
|
||||
assert!(peer_manager
|
||||
.network_globals
|
||||
.peers
|
||||
.read()
|
||||
.is_connected(&outbound_only_peer1));
|
||||
assert!(!peer_manager
|
||||
.network_globals
|
||||
.peers
|
||||
.read()
|
||||
.is_connected(&outbound_only_peer2));
|
||||
assert!(
|
||||
peer_manager
|
||||
.network_globals
|
||||
.peers
|
||||
.read()
|
||||
.is_connected(&outbound_only_peer1)
|
||||
);
|
||||
assert!(
|
||||
!peer_manager
|
||||
.network_globals
|
||||
.peers
|
||||
.read()
|
||||
.is_connected(&outbound_only_peer2)
|
||||
);
|
||||
|
||||
// The trusted peer remains connected
|
||||
assert!(peer_manager
|
||||
.network_globals
|
||||
.peers
|
||||
.read()
|
||||
.is_connected(&trusted_peer));
|
||||
assert!(
|
||||
peer_manager
|
||||
.network_globals
|
||||
.peers
|
||||
.read()
|
||||
.is_connected(&trusted_peer)
|
||||
);
|
||||
|
||||
peer_manager.heartbeat();
|
||||
|
||||
// The trusted peer remains connected, even after subsequent heartbeats.
|
||||
assert!(peer_manager
|
||||
.network_globals
|
||||
.peers
|
||||
.read()
|
||||
.is_connected(&trusted_peer));
|
||||
assert!(
|
||||
peer_manager
|
||||
.network_globals
|
||||
.peers
|
||||
.read()
|
||||
.is_connected(&trusted_peer)
|
||||
);
|
||||
|
||||
// Check that if we are at target number of peers, we do not disconnect any.
|
||||
assert_eq!(peer_manager.network_globals.connected_or_dialing_peers(), 3);
|
||||
@@ -1956,13 +1964,7 @@ mod tests {
|
||||
// id mod % 4
|
||||
// except for the last 5 peers which all go on their own subnets
|
||||
// So subnets 0-2 should have 4 peers subnet 3 should have 3 and 15-19 should have 1
|
||||
let subnet: u64 = {
|
||||
if x < 15 {
|
||||
x % 4
|
||||
} else {
|
||||
x
|
||||
}
|
||||
};
|
||||
let subnet: u64 = { if x < 15 { x % 4 } else { x } };
|
||||
|
||||
let peer = PeerId::random();
|
||||
peer_manager.inject_connect_ingoing(&peer, "/ip4/0.0.0.0".parse().unwrap(), None);
|
||||
|
||||
Reference in New Issue
Block a user