@@ -7,9 +7,6 @@ use beacon_chain::{
7
7
} ;
8
8
use genesis:: { generate_deterministic_keypairs, interop_genesis_state, DEFAULT_ETH1_BLOCK_HASH } ;
9
9
use lighthouse_network:: NetworkConfig ;
10
- use logging:: test_logger;
11
- use slog:: { o, Drain , Logger } ;
12
- use sloggers:: { null:: NullLoggerBuilder , Build } ;
13
10
use slot_clock:: { SlotClock , SystemTimeSlotClock } ;
14
11
use std:: sync:: { Arc , LazyLock } ;
15
12
use std:: time:: { Duration , SystemTime } ;
@@ -21,10 +18,6 @@ use types::{
21
18
SyncCommitteeSubscription , SyncSubnetId , ValidatorSubscription ,
22
19
} ;
23
20
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
-
28
21
const SLOT_DURATION_MILLIS : u64 = 400 ;
29
22
30
23
type TestBeaconChainType = Witness <
@@ -46,7 +39,7 @@ impl TestBeaconChain {
46
39
47
40
let keypairs = generate_deterministic_keypairs ( 1 ) ;
48
41
49
- let log = get_logger ( TEST_LOG_LEVEL ) ;
42
+ let log = logging :: test_logger ( ) ;
50
43
let store =
51
44
HotColdDB :: open_ephemeral ( StoreConfig :: default ( ) , spec. clone ( ) , log. clone ( ) ) . unwrap ( ) ;
52
45
@@ -98,28 +91,10 @@ pub fn recent_genesis_time() -> u64 {
98
91
. as_secs ( )
99
92
}
100
93
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
-
119
94
static CHAIN : LazyLock < TestBeaconChain > = LazyLock :: new ( TestBeaconChain :: new_with_system_clock) ;
120
95
121
96
fn get_subnet_service ( ) -> SubnetService < TestBeaconChainType > {
122
- let log = test_logger ( ) ;
97
+ let log = logging :: test_logger ( ) ;
123
98
let config = NetworkConfig :: default ( ) ;
124
99
125
100
let beacon_chain = CHAIN . chain . clone ( ) ;
@@ -501,8 +476,6 @@ mod test {
501
476
let committee_count = 1 ;
502
477
503
478
// 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).
506
479
let subscription_slot1 = 0 ;
507
480
let subscription_slot2 = MIN_PEER_DISCOVERY_SLOT_LOOK_AHEAD + 4 ;
508
481
let subscription_slot3 = subscription_slot2 * 2 ;
@@ -585,7 +558,7 @@ mod test {
585
558
let expected_unsubscription =
586
559
SubnetServiceMessage :: Unsubscribe ( Subnet :: Attestation ( subnet_id1) ) ;
587
560
588
- if !subnet_service. is_subscribed ( & Subnet :: Attestation ( subnet_id1) ) {
561
+ if !subnet_service. is_subscribed_permanent ( & Subnet :: Attestation ( subnet_id1) ) {
589
562
assert_eq ! ( expected_subscription, events[ 0 ] ) ;
590
563
assert_eq ! ( expected_unsubscription, events[ 2 ] ) ;
591
564
}
@@ -607,9 +580,18 @@ mod test {
607
580
608
581
assert_eq ! ( no_events, [ ] ) ;
609
582
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 ;
611
593
// 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) ) {
613
595
assert_eq ! (
614
596
[
615
597
expected_subscription. clone( ) ,
@@ -633,9 +615,18 @@ mod test {
633
615
634
616
assert_eq ! ( no_events, [ ] ) ;
635
617
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 ;
637
628
638
- if !subnet_service. is_subscribed ( & Subnet :: Attestation ( subnet_id1) ) {
629
+ if !subnet_service. is_subscribed_permanent ( & Subnet :: Attestation ( subnet_id1) ) {
639
630
assert_eq ! (
640
631
[ expected_subscription, expected_unsubscription] ,
641
632
third_subscribe_event[ ..]
0 commit comments