mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 10:52:43 +00:00
Fulu update to spec [v1.6.0-alpha.4](https://github.com/ethereum/consensus-specs/releases/tag/v1.6.0-alpha.4). - Make `number_of_columns` a preset - Optimise `get_custody_groups` to avoid computing if cgc = 128 - Add support for additional typenum values in type_dispatch macro
55 lines
1.8 KiB
Rust
55 lines
1.8 KiB
Rust
//! The subnet predicate used for searching for a particular subnet.
|
|
use super::*;
|
|
use crate::types::{EnrAttestationBitfield, EnrSyncCommitteeBitfield};
|
|
use std::ops::Deref;
|
|
use tracing::trace;
|
|
use types::ChainSpec;
|
|
use types::data_column_custody_group::compute_subnets_for_node;
|
|
|
|
/// Returns the predicate for a given subnet.
|
|
pub fn subnet_predicate<E>(
|
|
subnets: Vec<Subnet>,
|
|
spec: Arc<ChainSpec>,
|
|
) -> impl Fn(&Enr) -> bool + Send
|
|
where
|
|
E: EthSpec,
|
|
{
|
|
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::<E>(enr.node_id().raw(), custody_group_count, &spec)
|
|
.is_ok_and(|subnets| subnets.contains(s))
|
|
} else {
|
|
false
|
|
}
|
|
}
|
|
});
|
|
|
|
if !predicate {
|
|
trace!(
|
|
peer_id = %enr.peer_id(),
|
|
"Peer found but not on any of the desired subnets"
|
|
);
|
|
}
|
|
predicate
|
|
}
|
|
}
|