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:
Jimmy Chen
2024-09-06 17:39:16 +10:00
committed by GitHub
parent 0c5e25b62a
commit c0b4f01cf3
13 changed files with 292 additions and 235 deletions

View File

@@ -3,7 +3,6 @@ use super::score::{PeerAction, Score, ScoreState};
use super::sync_status::SyncStatus;
use crate::discovery::Eth2Enr;
use crate::{rpc::MetaData, types::Subnet};
use discv5::enr::NodeId;
use discv5::Enr;
use libp2p::core::multiaddr::{Multiaddr, Protocol};
use serde::{
@@ -14,7 +13,7 @@ use std::collections::HashSet;
use std::net::IpAddr;
use std::time::Instant;
use strum::AsRefStr;
use types::{ChainSpec, DataColumnSubnetId, EthSpec};
use types::{DataColumnSubnetId, EthSpec};
use PeerConnectionStatus::*;
/// Information about a given connected peer.
@@ -358,31 +357,7 @@ impl<E: EthSpec> PeerInfo<E> {
/// Sets an explicit value for the meta data.
// VISIBILITY: The peer manager is able to adjust the meta_data
pub(in crate::peer_manager) fn set_meta_data(
&mut self,
meta_data: MetaData<E>,
node_id_opt: Option<NodeId>,
spec: &ChainSpec,
) {
// If we don't have a node id, we cannot compute the custody duties anyway
let Some(node_id) = node_id_opt else {
self.meta_data = Some(meta_data);
return;
};
// Already set by enr if custody_subnets is non empty
if self.custody_subnets.is_empty() {
if let Ok(custody_subnet_count) = meta_data.custody_subnet_count() {
let custody_subnets = DataColumnSubnetId::compute_custody_subnets::<E>(
node_id.raw(),
std::cmp::min(*custody_subnet_count, spec.data_column_sidecar_subnet_count),
spec,
)
.collect::<HashSet<_>>();
self.set_custody_subnets(custody_subnets);
}
}
pub(in crate::peer_manager) fn set_meta_data(&mut self, meta_data: MetaData<E>) {
self.meta_data = Some(meta_data);
}
@@ -391,7 +366,10 @@ impl<E: EthSpec> PeerInfo<E> {
self.connection_status = connection_status
}
pub(super) fn set_custody_subnets(&mut self, custody_subnets: HashSet<DataColumnSubnetId>) {
pub(in crate::peer_manager) fn set_custody_subnets(
&mut self,
custody_subnets: HashSet<DataColumnSubnetId>,
) {
self.custody_subnets = custody_subnets
}