Remove Score Ord, PartialOrd, Eq and PartialEq impls (#6420)

* drop score Ord, PartialOrd, Eq and PartialEq impls

and impl total_cmp instead

* Revert "Fix test failure on Rust v1.81 (#6407)"

This reverts commit 8a085fc828.

* reverse in the compare function

* lint mdfiles
This commit is contained in:
João Oliveira
2024-09-25 14:45:35 +01:00
committed by GitHub
parent 2792705331
commit 50d8375d46
4 changed files with 31 additions and 41 deletions

View File

@@ -1,8 +1,8 @@
use crate::discovery::enr::PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY;
use crate::discovery::{peer_id_to_node_id, CombinedKey};
use crate::{metrics, multiaddr::Multiaddr, types::Subnet, Enr, EnrExt, Gossipsub, PeerId};
use itertools::Itertools;
use peer_info::{ConnectionDirection, PeerConnectionStatus, PeerInfo};
use rand::seq::SliceRandom;
use score::{PeerAction, ReportSource, Score, ScoreState};
use slog::{crit, debug, error, trace, warn};
use std::net::IpAddr;
@@ -290,15 +290,11 @@ impl<E: EthSpec> PeerDB<E> {
/// 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<E>)> {
let mut connected = self
.peers
self.peers
.iter()
.filter(|(_, info)| info.is_connected())
.collect::<Vec<_>>();
connected.shuffle(&mut rand::thread_rng());
connected.sort_by_key(|(_, info)| info.score());
connected
.sorted_by(|(_, info_a), (_, info_b)| info_a.score().total_cmp(info_b.score(), false))
.collect::<Vec<_>>()
}
/// Returns a vector containing peers (their ids and info), sorted by
@@ -307,13 +303,11 @@ impl<E: EthSpec> PeerDB<E> {
where
F: Fn(&PeerInfo<E>) -> bool,
{
let mut by_status = self
.peers
self.peers
.iter()
.filter(|(_, info)| is_status(info))
.collect::<Vec<_>>();
by_status.sort_by_key(|(_, info)| info.score());
by_status.into_iter().rev().collect()
.sorted_by(|(_, info_a), (_, info_b)| info_a.score().total_cmp(info_b.score(), true))
.collect::<Vec<_>>()
}
/// Returns the peer with highest reputation that satisfies `is_status`
@@ -324,7 +318,7 @@ impl<E: EthSpec> PeerDB<E> {
self.peers
.iter()
.filter(|(_, info)| is_status(info))
.max_by_key(|(_, info)| info.score())
.max_by(|(_, info_a), (_, info_b)| info_a.score().total_cmp(info_b.score(), false))
.map(|(id, _)| id)
}