@@ -17,7 +17,7 @@ use lighthouse_network::{discv5::enr::NodeId, NetworkConfig, Subnet, SubnetDisco
17
17
use slog:: { debug, error, o, warn} ;
18
18
use slot_clock:: SlotClock ;
19
19
use types:: {
20
- Attestation , EthSpec , Slot , SubnetId , SyncCommitteeSubscription , SyncSubnetId , Unsigned ,
20
+ Attestation , EthSpec , Slot , SubnetId , SyncCommitteeSubscription , SyncSubnetId ,
21
21
ValidatorSubscription ,
22
22
} ;
23
23
@@ -51,17 +51,14 @@ const ADVANCE_SUBSCRIBE_SLOT_FRACTION: u32 = 1;
51
51
/// `aggregate_validators_on_subnet` delay map.
52
52
const UNSUBSCRIBE_AFTER_AGGREGATOR_DUTY : u32 = 2 ;
53
53
54
- /// A particular subnet at a given slot.
54
+ /// A particular subnet at a given slot. This is used for Attestation subnets and not for sync
55
+ /// committee subnets because the logic for handling subscriptions between these types is different.
55
56
#[ derive( PartialEq , Eq , Hash , Clone , Debug , Copy ) ]
56
57
pub struct ExactSubnet {
57
58
/// The `SubnetId` associated with this subnet.
58
59
pub subnet : Subnet ,
59
60
/// For Attestations, this slot represents the start time at which we need to subscribe to the
60
- /// slot. For SyncCommittee subnet id's this represents the end slot at which we no longer need
61
- /// to subscribe to the subnet.
62
- // NOTE: There was different logic between the two subscriptions and having a different
63
- // interpretation of this variable seemed like the best way to group the logic, even though it
64
- // may be counter-intuitive (apologies to future readers).
61
+ /// slot.
65
62
pub slot : Slot ,
66
63
}
67
64
@@ -123,7 +120,7 @@ impl<T: BeaconChainTypes> SubnetService<T> {
123
120
config : & NetworkConfig ,
124
121
log : & slog:: Logger ,
125
122
) -> Self {
126
- let log = log. new ( o ! ( "service" => "attestation_service " ) ) ;
123
+ let log = log. new ( o ! ( "service" => "subnet_service " ) ) ;
127
124
128
125
let slot_duration = beacon_chain. slot_clock . slot_duration ( ) ;
129
126
@@ -136,16 +133,15 @@ impl<T: BeaconChainTypes> SubnetService<T> {
136
133
let mut permanent_attestation_subscriptions = HashSet :: default ( ) ;
137
134
if config. subscribe_all_subnets {
138
135
// We are subscribed to all subnets, set all the bits to true.
139
- for index in 0 ..< T :: EthSpec as EthSpec > :: SubnetBitfieldLength :: to_u64 ( ) {
136
+ for index in 0 ..beacon_chain . spec . attestation_subnet_count {
140
137
permanent_attestation_subscriptions
141
138
. insert ( Subnet :: Attestation ( SubnetId :: from ( index) ) ) ;
142
139
}
143
140
} else {
144
141
// Not subscribed to all subnets, so just calculate the required subnets from the
145
- for subnet_id in SubnetId :: compute_attestation_subnets :: < T :: EthSpec > (
146
- node_id. raw ( ) . into ( ) ,
147
- & beacon_chain. spec ,
148
- ) {
142
+ for subnet_id in
143
+ SubnetId :: compute_attestation_subnets ( node_id. raw ( ) . into ( ) , & beacon_chain. spec )
144
+ {
149
145
permanent_attestation_subscriptions. insert ( Subnet :: Attestation ( subnet_id) ) ;
150
146
}
151
147
}
@@ -165,16 +161,18 @@ impl<T: BeaconChainTypes> SubnetService<T> {
165
161
let mut events = VecDeque :: with_capacity ( 10 ) ;
166
162
167
163
// Queue discovery queries for the permanent attestation subnets
168
- events. push_back ( SubnetServiceMessage :: DiscoverPeers (
169
- permanent_attestation_subscriptions
170
- . iter ( )
171
- . cloned ( )
172
- . map ( |subnet| SubnetDiscovery {
173
- subnet,
174
- min_ttl : None ,
175
- } )
176
- . collect ( ) ,
177
- ) ) ;
164
+ if !config. disable_discovery {
165
+ events. push_back ( SubnetServiceMessage :: DiscoverPeers (
166
+ permanent_attestation_subscriptions
167
+ . iter ( )
168
+ . cloned ( )
169
+ . map ( |subnet| SubnetDiscovery {
170
+ subnet,
171
+ min_ttl : None ,
172
+ } )
173
+ . collect ( ) ,
174
+ ) ) ;
175
+ }
178
176
179
177
// Pre-populate the events with permanent subscriptions
180
178
for subnet in permanent_attestation_subscriptions. iter ( ) {
@@ -507,7 +505,7 @@ impl<T: BeaconChainTypes> SubnetService<T> {
507
505
return ;
508
506
}
509
507
510
- // Return if we already have a subscription for the subnet and its closer or
508
+ // Update the unsubscription duration if we already have a subscription for the subnet
511
509
if let Some ( current_instant_to_unsubscribe) = self . subscriptions . deadline ( & subnet) {
512
510
// The extra 500ms in the comparison accounts of the inaccuracy of the underlying
513
511
// DelayQueue inside the delaymap struct.
@@ -595,9 +593,7 @@ impl<T: BeaconChainTypes> SubnetService<T> {
595
593
Ok ( ( ) )
596
594
}
597
595
598
- // Unsubscribes from a subnet that was removed if it does not continue to exist as a
599
- // subscription of the other kind. For long lived subscriptions, it also removes the
600
- // advertisement from our ENR.
596
+ // Unsubscribes from a subnet that was removed.
601
597
fn handle_removed_subnet ( & mut self , subnet : Subnet ) {
602
598
if !self . subscriptions . contains_key ( & subnet) {
603
599
// Subscription no longer exists as short lived or long lived.
0 commit comments