Skip to content

Commit aa9998e

Browse files
committed
Cleanup
1 parent 7d3e57d commit aa9998e

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

beacon_node/network/src/subnet_service/attestation_subnets.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ pub(crate) const MIN_PEER_DISCOVERY_SLOT_LOOK_AHEAD: u64 = 2;
2929
/// Currently a whole slot ahead.
3030
const ADVANCE_SUBSCRIBE_SLOT_FRACTION: u32 = 1;
3131

32+
/// The number of slots after an aggregator duty where we remove the entry from
33+
/// `aggregate_validators_on_subnet` delay map.
34+
const UNSUBSCRIBE_AFTER_AGGREGATOR_DUTY: u32 = 2;
35+
3236
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
3337
pub(crate) enum SubscriptionKind {
3438
/// Long lived subscriptions.
@@ -462,31 +466,27 @@ impl<T: BeaconChainTypes> AttestationService<T> {
462466
) -> Result<(), &'static str> {
463467
let slot_duration = self.beacon_chain.slot_clock.slot_duration();
464468

465-
// Calculate how long before we need to subscribe to the subnet.
466-
let time_to_subscription_start = {
467-
// The short time we schedule the subscription before it's actually required. This
468-
// ensures we are subscribed on time, and allows consecutive subscriptions to the same
469-
// subnet to overlap, reducing subnet churn.
470-
let advance_subscription_duration = slot_duration / ADVANCE_SUBSCRIBE_SLOT_FRACTION;
471-
// The time to the required slot.
472-
let time_to_subscription_slot = self
473-
.beacon_chain
474-
.slot_clock
475-
.duration_to_slot(slot)
476-
.unwrap_or_default(); // If this is a past slot we will just get a 0 duration.
477-
time_to_subscription_slot.saturating_sub(advance_subscription_duration)
478-
};
479-
480-
let mut time_to_subscription_slot = self
469+
// The short time we schedule the subscription before it's actually required. This
470+
// ensures we are subscribed on time, and allows consecutive subscriptions to the same
471+
// subnet to overlap, reducing subnet churn.
472+
let advance_subscription_duration = slot_duration / ADVANCE_SUBSCRIBE_SLOT_FRACTION;
473+
// The time to the required slot.
474+
let time_to_subscription_slot = self
481475
.beacon_chain
482476
.slot_clock
483477
.duration_to_slot(slot)
484478
.unwrap_or_default(); // If this is a past slot we will just get a 0 duration.
485479

486-
time_to_subscription_slot += slot_duration * 2;
480+
// Calculate how long before we need to subscribe to the subnet.
481+
let time_to_subscription_start =
482+
time_to_subscription_slot.saturating_sub(advance_subscription_duration);
487483

484+
// The time after a duty slot where we no longer need it in the `aggregate_validators_on_subnet`
485+
// delay map.
486+
let time_to_unsubscribe =
487+
time_to_subscription_slot + UNSUBSCRIBE_AFTER_AGGREGATOR_DUTY * slot_duration;
488488
if let Some(tracked_vals) = self.aggregate_validators_on_subnet.as_mut() {
489-
tracked_vals.insert_at(ExactSubnet { subnet_id, slot }, time_to_subscription_slot);
489+
tracked_vals.insert_at(ExactSubnet { subnet_id, slot }, time_to_unsubscribe);
490490
}
491491

492492
// If the subscription should be done in the future, schedule it. Otherwise subscribe

0 commit comments

Comments
 (0)