Merge unstable

This commit is contained in:
Eitan Seri-Levi
2025-02-02 00:18:00 +03:00
340 changed files with 10457 additions and 4957 deletions

View File

@@ -16,7 +16,7 @@ use crate::rpc::{
use crate::types::{
attestation_sync_committee_topics, fork_core_topics, subnet_from_topic_hash, GossipEncoding,
GossipKind, GossipTopic, SnappyTransform, Subnet, SubnetDiscovery, ALTAIR_CORE_TOPICS,
BASE_CORE_TOPICS, CAPELLA_CORE_TOPICS, DENEB_CORE_TOPICS, LIGHT_CLIENT_GOSSIP_TOPICS,
BASE_CORE_TOPICS, CAPELLA_CORE_TOPICS, LIGHT_CLIENT_GOSSIP_TOPICS,
};
use crate::EnrExt;
use crate::Eth2Enr;
@@ -198,15 +198,12 @@ impl<E: EthSpec> Network<E> {
)?;
// Construct the metadata
let custody_subnet_count = ctx.chain_spec.is_peer_das_scheduled().then(|| {
if config.subscribe_all_data_column_subnets {
ctx.chain_spec.data_column_sidecar_subnet_count
} else {
ctx.chain_spec.custody_requirement
}
let custody_group_count = ctx.chain_spec.is_peer_das_scheduled().then(|| {
ctx.chain_spec
.custody_group_count(config.subscribe_all_data_column_subnets)
});
let meta_data =
utils::load_or_build_metadata(&config.network_dir, custody_subnet_count, &log);
utils::load_or_build_metadata(&config.network_dir, custody_group_count, &log);
let seq_number = *meta_data.seq_number();
let globals = NetworkGlobals::new(
enr,
@@ -285,26 +282,23 @@ impl<E: EthSpec> Network<E> {
let max_topics = ctx.chain_spec.attestation_subnet_count as usize
+ SYNC_COMMITTEE_SUBNET_COUNT as usize
+ ctx.chain_spec.blob_sidecar_subnet_count as usize
+ ctx.chain_spec.blob_sidecar_subnet_count_max() as usize
+ ctx.chain_spec.data_column_sidecar_subnet_count as usize
+ BASE_CORE_TOPICS.len()
+ ALTAIR_CORE_TOPICS.len()
+ CAPELLA_CORE_TOPICS.len()
+ DENEB_CORE_TOPICS.len()
+ CAPELLA_CORE_TOPICS.len() // 0 core deneb and electra topics
+ LIGHT_CLIENT_GOSSIP_TOPICS.len();
let possible_fork_digests = ctx.fork_context.all_fork_digests();
let filter = gossipsub::MaxCountSubscriptionFilter {
filter: utils::create_whitelist_filter(
possible_fork_digests,
ctx.chain_spec.attestation_subnet_count,
&ctx.chain_spec,
SYNC_COMMITTEE_SUBNET_COUNT,
ctx.chain_spec.blob_sidecar_subnet_count,
ctx.chain_spec.data_column_sidecar_subnet_count,
),
// during a fork we subscribe to both the old and new topics
max_subscribed_topics: max_topics * 4,
// 418 in theory = (64 attestation + 4 sync committee + 7 core topics + 6 blob topics + 128 column topics) * 2
// 424 in theory = (64 attestation + 4 sync committee + 7 core topics + 9 blob topics + 128 column topics) * 2
max_subscriptions_per_request: max_topics * 2,
};
@@ -1852,7 +1846,7 @@ impl<E: EthSpec> Network<E> {
None
}
#[allow(unreachable_patterns)]
BehaviourEvent::ConnectionLimits(le) => void::unreachable(le),
BehaviourEvent::ConnectionLimits(le) => libp2p::core::util::unreachable(le),
},
SwarmEvent::ConnectionEstablished { .. } => None,
SwarmEvent::ConnectionClosed { .. } => None,

View File

@@ -164,8 +164,8 @@ pub fn strip_peer_id(addr: &mut Multiaddr) {
/// Load metadata from persisted file. Return default metadata if loading fails.
pub fn load_or_build_metadata<E: EthSpec>(
network_dir: &std::path::Path,
custody_subnet_count: Option<u64>,
network_dir: &Path,
custody_group_count_opt: Option<u64>,
log: &slog::Logger,
) -> MetaData<E> {
// We load a V2 metadata version by default (regardless of current fork)
@@ -216,12 +216,12 @@ pub fn load_or_build_metadata<E: EthSpec>(
};
// Wrap the MetaData
let meta_data = if let Some(custody_count) = custody_subnet_count {
let meta_data = if let Some(custody_group_count) = custody_group_count_opt {
MetaData::V3(MetaDataV3 {
attnets: meta_data.attnets,
seq_number: meta_data.seq_number,
syncnets: meta_data.syncnets,
custody_subnet_count: custody_count,
custody_group_count,
})
} else {
MetaData::V2(meta_data)
@@ -236,10 +236,8 @@ pub fn load_or_build_metadata<E: EthSpec>(
/// possible fork digests.
pub(crate) fn create_whitelist_filter(
possible_fork_digests: Vec<[u8; 4]>,
attestation_subnet_count: u64,
spec: &ChainSpec,
sync_committee_subnet_count: u64,
blob_sidecar_subnet_count: u64,
data_column_sidecar_subnet_count: u64,
) -> gossipsub::WhitelistSubscriptionFilter {
let mut possible_hashes = HashSet::new();
for fork_digest in possible_fork_digests {
@@ -259,16 +257,17 @@ pub(crate) fn create_whitelist_filter(
add(BlsToExecutionChange);
add(LightClientFinalityUpdate);
add(LightClientOptimisticUpdate);
for id in 0..attestation_subnet_count {
for id in 0..spec.attestation_subnet_count {
add(Attestation(SubnetId::new(id)));
}
for id in 0..sync_committee_subnet_count {
add(SyncCommitteeMessage(SyncSubnetId::new(id)));
}
for id in 0..blob_sidecar_subnet_count {
let blob_subnet_count = spec.blob_sidecar_subnet_count_max();
for id in 0..blob_subnet_count {
add(BlobSidecar(id));
}
for id in 0..data_column_sidecar_subnet_count {
for id in 0..spec.data_column_sidecar_subnet_count {
add(DataColumnSidecar(DataColumnSubnetId::new(id)));
}
}
@@ -283,8 +282,8 @@ pub(crate) fn save_metadata_to_disk<E: EthSpec>(
) {
let _ = std::fs::create_dir_all(dir);
// We always store the metadata v2 to disk because
// custody_subnet_count parameter doesn't need to be persisted across runs.
// custody_subnet_count is what the user sets it for the current run.
// custody_group_count parameter doesn't need to be persisted across runs.
// custody_group_count is what the user sets it for the current run.
// This is to prevent ugly branching logic when reading the metadata from disk.
let metadata_bytes = metadata.metadata_v2().as_ssz_bytes();
match File::create(dir.join(METADATA_FILENAME)).and_then(|mut f| f.write_all(&metadata_bytes)) {