mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-19 21:04:41 +00:00
Use E for EthSpec globally (#5264)
* Use `E` for `EthSpec` globally * Fix tests * Merge branch 'unstable' into e-ethspec * Merge branch 'unstable' into e-ethspec # Conflicts: # beacon_node/execution_layer/src/engine_api.rs # beacon_node/execution_layer/src/engine_api/http.rs # beacon_node/execution_layer/src/engine_api/json_structures.rs # beacon_node/execution_layer/src/test_utils/handle_rpc.rs # beacon_node/store/src/partial_beacon_state.rs # consensus/types/src/beacon_block.rs # consensus/types/src/beacon_block_body.rs # consensus/types/src/beacon_state.rs # consensus/types/src/config_and_preset.rs # consensus/types/src/execution_payload.rs # consensus/types/src/execution_payload_header.rs # consensus/types/src/light_client_optimistic_update.rs # consensus/types/src/payload.rs # lcli/src/parse_ssz.rs
This commit is contained in:
@@ -32,9 +32,9 @@ const ALLOWED_NEGATIVE_GOSSIPSUB_FACTOR: f32 = 0.1;
|
||||
const DIAL_TIMEOUT: u64 = 15;
|
||||
|
||||
/// Storage of known peers, their reputation and information
|
||||
pub struct PeerDB<TSpec: EthSpec> {
|
||||
pub struct PeerDB<E: EthSpec> {
|
||||
/// The collection of known connected peers, their status and reputation
|
||||
peers: HashMap<PeerId, PeerInfo<TSpec>>,
|
||||
peers: HashMap<PeerId, PeerInfo<E>>,
|
||||
/// The number of disconnected nodes in the database.
|
||||
disconnected_peers: usize,
|
||||
/// Counts banned peers in total and per ip
|
||||
@@ -45,7 +45,7 @@ pub struct PeerDB<TSpec: EthSpec> {
|
||||
log: slog::Logger,
|
||||
}
|
||||
|
||||
impl<TSpec: EthSpec> PeerDB<TSpec> {
|
||||
impl<E: EthSpec> PeerDB<E> {
|
||||
pub fn new(trusted_peers: Vec<PeerId>, disable_peer_scoring: bool, log: &slog::Logger) -> Self {
|
||||
// Initialize the peers hashmap with trusted peers
|
||||
let peers = trusted_peers
|
||||
@@ -72,7 +72,7 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
|
||||
}
|
||||
|
||||
/// Returns an iterator over all peers in the db.
|
||||
pub fn peers(&self) -> impl Iterator<Item = (&PeerId, &PeerInfo<TSpec>)> {
|
||||
pub fn peers(&self) -> impl Iterator<Item = (&PeerId, &PeerInfo<E>)> {
|
||||
self.peers.iter()
|
||||
}
|
||||
|
||||
@@ -82,14 +82,14 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
|
||||
}
|
||||
|
||||
/// Returns a peer's info, if known.
|
||||
pub fn peer_info(&self, peer_id: &PeerId) -> Option<&PeerInfo<TSpec>> {
|
||||
pub fn peer_info(&self, peer_id: &PeerId) -> Option<&PeerInfo<E>> {
|
||||
self.peers.get(peer_id)
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to a peer's info if known.
|
||||
// VISIBILITY: The peer manager is able to modify some elements of the peer info, such as sync
|
||||
// status.
|
||||
pub(super) fn peer_info_mut(&mut self, peer_id: &PeerId) -> Option<&mut PeerInfo<TSpec>> {
|
||||
pub(super) fn peer_info_mut(&mut self, peer_id: &PeerId) -> Option<&mut PeerInfo<E>> {
|
||||
self.peers.get_mut(peer_id)
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
|
||||
}
|
||||
|
||||
/// Checks if the peer's known addresses are currently banned.
|
||||
fn ip_is_banned(&self, peer: &PeerInfo<TSpec>) -> Option<IpAddr> {
|
||||
fn ip_is_banned(&self, peer: &PeerInfo<E>) -> Option<IpAddr> {
|
||||
peer.seen_ip_addresses()
|
||||
.find(|ip| self.banned_peers_count.ip_is_banned(ip))
|
||||
}
|
||||
@@ -177,7 +177,7 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
|
||||
}
|
||||
|
||||
/// Gives the ids and info of all known connected peers.
|
||||
pub fn connected_peers(&self) -> impl Iterator<Item = (&PeerId, &PeerInfo<TSpec>)> {
|
||||
pub fn connected_peers(&self) -> impl Iterator<Item = (&PeerId, &PeerInfo<E>)> {
|
||||
self.peers.iter().filter(|(_, info)| info.is_connected())
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
|
||||
|
||||
/// Returns a vector of all connected peers sorted by score beginning with the worst scores.
|
||||
/// Ties get broken randomly.
|
||||
pub fn worst_connected_peers(&self) -> Vec<(&PeerId, &PeerInfo<TSpec>)> {
|
||||
pub fn worst_connected_peers(&self) -> Vec<(&PeerId, &PeerInfo<E>)> {
|
||||
let mut connected = self
|
||||
.peers
|
||||
.iter()
|
||||
@@ -285,9 +285,9 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
|
||||
|
||||
/// Returns a vector containing peers (their ids and info), sorted by
|
||||
/// score from highest to lowest, and filtered using `is_status`
|
||||
pub fn best_peers_by_status<F>(&self, is_status: F) -> Vec<(&PeerId, &PeerInfo<TSpec>)>
|
||||
pub fn best_peers_by_status<F>(&self, is_status: F) -> Vec<(&PeerId, &PeerInfo<E>)>
|
||||
where
|
||||
F: Fn(&PeerInfo<TSpec>) -> bool,
|
||||
F: Fn(&PeerInfo<E>) -> bool,
|
||||
{
|
||||
let mut by_status = self
|
||||
.peers
|
||||
@@ -301,7 +301,7 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
|
||||
/// Returns the peer with highest reputation that satisfies `is_status`
|
||||
pub fn best_by_status<F>(&self, is_status: F) -> Option<&PeerId>
|
||||
where
|
||||
F: Fn(&PeerInfo<TSpec>) -> bool,
|
||||
F: Fn(&PeerInfo<E>) -> bool,
|
||||
{
|
||||
self.peers
|
||||
.iter()
|
||||
@@ -1058,7 +1058,7 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
|
||||
fn handle_score_transition(
|
||||
previous_state: ScoreState,
|
||||
peer_id: &PeerId,
|
||||
info: &PeerInfo<TSpec>,
|
||||
info: &PeerInfo<E>,
|
||||
log: &slog::Logger,
|
||||
) -> ScoreTransitionResult {
|
||||
match (info.score_state(), previous_state) {
|
||||
@@ -1269,13 +1269,13 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn add_score<TSpec: EthSpec>(db: &mut PeerDB<TSpec>, peer_id: &PeerId, score: f64) {
|
||||
fn add_score<E: EthSpec>(db: &mut PeerDB<E>, peer_id: &PeerId, score: f64) {
|
||||
if let Some(info) = db.peer_info_mut(peer_id) {
|
||||
info.add_to_score(score);
|
||||
}
|
||||
}
|
||||
|
||||
fn reset_score<TSpec: EthSpec>(db: &mut PeerDB<TSpec>, peer_id: &PeerId) {
|
||||
fn reset_score<E: EthSpec>(db: &mut PeerDB<E>, peer_id: &PeerId) {
|
||||
if let Some(info) = db.peer_info_mut(peer_id) {
|
||||
info.reset_score();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user