Merge remote-tracking branch 'origin/release-v7.0.0' into unstable

This commit is contained in:
Michael Sproul
2025-03-29 13:01:58 +11:00
21 changed files with 364 additions and 48 deletions

View File

@@ -9,7 +9,7 @@ use std::net::IpAddr;
use std::time::Instant;
use std::{cmp::Ordering, fmt::Display};
use std::{
collections::{HashMap, HashSet},
collections::{hash_map::Entry, HashMap, HashSet},
fmt::Formatter,
};
use sync_status::SyncStatus;
@@ -77,6 +77,33 @@ impl<E: EthSpec> PeerDB<E> {
self.peers.iter()
}
pub fn set_trusted_peer(&mut self, enr: Enr) {
match self.peers.entry(enr.peer_id()) {
Entry::Occupied(mut info) => {
let entry = info.get_mut();
entry.score = Score::max_score();
entry.is_trusted = true;
}
Entry::Vacant(entry) => {
entry.insert(PeerInfo::trusted_peer_info());
}
}
}
pub fn unset_trusted_peer(&mut self, enr: Enr) {
if let Some(info) = self.peers.get_mut(&enr.peer_id()) {
info.is_trusted = false;
info.score = Score::default();
}
}
pub fn trusted_peers(&self) -> Vec<PeerId> {
self.peers
.iter()
.filter_map(|(id, info)| if info.is_trusted { Some(*id) } else { None })
.collect()
}
/// Gives the ids of all known peers.
pub fn peer_ids(&self) -> impl Iterator<Item = &PeerId> {
self.peers.keys()