From 3d2d65bf8d2499c900f78d6728536ee62f33585d Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Mon, 16 Jun 2025 12:10:28 +0100 Subject: [PATCH] Advertise `--advertise-false-custody-group-count` for testing PeerDAS (#7593) #6973 --- beacon_node/lighthouse_network/src/config.rs | 4 ++ .../lighthouse_network/src/discovery/enr.rs | 13 ++++--- beacon_node/lighthouse_network/src/rpc/mod.rs | 4 +- .../lighthouse_network/src/service/mod.rs | 10 ++--- .../lighthouse_network/src/service/utils.rs | 39 +++++++------------ beacon_node/network/src/service.rs | 9 ++++- beacon_node/src/cli.rs | 10 +++++ beacon_node/src/config.rs | 8 +++- lighthouse/tests/beacon_node.rs | 10 +++++ 9 files changed, 67 insertions(+), 40 deletions(-) diff --git a/beacon_node/lighthouse_network/src/config.rs b/beacon_node/lighthouse_network/src/config.rs index 89d260569a..bd72a5d51a 100644 --- a/beacon_node/lighthouse_network/src/config.rs +++ b/beacon_node/lighthouse_network/src/config.rs @@ -139,6 +139,9 @@ pub struct Config { /// Configuration for the minimum message size for which IDONTWANT messages are send in the mesh. /// Lower the value reduces the optimization effect of the IDONTWANT messages. pub idontwant_message_size_threshold: usize, + + /// Flag for advertising a fake CGC to peers for testing ONLY. + pub advertise_false_custody_group_count: Option, } impl Config { @@ -363,6 +366,7 @@ impl Default for Config { invalid_block_storage: None, inbound_rate_limiter_config: None, idontwant_message_size_threshold: DEFAULT_IDONTWANT_MESSAGE_SIZE_THRESHOLD, + advertise_false_custody_group_count: None, } } } diff --git a/beacon_node/lighthouse_network/src/discovery/enr.rs b/beacon_node/lighthouse_network/src/discovery/enr.rs index e70c8047e0..5628d5c463 100644 --- a/beacon_node/lighthouse_network/src/discovery/enr.rs +++ b/beacon_node/lighthouse_network/src/discovery/enr.rs @@ -259,11 +259,14 @@ pub fn build_enr( // only set `cgc` if PeerDAS fork epoch has been scheduled if spec.is_peer_das_scheduled() { - let custody_group_count = if config.subscribe_all_data_column_subnets { - spec.number_of_custody_groups - } else { - spec.custody_requirement - }; + let custody_group_count = + if let Some(false_cgc) = config.advertise_false_custody_group_count { + false_cgc + } else if config.subscribe_all_data_column_subnets { + spec.number_of_custody_groups + } else { + spec.custody_requirement + }; builder.add_value(PEERDAS_CUSTODY_GROUP_COUNT_ENR_KEY, &custody_group_count); } diff --git a/beacon_node/lighthouse_network/src/rpc/mod.rs b/beacon_node/lighthouse_network/src/rpc/mod.rs index 8cb720132a..0619908bb6 100644 --- a/beacon_node/lighthouse_network/src/rpc/mod.rs +++ b/beacon_node/lighthouse_network/src/rpc/mod.rs @@ -21,9 +21,7 @@ use tracing::{debug, error, instrument, trace}; use types::{EthSpec, ForkContext}; pub(crate) use handler::{HandlerErr, HandlerEvent}; -pub(crate) use methods::{ - MetaData, MetaDataV1, MetaDataV2, MetaDataV3, Ping, RpcResponse, RpcSuccessResponse, -}; +pub(crate) use methods::{MetaData, MetaDataV2, MetaDataV3, Ping, RpcResponse, RpcSuccessResponse}; pub use protocol::RequestType; use self::config::{InboundRateLimiterConfig, OutboundRateLimiterConfig}; diff --git a/beacon_node/lighthouse_network/src/service/mod.rs b/beacon_node/lighthouse_network/src/service/mod.rs index 5f65a6c6d0..e2c6f24405 100644 --- a/beacon_node/lighthouse_network/src/service/mod.rs +++ b/beacon_node/lighthouse_network/src/service/mod.rs @@ -202,12 +202,10 @@ impl Network { )?; // Construct the metadata - let custody_group_count_metadata = ctx - .chain_spec - .is_peer_das_scheduled() - .then_some(custody_group_count); - let meta_data = - utils::load_or_build_metadata(&config.network_dir, custody_group_count_metadata); + let advertised_cgc = config + .advertise_false_custody_group_count + .unwrap_or(custody_group_count); + let meta_data = utils::load_or_build_metadata(&config.network_dir, advertised_cgc); let seq_number = *meta_data.seq_number(); let globals = NetworkGlobals::new( enr, diff --git a/beacon_node/lighthouse_network/src/service/utils.rs b/beacon_node/lighthouse_network/src/service/utils.rs index 01929bcb01..9a93936874 100644 --- a/beacon_node/lighthouse_network/src/service/utils.rs +++ b/beacon_node/lighthouse_network/src/service/utils.rs @@ -1,6 +1,5 @@ use crate::multiaddr::Protocol; -use crate::rpc::methods::MetaDataV3; -use crate::rpc::{MetaData, MetaDataV1, MetaDataV2}; +use crate::rpc::{MetaData, MetaDataV2, MetaDataV3}; use crate::types::{EnrAttestationBitfield, EnrSyncCommitteeBitfield, GossipEncoding, GossipKind}; use crate::{GossipTopic, NetworkConfig}; use futures::future::Either; @@ -165,38 +164,41 @@ 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( network_dir: &Path, - custody_group_count_opt: Option, + custody_group_count: u64, ) -> MetaData { - // We load a V2 metadata version by default (regardless of current fork) - // since a V2 metadata can be converted to V1. The RPC encoder is responsible + // We load a V3 metadata version by default (regardless of current fork) + // since a V3 metadata can be converted to V1 or V2. The RPC encoder is responsible // for sending the correct metadata version based on the negotiated protocol version. - let mut meta_data = MetaDataV2 { + let mut meta_data = MetaDataV3 { seq_number: 0, attnets: EnrAttestationBitfield::::default(), syncnets: EnrSyncCommitteeBitfield::::default(), + custody_group_count, }; + // Read metadata from persisted file if available let metadata_path = network_dir.join(METADATA_FILENAME); if let Ok(mut metadata_file) = File::open(metadata_path) { let mut metadata_ssz = Vec::new(); if metadata_file.read_to_end(&mut metadata_ssz).is_ok() { - // Attempt to read a MetaDataV2 version from the persisted file, - // if that fails, read MetaDataV1 - match MetaDataV2::::from_ssz_bytes(&metadata_ssz) { + // Attempt to read a MetaDataV3 version from the persisted file, + // if that fails, read MetaDataV2 + match MetaDataV3::::from_ssz_bytes(&metadata_ssz) { Ok(persisted_metadata) => { meta_data.seq_number = persisted_metadata.seq_number; // Increment seq number if persisted attnet is not default if persisted_metadata.attnets != meta_data.attnets || persisted_metadata.syncnets != meta_data.syncnets + || persisted_metadata.custody_group_count != meta_data.custody_group_count { meta_data.seq_number += 1; } debug!("Loaded metadata from disk"); } Err(_) => { - match MetaDataV1::::from_ssz_bytes(&metadata_ssz) { + match MetaDataV2::::from_ssz_bytes(&metadata_ssz) { Ok(persisted_metadata) => { - let persisted_metadata = MetaData::V1(persisted_metadata); + let persisted_metadata = MetaData::V2(persisted_metadata); // Increment seq number as the persisted metadata version is updated meta_data.seq_number = *persisted_metadata.seq_number() + 1; debug!("Loaded metadata from disk"); @@ -213,19 +215,8 @@ pub fn load_or_build_metadata( } }; - // Wrap the MetaData - 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_group_count, - }) - } else { - MetaData::V2(meta_data) - }; - - debug!(seq_num = meta_data.seq_number(), "Metadata sequence number"); + debug!(seq_num = meta_data.seq_number, "Metadata sequence number"); + let meta_data = MetaData::V3(meta_data); save_metadata_to_disk(network_dir, meta_data.clone()); meta_data } diff --git a/beacon_node/network/src/service.rs b/beacon_node/network/src/service.rs index c9f89ad668..ba96ce4731 100644 --- a/beacon_node/network/src/service.rs +++ b/beacon_node/network/src/service.rs @@ -767,7 +767,14 @@ impl NetworkService { // subscribe to `sampling_count` subnets self.libp2p .subscribe_new_data_column_subnets(sampling_count); - self.libp2p.update_enr_cgc(new_custody_group_count); + if self + .network_globals + .config + .advertise_false_custody_group_count + .is_none() + { + self.libp2p.update_enr_cgc(new_custody_group_count); + } } } } diff --git a/beacon_node/src/cli.rs b/beacon_node/src/cli.rs index 7d086dcc32..9dbbcd15e7 100644 --- a/beacon_node/src/cli.rs +++ b/beacon_node/src/cli.rs @@ -68,6 +68,16 @@ pub fn cli_app() -> Command { .hide(true) .display_order(0) ) + .arg( + // TODO(das): remove this before PeerDAS release + Arg::new("advertise-false-custody-group-count") + .long("advertise-false-custody-group-count") + .action(ArgAction::Set) + .help_heading(FLAG_HEADER) + .help("Advertises a false CGC for testing PeerDAS. Do NOT use in production.") + .hide(true) + .display_order(0) + ) .arg( Arg::new("enable-sampling") .long("enable-sampling") diff --git a/beacon_node/src/config.rs b/beacon_node/src/config.rs index e887aa9abc..fbe22edd95 100644 --- a/beacon_node/src/config.rs +++ b/beacon_node/src/config.rs @@ -8,7 +8,7 @@ use beacon_chain::graffiti_calculator::GraffitiOrigin; use beacon_chain::TrustedSetup; use clap::{parser::ValueSource, ArgMatches, Id}; use clap_utils::flags::DISABLE_MALLOC_TUNING_FLAG; -use clap_utils::{parse_flag, parse_required}; +use clap_utils::{parse_flag, parse_optional, parse_required}; use client::{ClientConfig, ClientGenesis}; use directory::{DEFAULT_BEACON_NODE_DIR, DEFAULT_NETWORK_DIR, DEFAULT_ROOT_DIR}; use environment::RuntimeContext; @@ -1197,6 +1197,12 @@ pub fn set_network_config( config.import_all_attestations = true; } + if let Some(advertise_false_custody_group_count) = + parse_optional(cli_args, "advertise-false-custody-group-count")? + { + config.advertise_false_custody_group_count = Some(advertise_false_custody_group_count); + } + if parse_flag(cli_args, "shutdown-after-sync") { config.shutdown_after_sync = true; } diff --git a/lighthouse/tests/beacon_node.rs b/lighthouse/tests/beacon_node.rs index ea4716c010..c7654c7b7a 100644 --- a/lighthouse/tests/beacon_node.rs +++ b/lighthouse/tests/beacon_node.rs @@ -2679,6 +2679,16 @@ fn invalid_gossip_verified_blocks_path() { }); } +#[test] +fn advertise_false_custody_group_count() { + CommandLineTest::new() + .flag("advertise-false-custody-group-count", Some("64")) + .run_with_zero_port() + .with_config(|config| { + assert_eq!(config.network.advertise_false_custody_group_count, Some(64)) + }); +} + #[test] fn beacon_processor() { CommandLineTest::new()