@@ -7,9 +7,6 @@ use beacon_chain::{
77} ;
88use genesis:: { generate_deterministic_keypairs, interop_genesis_state, DEFAULT_ETH1_BLOCK_HASH } ;
99use lighthouse_network:: NetworkConfig ;
10- use logging:: test_logger;
11- use slog:: { o, Drain , Logger } ;
12- use sloggers:: { null:: NullLoggerBuilder , Build } ;
1310use slot_clock:: { SlotClock , SystemTimeSlotClock } ;
1411use std:: sync:: { Arc , LazyLock } ;
1512use std:: time:: { Duration , SystemTime } ;
@@ -21,10 +18,6 @@ use types::{
2118 SyncCommitteeSubscription , SyncSubnetId , ValidatorSubscription ,
2219} ;
2320
24- // Set to enable/disable logging
25- // const TEST_LOG_LEVEL: Option<slog::Level> = Some(slog::Level::Debug);
26- const TEST_LOG_LEVEL : Option < slog:: Level > = None ;
27-
2821const SLOT_DURATION_MILLIS : u64 = 400 ;
2922
3023type TestBeaconChainType = Witness <
@@ -46,7 +39,7 @@ impl TestBeaconChain {
4639
4740 let keypairs = generate_deterministic_keypairs ( 1 ) ;
4841
49- let log = get_logger ( TEST_LOG_LEVEL ) ;
42+ let log = logging :: test_logger ( ) ;
5043 let store =
5144 HotColdDB :: open_ephemeral ( StoreConfig :: default ( ) , spec. clone ( ) , log. clone ( ) ) . unwrap ( ) ;
5245
@@ -98,28 +91,10 @@ pub fn recent_genesis_time() -> u64 {
9891 . as_secs ( )
9992}
10093
101- fn get_logger ( log_level : Option < slog:: Level > ) -> Logger {
102- if let Some ( level) = log_level {
103- let drain = {
104- let decorator = slog_term:: TermDecorator :: new ( ) . build ( ) ;
105- let decorator =
106- logging:: AlignedTermDecorator :: new ( decorator, logging:: MAX_MESSAGE_WIDTH ) ;
107- let drain = slog_term:: FullFormat :: new ( decorator) . build ( ) . fuse ( ) ;
108- let drain = slog_async:: Async :: new ( drain) . chan_size ( 2048 ) . build ( ) ;
109- drain. filter_level ( level)
110- } ;
111-
112- Logger :: root ( drain. fuse ( ) , o ! ( ) )
113- } else {
114- let builder = NullLoggerBuilder ;
115- builder. build ( ) . expect ( "should build logger" )
116- }
117- }
118-
11994static CHAIN : LazyLock < TestBeaconChain > = LazyLock :: new ( TestBeaconChain :: new_with_system_clock) ;
12095
12196fn get_subnet_service ( ) -> SubnetService < TestBeaconChainType > {
122- let log = test_logger ( ) ;
97+ let log = logging :: test_logger ( ) ;
12398 let config = NetworkConfig :: default ( ) ;
12499
125100 let beacon_chain = CHAIN . chain . clone ( ) ;
@@ -501,8 +476,6 @@ mod test {
501476 let committee_count = 1 ;
502477
503478 // Makes 3 validator subscriptions to the same subnet but at different slots.
504- // There should be just 1 unsubscription event for each of the later slots subscriptions
505- // (subscription_slot2 and subscription_slot3).
506479 let subscription_slot1 = 0 ;
507480 let subscription_slot2 = MIN_PEER_DISCOVERY_SLOT_LOOK_AHEAD + 4 ;
508481 let subscription_slot3 = subscription_slot2 * 2 ;
@@ -585,7 +558,7 @@ mod test {
585558 let expected_unsubscription =
586559 SubnetServiceMessage :: Unsubscribe ( Subnet :: Attestation ( subnet_id1) ) ;
587560
588- if !subnet_service. is_subscribed ( & Subnet :: Attestation ( subnet_id1) ) {
561+ if !subnet_service. is_subscribed_permanent ( & Subnet :: Attestation ( subnet_id1) ) {
589562 assert_eq ! ( expected_subscription, events[ 0 ] ) ;
590563 assert_eq ! ( expected_unsubscription, events[ 2 ] ) ;
591564 }
@@ -607,9 +580,18 @@ mod test {
607580
608581 assert_eq ! ( no_events, [ ] ) ;
609582
610- let second_subscribe_event = get_events ( & mut subnet_service, None , 2 ) . await ;
583+ let subscription_end_slot = current_slot + subscription_slot2 + 2 ; // +1 to get to the end of the duty slot, +1 for the slot to complete
584+ let wait_slots = subnet_service
585+ . beacon_chain
586+ . slot_clock
587+ . duration_to_slot ( subscription_end_slot)
588+ . unwrap ( )
589+ . as_millis ( ) as u64
590+ / SLOT_DURATION_MILLIS ;
591+
592+ let second_subscribe_event = get_events ( & mut subnet_service, None , wait_slots as u32 ) . await ;
611593 // If the permanent and short lived subnets are different, we should get an unsubscription event.
612- if !subnet_service. is_subscribed ( & Subnet :: Attestation ( subnet_id1) ) {
594+ if !subnet_service. is_subscribed_permanent ( & Subnet :: Attestation ( subnet_id1) ) {
613595 assert_eq ! (
614596 [
615597 expected_subscription. clone( ) ,
@@ -633,9 +615,18 @@ mod test {
633615
634616 assert_eq ! ( no_events, [ ] ) ;
635617
636- let third_subscribe_event = get_events ( & mut subnet_service, None , 2 ) . await ;
618+ let subscription_end_slot = current_slot + subscription_slot3 + 2 ; // +1 to get to the end of the duty slot, +1 for the slot to complete
619+ let wait_slots = subnet_service
620+ . beacon_chain
621+ . slot_clock
622+ . duration_to_slot ( subscription_end_slot)
623+ . unwrap ( )
624+ . as_millis ( ) as u64
625+ / SLOT_DURATION_MILLIS ;
626+
627+ let third_subscribe_event = get_events ( & mut subnet_service, None , wait_slots as u32 ) . await ;
637628
638- if !subnet_service. is_subscribed ( & Subnet :: Attestation ( subnet_id1) ) {
629+ if !subnet_service. is_subscribed_permanent ( & Subnet :: Attestation ( subnet_id1) ) {
639630 assert_eq ! (
640631 [ expected_subscription, expected_unsubscription] ,
641632 third_subscribe_event[ ..]
0 commit comments