@@ -159,14 +159,22 @@ pub fn build_or_load_enr<E: EthSpec>(
159
159
local_key : Keypair ,
160
160
config : & NetworkConfig ,
161
161
enr_fork_id : & EnrForkId ,
162
+ custody_group_count : Option < u64 > ,
162
163
next_fork_digest : [ u8 ; 4 ] ,
163
164
spec : & ChainSpec ,
164
165
) -> Result < Enr , String > {
165
166
// Build the local ENR.
166
167
// Note: Discovery should update the ENR record's IP to the external IP as seen by the
167
168
// majority of our peers, if the CLI doesn't expressly forbid it.
168
169
let enr_key = CombinedKey :: from_libp2p ( local_key) ?;
169
- let mut local_enr = build_enr :: < E > ( & enr_key, config, enr_fork_id, next_fork_digest, spec) ?;
170
+ let mut local_enr = build_enr :: < E > (
171
+ & enr_key,
172
+ config,
173
+ enr_fork_id,
174
+ custody_group_count,
175
+ next_fork_digest,
176
+ spec,
177
+ ) ?;
170
178
171
179
use_or_load_enr ( & enr_key, & mut local_enr, config) ?;
172
180
Ok ( local_enr)
@@ -177,6 +185,7 @@ pub fn build_enr<E: EthSpec>(
177
185
enr_key : & CombinedKey ,
178
186
config : & NetworkConfig ,
179
187
enr_fork_id : & EnrForkId ,
188
+ custody_group_count : Option < u64 > ,
180
189
next_fork_digest : [ u8 ; 4 ] ,
181
190
spec : & ChainSpec ,
182
191
) -> Result < Enr , String > {
@@ -271,14 +280,15 @@ pub fn build_enr<E: EthSpec>(
271
280
272
281
// only set `cgc` and `nfd` if PeerDAS fork (Fulu) epoch has been scheduled
273
282
if spec. is_peer_das_scheduled ( ) {
274
- let custody_group_count =
275
- if let Some ( false_cgc) = config. advertise_false_custody_group_count {
276
- false_cgc
277
- } else if config. subscribe_all_data_column_subnets {
278
- spec. number_of_custody_groups
279
- } else {
280
- spec. custody_requirement
281
- } ;
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
+ } ;
282
292
builder. add_value ( PEERDAS_CUSTODY_GROUP_COUNT_ENR_KEY , & custody_group_count) ;
283
293
builder. add_value ( NEXT_FORK_DIGEST_ENR_KEY , & next_fork_digest) ;
284
294
}
@@ -361,18 +371,22 @@ mod test {
361
371
spec
362
372
}
363
373
364
- fn build_enr_with_config ( config : NetworkConfig , spec : & ChainSpec ) -> ( Enr , CombinedKey ) {
374
+ fn build_enr_with_config (
375
+ config : NetworkConfig ,
376
+ cgc : Option < u64 > ,
377
+ spec : & ChainSpec ,
378
+ ) -> ( Enr , CombinedKey ) {
365
379
let keypair = libp2p:: identity:: secp256k1:: Keypair :: generate ( ) ;
366
380
let enr_key = CombinedKey :: from_secp256k1 ( & keypair) ;
367
381
let enr_fork_id = EnrForkId :: default ( ) ;
368
- let enr = build_enr :: < E > ( & enr_key, & config, & enr_fork_id, TEST_NFD , spec) . unwrap ( ) ;
382
+ let enr = build_enr :: < E > ( & enr_key, & config, & enr_fork_id, cgc , TEST_NFD , spec) . unwrap ( ) ;
369
383
( enr, enr_key)
370
384
}
371
385
372
386
#[ test]
373
387
fn test_nfd_enr_encoding ( ) {
374
388
let spec = make_fulu_spec ( ) ;
375
- let enr = build_enr_with_config ( NetworkConfig :: default ( ) , & spec) . 0 ;
389
+ let enr = build_enr_with_config ( NetworkConfig :: default ( ) , None , & spec) . 0 ;
376
390
assert_eq ! ( enr. next_fork_digest( ) . unwrap( ) , TEST_NFD ) ;
377
391
}
378
392
@@ -384,7 +398,7 @@ mod test {
384
398
} ;
385
399
let spec = make_fulu_spec ( ) ;
386
400
387
- let enr = build_enr_with_config ( config, & spec) . 0 ;
401
+ let enr = build_enr_with_config ( config, None , & spec) . 0 ;
388
402
389
403
assert_eq ! (
390
404
enr. custody_group_count:: <E >( & spec) . unwrap( ) ,
@@ -399,17 +413,29 @@ mod test {
399
413
..NetworkConfig :: default ( )
400
414
} ;
401
415
let spec = make_fulu_spec ( ) ;
402
- let enr = build_enr_with_config ( config, & spec) . 0 ;
416
+ let enr = build_enr_with_config ( config, None , & spec) . 0 ;
403
417
404
418
assert_eq ! (
405
419
enr. custody_group_count:: <E >( & spec) . unwrap( ) ,
406
420
spec. number_of_custody_groups,
407
421
) ;
408
422
}
409
423
424
+ #[ test]
425
+ fn custody_group_value ( ) {
426
+ let config = NetworkConfig {
427
+ subscribe_all_data_column_subnets : true ,
428
+ ..NetworkConfig :: default ( )
429
+ } ;
430
+ let spec = make_fulu_spec ( ) ;
431
+ let enr = build_enr_with_config ( config, Some ( 42 ) , & spec) . 0 ;
432
+
433
+ assert_eq ! ( enr. custody_group_count:: <E >( & spec) . unwrap( ) , 42 ) ;
434
+ }
435
+
410
436
#[ test]
411
437
fn test_encode_decode_eth2_enr ( ) {
412
- let ( enr, _key) = build_enr_with_config ( NetworkConfig :: default ( ) , & E :: default_spec ( ) ) ;
438
+ let ( enr, _key) = build_enr_with_config ( NetworkConfig :: default ( ) , None , & E :: default_spec ( ) ) ;
413
439
// Check all Eth2 Mappings are decodeable
414
440
enr. eth2 ( ) . unwrap ( ) ;
415
441
enr. attestation_bitfield :: < MainnetEthSpec > ( ) . unwrap ( ) ;
0 commit comments