Skip to content

Commit 1a89fb4

Browse files
committed
Correct comments and reviewers comments
1 parent 6bd0f75 commit 1a89fb4

File tree

4 files changed

+27
-30
lines changed

4 files changed

+27
-30
lines changed

beacon_node/network/src/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ pub struct NetworkService<T: BeaconChainTypes> {
166166
beacon_chain: Arc<BeaconChain<T>>,
167167
/// The underlying libp2p service that drives all the network interactions.
168168
libp2p: Network<RequestId, T::EthSpec>,
169-
/// An attestation and subnet manager service.
169+
/// An attestation and sync committee subnet manager service.
170170
subnet_service: SubnetService<T>,
171171
/// The receiver channel for lighthouse to communicate with the network service.
172172
network_recv: mpsc::UnboundedReceiver<NetworkMessage<T::EthSpec>>,

beacon_node/network/src/subnet_service/mod.rs

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use lighthouse_network::{discv5::enr::NodeId, NetworkConfig, Subnet, SubnetDisco
1717
use slog::{debug, error, o, warn};
1818
use slot_clock::SlotClock;
1919
use types::{
20-
Attestation, EthSpec, Slot, SubnetId, SyncCommitteeSubscription, SyncSubnetId, Unsigned,
20+
Attestation, EthSpec, Slot, SubnetId, SyncCommitteeSubscription, SyncSubnetId,
2121
ValidatorSubscription,
2222
};
2323

@@ -51,17 +51,14 @@ const ADVANCE_SUBSCRIBE_SLOT_FRACTION: u32 = 1;
5151
/// `aggregate_validators_on_subnet` delay map.
5252
const UNSUBSCRIBE_AFTER_AGGREGATOR_DUTY: u32 = 2;
5353

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.
5556
#[derive(PartialEq, Eq, Hash, Clone, Debug, Copy)]
5657
pub struct ExactSubnet {
5758
/// The `SubnetId` associated with this subnet.
5859
pub subnet: Subnet,
5960
/// 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.
6562
pub slot: Slot,
6663
}
6764

@@ -123,7 +120,7 @@ impl<T: BeaconChainTypes> SubnetService<T> {
123120
config: &NetworkConfig,
124121
log: &slog::Logger,
125122
) -> Self {
126-
let log = log.new(o!("service" => "attestation_service"));
123+
let log = log.new(o!("service" => "subnet_service"));
127124

128125
let slot_duration = beacon_chain.slot_clock.slot_duration();
129126

@@ -136,16 +133,15 @@ impl<T: BeaconChainTypes> SubnetService<T> {
136133
let mut permanent_attestation_subscriptions = HashSet::default();
137134
if config.subscribe_all_subnets {
138135
// 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 {
140137
permanent_attestation_subscriptions
141138
.insert(Subnet::Attestation(SubnetId::from(index)));
142139
}
143140
} else {
144141
// 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+
{
149145
permanent_attestation_subscriptions.insert(Subnet::Attestation(subnet_id));
150146
}
151147
}
@@ -165,16 +161,18 @@ impl<T: BeaconChainTypes> SubnetService<T> {
165161
let mut events = VecDeque::with_capacity(10);
166162

167163
// 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+
}
178176

179177
// Pre-populate the events with permanent subscriptions
180178
for subnet in permanent_attestation_subscriptions.iter() {
@@ -507,7 +505,7 @@ impl<T: BeaconChainTypes> SubnetService<T> {
507505
return;
508506
}
509507

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
511509
if let Some(current_instant_to_unsubscribe) = self.subscriptions.deadline(&subnet) {
512510
// The extra 500ms in the comparison accounts of the inaccuracy of the underlying
513511
// DelayQueue inside the delaymap struct.
@@ -595,9 +593,7 @@ impl<T: BeaconChainTypes> SubnetService<T> {
595593
Ok(())
596594
}
597595

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.
601597
fn handle_removed_subnet(&mut self, subnet: Subnet) {
602598
if !self.subscriptions.contains_key(&subnet) {
603599
// Subscription no longer exists as short lived or long lived.

beacon_node/network/src/subnet_service/tests/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use beacon_chain::{
77
use genesis::{generate_deterministic_keypairs, interop_genesis_state, DEFAULT_ETH1_BLOCK_HASH};
88
use lazy_static::lazy_static;
99
use lighthouse_network::NetworkConfig;
10+
use logging::test_logger;
1011
use slog::{o, Drain, Logger};
1112
use sloggers::{null::NullLoggerBuilder, Build};
1213
use slot_clock::{SlotClock, SystemTimeSlotClock};
@@ -118,7 +119,7 @@ lazy_static! {
118119
}
119120

120121
fn get_subnet_service() -> SubnetService<TestBeaconChainType> {
121-
let log = get_logger(TEST_LOG_LEVEL);
122+
let log = test_logger();
122123
let config = NetworkConfig::default();
123124

124125
let beacon_chain = CHAIN.chain.clone();

consensus/types/src/subnet_id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl SubnetId {
7777
/// Computes the set of subnets the node should be subscribed to during the current epoch,
7878
/// along with the first epoch in which these subscriptions are no longer valid.
7979
#[allow(clippy::arithmetic_side_effects)]
80-
pub fn compute_attestation_subnets<E: EthSpec>(
80+
pub fn compute_attestation_subnets(
8181
node_id: ethereum_types::U256,
8282
spec: &ChainSpec,
8383
) -> impl Iterator<Item = SubnetId> {

0 commit comments

Comments
 (0)