Modularize CGC logic in network service

This commit is contained in:
dapplion
2025-04-10 18:47:54 -03:00
parent 1c7d47052f
commit 630c79d110
7 changed files with 336 additions and 138 deletions

View File

@@ -931,8 +931,10 @@ impl<E: EthSpec> Network<E> {
warn!(%topic, error = ?e, "Failed to subscribe to topic");
false
}
Ok(_) => {
debug!(%topic, "Subscribed to topic");
Ok(new_subscription) => {
if new_subscription {
debug!(%topic, "Subscribed to topic");
}
true
}
}

View File

@@ -7,6 +7,7 @@ use crate::{Client, Enr, EnrExt, GossipTopic, Multiaddr, NetworkConfig, PeerId};
use local_metadata::LocalMetadata;
use parking_lot::RwLock;
use std::collections::HashSet;
use std::ops::Range;
use std::sync::Arc;
use types::data_column_custody_group::{
compute_columns_from_custody_groups, compute_subnets_from_custody_groups, get_custody_groups,
@@ -141,6 +142,12 @@ impl<E: EthSpec> NetworkGlobals<E> {
self.cgc_updates.read().at_slot(slot)
}
/// Returns the minimum CGC value in the range of slots `range`. If the range is empty,
/// i.e. `3..1` returns the CGC value at `range.start`.
pub fn min_custody_group_count_at_range(&self, slot_range: Range<Slot>) -> u64 {
self.cgc_updates.read().min_at_slot_range(slot_range)
}
/// Returns the count of custody columns this node must sample for block import
pub fn custody_columns_count(&self, slot: Slot) -> u64 {
// This only panics if the chain spec contains invalid values
@@ -164,6 +171,10 @@ impl<E: EthSpec> NetworkGlobals<E> {
self.cgc_updates.read().clone()
}
pub fn cgc_updates_len(&self) -> usize {
self.cgc_updates.read().len()
}
/// Returns the number of libp2p connected peers.
pub fn connected_peers(&self) -> usize {
self.peers.read().connected_peer_ids().count()

View File

@@ -195,6 +195,27 @@ impl std::fmt::Display for GossipKind {
}
}
impl GossipKind {
/// Returns the ForkName after which this GossipKind can form a valid topic
pub fn fork_activation(&self) -> ForkName {
match self {
Self::BeaconBlock => ForkName::Base,
Self::BeaconAggregateAndProof => ForkName::Base,
Self::BlobSidecar(_) => ForkName::Deneb,
Self::DataColumnSidecar(_) => ForkName::Fulu,
Self::Attestation(_) => ForkName::Base,
Self::VoluntaryExit => ForkName::Base,
Self::ProposerSlashing => ForkName::Base,
Self::AttesterSlashing => ForkName::Base,
Self::SignedContributionAndProof => ForkName::Altair,
Self::SyncCommitteeMessage(_) => ForkName::Altair,
Self::BlsToExecutionChange => ForkName::Capella,
Self::LightClientFinalityUpdate => ForkName::Altair,
Self::LightClientOptimisticUpdate => ForkName::Altair,
}
}
}
/// The known encoding types for gossipsub messages.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash, Default)]
pub enum GossipEncoding {