@@ -29,6 +29,10 @@ pub(crate) const MIN_PEER_DISCOVERY_SLOT_LOOK_AHEAD: u64 = 2;
29
29
/// Currently a whole slot ahead.
30
30
const ADVANCE_SUBSCRIBE_SLOT_FRACTION : u32 = 1 ;
31
31
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
+
32
36
#[ derive( Debug , Clone , Copy , Hash , PartialEq , Eq ) ]
33
37
pub ( crate ) enum SubscriptionKind {
34
38
/// Long lived subscriptions.
@@ -462,31 +466,27 @@ impl<T: BeaconChainTypes> AttestationService<T> {
462
466
) -> Result < ( ) , & ' static str > {
463
467
let slot_duration = self . beacon_chain . slot_clock . slot_duration ( ) ;
464
468
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
481
475
. beacon_chain
482
476
. slot_clock
483
477
. duration_to_slot ( slot)
484
478
. unwrap_or_default ( ) ; // If this is a past slot we will just get a 0 duration.
485
479
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) ;
487
483
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;
488
488
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 ) ;
490
490
}
491
491
492
492
// If the subscription should be done in the future, schedule it. Otherwise subscribe
0 commit comments