mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-17 20:02:43 +00:00
* Implement PeerDAS subnet decoupling (aka custody groups). * Merge branch 'unstable' into decouple-subnets * Refactor feature testing for spec tests (#6737) Squashed commit of the following: commit898d05ee17Merge:ffbd25e2b7e0cddef3Author: Jimmy Chen <jchen.tc@gmail.com> Date: Tue Dec 24 14:41:19 2024 +1100 Merge branch 'unstable' into refactor-ef-tests-features commitffbd25e2beAuthor: Jimmy Chen <jchen.tc@gmail.com> Date: Tue Dec 24 14:40:38 2024 +1100 Fix `SszStatic` tests for PeerDAS: exclude eip7594 test vectors when testing Electra types. commitaa593cf35cAuthor: Jimmy Chen <jchen.tc@gmail.com> Date: Fri Dec 20 12:08:54 2024 +1100 Refactor spec testing for features and simplify usage. * Fix build. * Add input validation and improve arithmetic handling when calculating custody groups. * Address review comments re code style consistency. * Merge branch 'unstable' into decouple-subnets # Conflicts: # beacon_node/beacon_chain/src/kzg_utils.rs # beacon_node/beacon_chain/src/observed_data_sidecars.rs # beacon_node/lighthouse_network/src/discovery/subnet_predicate.rs # common/eth2_network_config/built_in_network_configs/chiado/config.yaml # common/eth2_network_config/built_in_network_configs/gnosis/config.yaml # common/eth2_network_config/built_in_network_configs/holesky/config.yaml # common/eth2_network_config/built_in_network_configs/mainnet/config.yaml # common/eth2_network_config/built_in_network_configs/sepolia/config.yaml # consensus/types/src/chain_spec.rs * Update consensus/types/src/chain_spec.rs Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com> * Merge remote-tracking branch 'origin/unstable' into decouple-subnets * Update error handling. * Address review comment. * Merge remote-tracking branch 'origin/unstable' into decouple-subnets # Conflicts: # consensus/types/src/chain_spec.rs * Update PeerDAS spec tests to `1.5.0-beta.0` and fix failing unit tests. * Merge remote-tracking branch 'origin/unstable' into decouple-subnets # Conflicts: # beacon_node/lighthouse_network/src/peer_manager/mod.rs
59 lines
1.9 KiB
Rust
59 lines
1.9 KiB
Rust
//! The subnet predicate used for searching for a particular subnet.
|
|
use super::*;
|
|
use crate::types::{EnrAttestationBitfield, EnrSyncCommitteeBitfield};
|
|
use slog::trace;
|
|
use std::ops::Deref;
|
|
use types::data_column_custody_group::compute_subnets_for_node;
|
|
use types::ChainSpec;
|
|
|
|
/// Returns the predicate for a given subnet.
|
|
pub fn subnet_predicate<E>(
|
|
subnets: Vec<Subnet>,
|
|
log: &slog::Logger,
|
|
spec: Arc<ChainSpec>,
|
|
) -> impl Fn(&Enr) -> bool + Send
|
|
where
|
|
E: EthSpec,
|
|
{
|
|
let log_clone = log.clone();
|
|
|
|
move |enr: &Enr| {
|
|
let attestation_bitfield: EnrAttestationBitfield<E> = match enr.attestation_bitfield::<E>()
|
|
{
|
|
Ok(b) => b,
|
|
Err(_e) => return false,
|
|
};
|
|
|
|
// Pre-fork/fork-boundary enrs may not contain a syncnets field.
|
|
// Don't return early here.
|
|
let sync_committee_bitfield: Result<EnrSyncCommitteeBitfield<E>, _> =
|
|
enr.sync_committee_bitfield::<E>();
|
|
|
|
let predicate = subnets.iter().any(|subnet| match subnet {
|
|
Subnet::Attestation(s) => attestation_bitfield
|
|
.get(*s.deref() as usize)
|
|
.unwrap_or(false),
|
|
Subnet::SyncCommittee(s) => sync_committee_bitfield
|
|
.as_ref()
|
|
.is_ok_and(|b| b.get(*s.deref() as usize).unwrap_or(false)),
|
|
Subnet::DataColumn(s) => {
|
|
if let Ok(custody_group_count) = enr.custody_group_count::<E>(&spec) {
|
|
compute_subnets_for_node(enr.node_id().raw(), custody_group_count, &spec)
|
|
.is_ok_and(|subnets| subnets.contains(s))
|
|
} else {
|
|
false
|
|
}
|
|
}
|
|
});
|
|
|
|
if !predicate {
|
|
trace!(
|
|
log_clone,
|
|
"Peer found but not on any of the desired subnets";
|
|
"peer_id" => %enr.peer_id()
|
|
);
|
|
}
|
|
predicate
|
|
}
|
|
}
|