Skip to content

Commit a2987d6

Browse files
committed
Advertise false CGC for testing.
1 parent 9803d69 commit a2987d6

File tree

9 files changed

+67
-40
lines changed

9 files changed

+67
-40
lines changed

beacon_node/lighthouse_network/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ pub struct Config {
139139
/// Configuration for the minimum message size for which IDONTWANT messages are send in the mesh.
140140
/// Lower the value reduces the optimization effect of the IDONTWANT messages.
141141
pub idontwant_message_size_threshold: usize,
142+
143+
/// Flag for advertising a fake CGC to peers for testing ONLY.
144+
pub advertise_false_custody_group_count: Option<u64>,
142145
}
143146

144147
impl Config {
@@ -363,6 +366,7 @@ impl Default for Config {
363366
invalid_block_storage: None,
364367
inbound_rate_limiter_config: None,
365368
idontwant_message_size_threshold: DEFAULT_IDONTWANT_MESSAGE_SIZE_THRESHOLD,
369+
advertise_false_custody_group_count: None,
366370
}
367371
}
368372
}

beacon_node/lighthouse_network/src/discovery/enr.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,14 @@ pub fn build_enr<E: EthSpec>(
259259

260260
// only set `cgc` if PeerDAS fork epoch has been scheduled
261261
if spec.is_peer_das_scheduled() {
262-
let custody_group_count = if config.subscribe_all_data_column_subnets {
263-
spec.number_of_custody_groups
264-
} else {
265-
spec.custody_requirement
266-
};
262+
let custody_group_count =
263+
if let Some(false_cgc) = config.advertise_false_custody_group_count {
264+
false_cgc
265+
} else if config.subscribe_all_data_column_subnets {
266+
spec.number_of_custody_groups
267+
} else {
268+
spec.custody_requirement
269+
};
267270
builder.add_value(PEERDAS_CUSTODY_GROUP_COUNT_ENR_KEY, &custody_group_count);
268271
}
269272

beacon_node/lighthouse_network/src/rpc/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ use tracing::{debug, error, instrument, trace};
2121
use types::{EthSpec, ForkContext};
2222

2323
pub(crate) use handler::{HandlerErr, HandlerEvent};
24-
pub(crate) use methods::{
25-
MetaData, MetaDataV1, MetaDataV2, MetaDataV3, Ping, RpcResponse, RpcSuccessResponse,
26-
};
24+
pub(crate) use methods::{MetaData, MetaDataV2, MetaDataV3, Ping, RpcResponse, RpcSuccessResponse};
2725
pub use protocol::RequestType;
2826

2927
use self::config::{InboundRateLimiterConfig, OutboundRateLimiterConfig};

beacon_node/lighthouse_network/src/service/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,10 @@ impl<E: EthSpec> Network<E> {
202202
)?;
203203

204204
// Construct the metadata
205-
let custody_group_count_metadata = ctx
206-
.chain_spec
207-
.is_peer_das_scheduled()
208-
.then_some(custody_group_count);
209-
let meta_data =
210-
utils::load_or_build_metadata(&config.network_dir, custody_group_count_metadata);
205+
let advertised_cgc = config
206+
.advertise_false_custody_group_count
207+
.unwrap_or(custody_group_count);
208+
let meta_data = utils::load_or_build_metadata(&config.network_dir, advertised_cgc);
211209
let seq_number = *meta_data.seq_number();
212210
let globals = NetworkGlobals::new(
213211
enr,

beacon_node/lighthouse_network/src/service/utils.rs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::multiaddr::Protocol;
2-
use crate::rpc::methods::MetaDataV3;
3-
use crate::rpc::{MetaData, MetaDataV1, MetaDataV2};
2+
use crate::rpc::{MetaData, MetaDataV2, MetaDataV3};
43
use crate::types::{EnrAttestationBitfield, EnrSyncCommitteeBitfield, GossipEncoding, GossipKind};
54
use crate::{GossipTopic, NetworkConfig};
65
use futures::future::Either;
@@ -165,38 +164,41 @@ pub fn strip_peer_id(addr: &mut Multiaddr) {
165164
/// Load metadata from persisted file. Return default metadata if loading fails.
166165
pub fn load_or_build_metadata<E: EthSpec>(
167166
network_dir: &Path,
168-
custody_group_count_opt: Option<u64>,
167+
custody_group_count: u64,
169168
) -> MetaData<E> {
170-
// We load a V2 metadata version by default (regardless of current fork)
171-
// since a V2 metadata can be converted to V1. The RPC encoder is responsible
169+
// We load a V3 metadata version by default (regardless of current fork)
170+
// since a V3 metadata can be converted to V1 or V2. The RPC encoder is responsible
172171
// for sending the correct metadata version based on the negotiated protocol version.
173-
let mut meta_data = MetaDataV2 {
172+
let mut meta_data = MetaDataV3 {
174173
seq_number: 0,
175174
attnets: EnrAttestationBitfield::<E>::default(),
176175
syncnets: EnrSyncCommitteeBitfield::<E>::default(),
176+
custody_group_count,
177177
};
178+
178179
// Read metadata from persisted file if available
179180
let metadata_path = network_dir.join(METADATA_FILENAME);
180181
if let Ok(mut metadata_file) = File::open(metadata_path) {
181182
let mut metadata_ssz = Vec::new();
182183
if metadata_file.read_to_end(&mut metadata_ssz).is_ok() {
183-
// Attempt to read a MetaDataV2 version from the persisted file,
184-
// if that fails, read MetaDataV1
185-
match MetaDataV2::<E>::from_ssz_bytes(&metadata_ssz) {
184+
// Attempt to read a MetaDataV3 version from the persisted file,
185+
// if that fails, read MetaDataV2
186+
match MetaDataV3::<E>::from_ssz_bytes(&metadata_ssz) {
186187
Ok(persisted_metadata) => {
187188
meta_data.seq_number = persisted_metadata.seq_number;
188189
// Increment seq number if persisted attnet is not default
189190
if persisted_metadata.attnets != meta_data.attnets
190191
|| persisted_metadata.syncnets != meta_data.syncnets
192+
|| persisted_metadata.custody_group_count != meta_data.custody_group_count
191193
{
192194
meta_data.seq_number += 1;
193195
}
194196
debug!("Loaded metadata from disk");
195197
}
196198
Err(_) => {
197-
match MetaDataV1::<E>::from_ssz_bytes(&metadata_ssz) {
199+
match MetaDataV2::<E>::from_ssz_bytes(&metadata_ssz) {
198200
Ok(persisted_metadata) => {
199-
let persisted_metadata = MetaData::V1(persisted_metadata);
201+
let persisted_metadata = MetaData::V2(persisted_metadata);
200202
// Increment seq number as the persisted metadata version is updated
201203
meta_data.seq_number = *persisted_metadata.seq_number() + 1;
202204
debug!("Loaded metadata from disk");
@@ -213,19 +215,8 @@ pub fn load_or_build_metadata<E: EthSpec>(
213215
}
214216
};
215217

216-
// Wrap the MetaData
217-
let meta_data = if let Some(custody_group_count) = custody_group_count_opt {
218-
MetaData::V3(MetaDataV3 {
219-
attnets: meta_data.attnets,
220-
seq_number: meta_data.seq_number,
221-
syncnets: meta_data.syncnets,
222-
custody_group_count,
223-
})
224-
} else {
225-
MetaData::V2(meta_data)
226-
};
227-
228-
debug!(seq_num = meta_data.seq_number(), "Metadata sequence number");
218+
debug!(seq_num = meta_data.seq_number, "Metadata sequence number");
219+
let meta_data = MetaData::V3(meta_data);
229220
save_metadata_to_disk(network_dir, meta_data.clone());
230221
meta_data
231222
}

beacon_node/network/src/service.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,14 @@ impl<T: BeaconChainTypes> NetworkService<T> {
767767
// subscribe to `sampling_count` subnets
768768
self.libp2p
769769
.subscribe_new_data_column_subnets(sampling_count);
770-
self.libp2p.update_enr_cgc(new_custody_group_count);
770+
if self
771+
.network_globals
772+
.config
773+
.advertise_false_custody_group_count
774+
.is_none()
775+
{
776+
self.libp2p.update_enr_cgc(new_custody_group_count);
777+
}
771778
}
772779
}
773780
}

beacon_node/src/cli.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ pub fn cli_app() -> Command {
6868
.hide(true)
6969
.display_order(0)
7070
)
71+
.arg(
72+
// TODO(das): remove this before PeerDAS release
73+
Arg::new("advertise-false-custody-group-count")
74+
.long("advertise-false-custody-group-count")
75+
.action(ArgAction::Set)
76+
.help_heading(FLAG_HEADER)
77+
.help("Advertises a false CGC for testing PeerDAS. Do NOT use in production.")
78+
.hide(true)
79+
.display_order(0)
80+
)
7181
.arg(
7282
Arg::new("enable-sampling")
7383
.long("enable-sampling")

beacon_node/src/config.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use beacon_chain::graffiti_calculator::GraffitiOrigin;
88
use beacon_chain::TrustedSetup;
99
use clap::{parser::ValueSource, ArgMatches, Id};
1010
use clap_utils::flags::DISABLE_MALLOC_TUNING_FLAG;
11-
use clap_utils::{parse_flag, parse_required};
11+
use clap_utils::{parse_flag, parse_optional, parse_required};
1212
use client::{ClientConfig, ClientGenesis};
1313
use directory::{DEFAULT_BEACON_NODE_DIR, DEFAULT_NETWORK_DIR, DEFAULT_ROOT_DIR};
1414
use environment::RuntimeContext;
@@ -1197,6 +1197,12 @@ pub fn set_network_config(
11971197
config.import_all_attestations = true;
11981198
}
11991199

1200+
if let Some(advertise_false_custody_group_count) =
1201+
parse_optional(cli_args, "advertise-false-custody-group-count")?
1202+
{
1203+
config.advertise_false_custody_group_count = Some(advertise_false_custody_group_count);
1204+
}
1205+
12001206
if parse_flag(cli_args, "shutdown-after-sync") {
12011207
config.shutdown_after_sync = true;
12021208
}

lighthouse/tests/beacon_node.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,6 +2679,16 @@ fn invalid_gossip_verified_blocks_path() {
26792679
});
26802680
}
26812681

2682+
#[test]
2683+
fn advertise_false_custody_group_count() {
2684+
CommandLineTest::new()
2685+
.flag("advertise-false-custody-group-count", Some("64"))
2686+
.run_with_zero_port()
2687+
.with_config(|config| {
2688+
assert_eq!(config.network.advertise_false_custody_group_count, Some(64))
2689+
});
2690+
}
2691+
26822692
#[test]
26832693
fn beacon_processor() {
26842694
CommandLineTest::new()

0 commit comments

Comments
 (0)