Skip to content

Commit ed5718e

Browse files
jimmygcheneserilev
authored andcommitted
Remove redundant subscribe_all_data_column_subnets field from network (#8259)
Addresses this comment: #8254 (comment) We're currently using `subscribe_all_data_column_subnets` here to subscribe to all subnets https://github.com/sigp/lighthouse/blob/522bd9e9c6ac167f2231525e937c9ebbcb86cf6e/beacon_node/lighthouse_network/src/types/topics.rs#L82-L92 But its unnecessary because the else path also works for supernode (uses `sampling_subnets` instead) The big diffs will disappear once #8254 is merged. Co-Authored-By: Jimmy Chen <[email protected]>
1 parent 4b3dabf commit ed5718e

File tree

8 files changed

+17
-74
lines changed

8 files changed

+17
-74
lines changed

beacon_node/lighthouse_network/src/config.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ pub struct Config {
9494
/// Attempt to construct external port mappings with UPnP.
9595
pub upnp_enabled: bool,
9696

97-
/// Subscribe to all data column subnets for the duration of the runtime.
98-
pub subscribe_all_data_column_subnets: bool,
99-
10097
/// Subscribe to all subnets for the duration of the runtime.
10198
pub subscribe_all_subnets: bool,
10299

@@ -355,7 +352,6 @@ impl Default for Config {
355352
upnp_enabled: true,
356353
network_load: 3,
357354
private: false,
358-
subscribe_all_data_column_subnets: false,
359355
subscribe_all_subnets: false,
360356
import_all_attestations: false,
361357
shutdown_after_sync: false,

beacon_node/lighthouse_network/src/discovery/enr.rs

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub fn build_or_load_enr<E: EthSpec>(
159159
local_key: Keypair,
160160
config: &NetworkConfig,
161161
enr_fork_id: &EnrForkId,
162-
custody_group_count: Option<u64>,
162+
custody_group_count: u64,
163163
next_fork_digest: [u8; 4],
164164
spec: &ChainSpec,
165165
) -> Result<Enr, String> {
@@ -185,7 +185,7 @@ pub fn build_enr<E: EthSpec>(
185185
enr_key: &CombinedKey,
186186
config: &NetworkConfig,
187187
enr_fork_id: &EnrForkId,
188-
custody_group_count: Option<u64>,
188+
custody_group_count: u64,
189189
next_fork_digest: [u8; 4],
190190
spec: &ChainSpec,
191191
) -> Result<Enr, String> {
@@ -280,15 +280,6 @@ pub fn build_enr<E: EthSpec>(
280280

281281
// only set `cgc` and `nfd` if PeerDAS fork (Fulu) epoch has been scheduled
282282
if spec.is_peer_das_scheduled() {
283-
let custody_group_count = if let Some(cgc) = custody_group_count {
284-
cgc
285-
} else if let Some(false_cgc) = config.advertise_false_custody_group_count {
286-
false_cgc
287-
} else if config.subscribe_all_data_column_subnets {
288-
spec.number_of_custody_groups
289-
} else {
290-
spec.custody_requirement
291-
};
292283
builder.add_value(PEERDAS_CUSTODY_GROUP_COUNT_ENR_KEY, &custody_group_count);
293284
builder.add_value(NEXT_FORK_DIGEST_ENR_KEY, &next_fork_digest);
294285
}
@@ -373,7 +364,7 @@ mod test {
373364

374365
fn build_enr_with_config(
375366
config: NetworkConfig,
376-
cgc: Option<u64>,
367+
cgc: u64,
377368
spec: &ChainSpec,
378369
) -> (Enr, CombinedKey) {
379370
let keypair = libp2p::identity::secp256k1::Keypair::generate();
@@ -386,56 +377,23 @@ mod test {
386377
#[test]
387378
fn test_nfd_enr_encoding() {
388379
let spec = make_fulu_spec();
389-
let enr = build_enr_with_config(NetworkConfig::default(), None, &spec).0;
380+
let enr =
381+
build_enr_with_config(NetworkConfig::default(), spec.custody_requirement, &spec).0;
390382
assert_eq!(enr.next_fork_digest().unwrap(), TEST_NFD);
391383
}
392384

393-
#[test]
394-
fn custody_group_count_default() {
395-
let config = NetworkConfig {
396-
subscribe_all_data_column_subnets: false,
397-
..NetworkConfig::default()
398-
};
399-
let spec = make_fulu_spec();
400-
401-
let enr = build_enr_with_config(config, None, &spec).0;
402-
403-
assert_eq!(
404-
enr.custody_group_count::<E>(&spec).unwrap(),
405-
spec.custody_requirement,
406-
);
407-
}
408-
409-
#[test]
410-
fn custody_group_count_all() {
411-
let config = NetworkConfig {
412-
subscribe_all_data_column_subnets: true,
413-
..NetworkConfig::default()
414-
};
415-
let spec = make_fulu_spec();
416-
let enr = build_enr_with_config(config, None, &spec).0;
417-
418-
assert_eq!(
419-
enr.custody_group_count::<E>(&spec).unwrap(),
420-
spec.number_of_custody_groups,
421-
);
422-
}
423-
424385
#[test]
425386
fn custody_group_value() {
426-
let config = NetworkConfig {
427-
subscribe_all_data_column_subnets: true,
428-
..NetworkConfig::default()
429-
};
387+
let config = NetworkConfig::default();
430388
let spec = make_fulu_spec();
431-
let enr = build_enr_with_config(config, Some(42), &spec).0;
389+
let enr = build_enr_with_config(config, 42, &spec).0;
432390

433391
assert_eq!(enr.custody_group_count::<E>(&spec).unwrap(), 42);
434392
}
435393

436394
#[test]
437395
fn test_encode_decode_eth2_enr() {
438-
let (enr, _key) = build_enr_with_config(NetworkConfig::default(), None, &E::default_spec());
396+
let (enr, _key) = build_enr_with_config(NetworkConfig::default(), 4, &E::default_spec());
439397
// Check all Eth2 Mappings are decodeable
440398
enr.eth2().unwrap();
441399
enr.attestation_bitfield::<MainnetEthSpec>().unwrap();

beacon_node/lighthouse_network/src/discovery/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,11 +1243,12 @@ mod tests {
12431243
let config = Arc::new(config);
12441244
let enr_key: CombinedKey = CombinedKey::from_secp256k1(&keypair);
12451245
let next_fork_digest = [0; 4];
1246+
let custody_group_count = spec.custody_requirement;
12461247
let enr: Enr = build_enr::<E>(
12471248
&enr_key,
12481249
&config,
12491250
&EnrForkId::default(),
1250-
None,
1251+
custody_group_count,
12511252
next_fork_digest,
12521253
&spec,
12531254
)
@@ -1258,7 +1259,7 @@ mod tests {
12581259
seq_number: 0,
12591260
attnets: Default::default(),
12601261
syncnets: Default::default(),
1261-
custody_group_count: spec.custody_requirement,
1262+
custody_group_count,
12621263
}),
12631264
vec![],
12641265
false,

beacon_node/lighthouse_network/src/service/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl<E: EthSpec> Network<E> {
199199
local_keypair.clone(),
200200
&config,
201201
&ctx.enr_fork_id,
202-
Some(advertised_cgc),
202+
advertised_cgc,
203203
next_fork_digest,
204204
&ctx.chain_spec,
205205
)?;

beacon_node/lighthouse_network/src/types/globals.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ impl<E: EthSpec> NetworkGlobals<E> {
227227
TopicConfig {
228228
enable_light_client_server: self.config.enable_light_client_server,
229229
subscribe_all_subnets: self.config.subscribe_all_subnets,
230-
subscribe_all_data_column_subnets: self.config.subscribe_all_data_column_subnets,
231230
sampling_subnets: self.sampling_subnets.read().clone(),
232231
}
233232
}

beacon_node/lighthouse_network/src/types/topics.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ pub const LIGHT_CLIENT_OPTIMISTIC_UPDATE: &str = "light_client_optimistic_update
2929
pub struct TopicConfig {
3030
pub enable_light_client_server: bool,
3131
pub subscribe_all_subnets: bool,
32-
pub subscribe_all_data_column_subnets: bool,
3332
pub sampling_subnets: HashSet<DataColumnSubnetId>,
3433
}
3534

@@ -80,14 +79,8 @@ pub fn core_topics_to_subscribe<E: EthSpec>(
8079
}
8180

8281
if fork_name.fulu_enabled() {
83-
if opts.subscribe_all_data_column_subnets {
84-
for i in 0..spec.data_column_sidecar_subnet_count {
85-
topics.push(GossipKind::DataColumnSidecar(i.into()));
86-
}
87-
} else {
88-
for subnet in &opts.sampling_subnets {
89-
topics.push(GossipKind::DataColumnSidecar(*subnet));
90-
}
82+
for subnet in &opts.sampling_subnets {
83+
topics.push(GossipKind::DataColumnSidecar(*subnet));
9184
}
9285
}
9386

@@ -125,7 +118,6 @@ pub fn all_topics_at_fork<E: EthSpec>(fork: ForkName, spec: &ChainSpec) -> Vec<G
125118
let opts = TopicConfig {
126119
enable_light_client_server: true,
127120
subscribe_all_subnets: true,
128-
subscribe_all_data_column_subnets: true,
129121
sampling_subnets,
130122
};
131123
core_topics_to_subscribe::<E>(fork, &opts, spec)
@@ -520,7 +512,6 @@ mod tests {
520512
TopicConfig {
521513
enable_light_client_server: false,
522514
subscribe_all_subnets: false,
523-
subscribe_all_data_column_subnets: false,
524515
sampling_subnets: sampling_subnets.clone(),
525516
}
526517
}
@@ -552,9 +543,8 @@ mod tests {
552543
#[test]
553544
fn columns_are_subscribed_in_peerdas() {
554545
let spec = get_spec();
555-
let s = get_sampling_subnets();
556-
let mut topic_config = get_topic_config(&s);
557-
topic_config.subscribe_all_data_column_subnets = true;
546+
let s = HashSet::from_iter([0.into()]);
547+
let topic_config = get_topic_config(&s);
558548
assert!(
559549
core_topics_to_subscribe::<E>(ForkName::Fulu, &topic_config, &spec)
560550
.contains(&GossipKind::DataColumnSidecar(0.into()))

beacon_node/src/config.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ pub fn get_config<E: EthSpec>(
114114
let is_semi_supernode = parse_flag(cli_args, "semi-supernode");
115115

116116
client_config.chain.node_custody_type = if is_supernode {
117-
client_config.network.subscribe_all_data_column_subnets = true;
118117
NodeCustodyType::Supernode
119118
} else if is_semi_supernode {
120119
NodeCustodyType::SemiSupernode

lcli/src/generate_bootnode_enr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn run<E: EthSpec>(matches: &ArgMatches, spec: &ChainSpec) -> Result<(), Str
4343
&enr_key,
4444
&config,
4545
&enr_fork_id,
46-
None,
46+
spec.custody_requirement,
4747
genesis_fork_digest,
4848
spec,
4949
)

0 commit comments

Comments
 (0)