mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-17 11:52:42 +00:00
Improve get_custody_columns validation, caching and error handling (#6308)
* Improve `get_custody_columns` validation, caching and error handling. * Merge branch 'unstable' into get-custody-columns-error-handing * Fix failing test and add more test. * Fix failing test and add more test. * Merge branch 'unstable' into get-custody-columns-error-handing # Conflicts: # beacon_node/lighthouse_network/src/discovery/subnet_predicate.rs # beacon_node/lighthouse_network/src/peer_manager/peerdb.rs # beacon_node/lighthouse_network/src/peer_manager/peerdb/peer_info.rs # beacon_node/lighthouse_network/src/types/globals.rs # beacon_node/network/src/service.rs # consensus/types/src/data_column_subnet_id.rs * Add unit test to make sure the default specs won't panic on the `compute_custody_requirement_subnets` function. * Add condition when calling `compute_custody_subnets_from_metadata` and update logs. * Validate `csc` when returning from enr. Remove `csc` computation on connection since we get them on metadata anyway. * Add `peers_per_custody_subnet_count` to track peer csc and supernodes. * Disconnect peers with invalid metadata and find other peers instead. * Fix sampling tests. * Merge branch 'unstable' into get-custody-columns-error-handing * Merge branch 'unstable' into get-custody-columns-error-handing
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
use crate::discovery::enr::PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY;
|
||||
use crate::discovery::CombinedKey;
|
||||
use crate::{
|
||||
metrics, multiaddr::Multiaddr, types::Subnet, Enr, EnrExt, Eth2Enr, Gossipsub, PeerId,
|
||||
};
|
||||
use crate::{metrics, multiaddr::Multiaddr, types::Subnet, Enr, EnrExt, Gossipsub, PeerId};
|
||||
use peer_info::{ConnectionDirection, PeerConnectionStatus, PeerInfo};
|
||||
use rand::seq::SliceRandom;
|
||||
use score::{PeerAction, ReportSource, Score, ScoreState};
|
||||
@@ -47,16 +45,10 @@ pub struct PeerDB<E: EthSpec> {
|
||||
disable_peer_scoring: bool,
|
||||
/// PeerDB's logger
|
||||
log: slog::Logger,
|
||||
spec: ChainSpec,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> PeerDB<E> {
|
||||
pub fn new(
|
||||
trusted_peers: Vec<PeerId>,
|
||||
disable_peer_scoring: bool,
|
||||
log: &slog::Logger,
|
||||
spec: ChainSpec,
|
||||
) -> Self {
|
||||
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
|
||||
.into_iter()
|
||||
@@ -68,7 +60,6 @@ impl<E: EthSpec> PeerDB<E> {
|
||||
banned_peers_count: BannedPeersCount::default(),
|
||||
disable_peer_scoring,
|
||||
peers,
|
||||
spec,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -726,6 +717,14 @@ impl<E: EthSpec> PeerDB<E> {
|
||||
},
|
||||
);
|
||||
|
||||
if supernode {
|
||||
let peer_info = self.peers.get_mut(&peer_id).expect("peer exists");
|
||||
let all_subnets = (0..spec.data_column_sidecar_subnet_count)
|
||||
.map(|csc| csc.into())
|
||||
.collect();
|
||||
peer_info.set_custody_subnets(all_subnets);
|
||||
}
|
||||
|
||||
peer_id
|
||||
}
|
||||
|
||||
@@ -791,14 +790,6 @@ impl<E: EthSpec> PeerDB<E> {
|
||||
) => {
|
||||
// Update the ENR if one exists, and compute the custody subnets
|
||||
if let Some(enr) = enr {
|
||||
let custody_subnet_count = enr.custody_subnet_count::<E>(&self.spec);
|
||||
let custody_subnets = DataColumnSubnetId::compute_custody_subnets::<E>(
|
||||
enr.node_id().raw(),
|
||||
custody_subnet_count,
|
||||
&self.spec,
|
||||
)
|
||||
.collect::<HashSet<_>>();
|
||||
info.set_custody_subnets(custody_subnets);
|
||||
info.set_enr(enr);
|
||||
}
|
||||
|
||||
@@ -1349,8 +1340,7 @@ mod tests {
|
||||
|
||||
fn get_db() -> PeerDB<M> {
|
||||
let log = build_log(slog::Level::Debug, false);
|
||||
let spec = M::default_spec();
|
||||
PeerDB::new(vec![], false, &log, spec)
|
||||
PeerDB::new(vec![], false, &log)
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2049,8 +2039,7 @@ mod tests {
|
||||
fn test_trusted_peers_score() {
|
||||
let trusted_peer = PeerId::random();
|
||||
let log = build_log(slog::Level::Debug, false);
|
||||
let spec = M::default_spec();
|
||||
let mut pdb: PeerDB<M> = PeerDB::new(vec![trusted_peer], false, &log, spec);
|
||||
let mut pdb: PeerDB<M> = PeerDB::new(vec![trusted_peer], false, &log);
|
||||
|
||||
pdb.connect_ingoing(&trusted_peer, "/ip4/0.0.0.0".parse().unwrap(), None);
|
||||
|
||||
@@ -2074,8 +2063,7 @@ mod tests {
|
||||
fn test_disable_peer_scoring() {
|
||||
let peer = PeerId::random();
|
||||
let log = build_log(slog::Level::Debug, false);
|
||||
let spec = M::default_spec();
|
||||
let mut pdb: PeerDB<M> = PeerDB::new(vec![], true, &log, spec);
|
||||
let mut pdb: PeerDB<M> = PeerDB::new(vec![], true, &log);
|
||||
|
||||
pdb.connect_ingoing(&peer, "/ip4/0.0.0.0".parse().unwrap(), None);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user