Skip to content

Commit 1ef47af

Browse files
committed
Fix attestations not getting added to the aggregation pool (#5863)
Squashed commit of the following: commit aa9998e Author: Pawan Dhananjay <[email protected]> Date: Wed May 29 22:01:44 2024 +0530 Cleanup commit 7d3e57d Author: Pawan Dhananjay <[email protected]> Date: Wed May 29 20:12:21 2024 +0530 Remove from delay_map 2 slots after duty
1 parent 73e106b commit 1ef47af

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

beacon_node/network/src/subnet_service/attestation_subnets.rs

Lines changed: 22 additions & 14 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,23 +466,27 @@ impl<T: BeaconChainTypes> AttestationService<T> {
462466
) -> Result<(), &'static str> {
463467
let slot_duration = self.beacon_chain.slot_clock.slot_duration();
464468

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
475+
.beacon_chain
476+
.slot_clock
477+
.duration_to_slot(slot)
478+
.unwrap_or_default(); // If this is a past slot we will just get a 0 duration.
479+
465480
// 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-
};
481+
let time_to_subscription_start =
482+
time_to_subscription_slot.saturating_sub(advance_subscription_duration);
479483

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;
480488
if let Some(tracked_vals) = self.aggregate_validators_on_subnet.as_mut() {
481-
tracked_vals.insert(ExactSubnet { subnet_id, slot });
489+
tracked_vals.insert_at(ExactSubnet { subnet_id, slot }, time_to_unsubscribe);
482490
}
483491

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

0 commit comments

Comments
 (0)