Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions beacon_node/lighthouse_network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>,
}

impl Config {
Expand Down Expand Up @@ -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,
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions beacon_node/lighthouse_network/src/discovery/enr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,14 @@ pub fn build_enr<E: EthSpec>(

// 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);
}

Expand Down
4 changes: 1 addition & 3 deletions beacon_node/lighthouse_network/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
10 changes: 4 additions & 6 deletions beacon_node/lighthouse_network/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,10 @@ impl<E: EthSpec> Network<E> {
)?;

// 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,
Expand Down
39 changes: 15 additions & 24 deletions beacon_node/lighthouse_network/src/service/utils.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<E: EthSpec>(
network_dir: &Path,
custody_group_count_opt: Option<u64>,
custody_group_count: u64,
) -> MetaData<E> {
// 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::<E>::default(),
syncnets: EnrSyncCommitteeBitfield::<E>::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::<E>::from_ssz_bytes(&metadata_ssz) {
// Attempt to read a MetaDataV3 version from the persisted file,
// if that fails, read MetaDataV2
match MetaDataV3::<E>::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::<E>::from_ssz_bytes(&metadata_ssz) {
match MetaDataV2::<E>::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");
Expand All @@ -213,19 +215,8 @@ pub fn load_or_build_metadata<E: EthSpec>(
}
};

// 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
}
Expand Down
9 changes: 8 additions & 1 deletion beacon_node/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,14 @@ impl<T: BeaconChainTypes> NetworkService<T> {
// 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);
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions beacon_node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 7 additions & 1 deletion beacon_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions lighthouse/tests/beacon_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down