From 9bd384a573c869f3a59752bae4f75023d394052e Mon Sep 17 00:00:00 2001 From: Divma Date: Fri, 23 Sep 2022 03:52:45 +0000 Subject: [PATCH] send attnet unsubscription event on random subnet expiry (#3600) ## Issue Addressed :lady_beetle: in which we don't actually unsubscribe from a random long lived subnet when it expires ## Proposed Changes Remove code addressing a specific case in which we are subscribed to all subnets and handle the removal of the long lived subnet. I don't think the special case code is particularly important as, if someone is running with that many validators to be subscribed to all subnets, it should use `--subscribe-all-subnets` instead ## Additional Info Noticed on some test nodes climbing bandwidth usage periodically (around 27hours, the time of subnet expirations) I'm running this code to test this does not happen anymore, but I think it should be good now --- .../src/subnet_service/attestation_subnets.rs | 26 +++---------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/beacon_node/network/src/subnet_service/attestation_subnets.rs b/beacon_node/network/src/subnet_service/attestation_subnets.rs index ecca3c968..ee8ba24fc 100644 --- a/beacon_node/network/src/subnet_service/attestation_subnets.rs +++ b/beacon_node/network/src/subnet_service/attestation_subnets.rs @@ -564,26 +564,8 @@ impl AttestationService { /// /// This function selects a new subnet to join, or extends the expiry if there are no more /// available subnets to choose from. - fn handle_random_subnet_expiry(&mut self, subnet_id: SubnetId, end_slot: Slot) { - let subnet_count = self.beacon_chain.spec.attestation_subnet_count; - if self.long_lived_subscriptions.len() == (subnet_count - 1) as usize { - let end_slot = end_slot + self.long_lived_subnet_subscription_slots; - // This is just an extra accuracy precaution, we could use the default timeout if - // needed. - if let Some(time_to_subscription_end) = - self.beacon_chain.slot_clock.duration_to_slot(end_slot) - { - // We are at capacity, simply increase the timeout of the current subnet. - self.long_lived_subscriptions.insert_at( - subnet_id, - end_slot + 1, - time_to_subscription_end, - ); - } else { - self.long_lived_subscriptions.insert(subnet_id, end_slot); - } - return; - } + fn handle_random_subnet_expiry(&mut self, subnet_id: SubnetId) { + self.handle_removed_subnet(subnet_id, SubscriptionKind::LongLived); // Remove the ENR bitfield bit and choose a new random on from the available subnets // Subscribe to a new random subnet. @@ -718,8 +700,8 @@ impl Stream for AttestationService { // Process any random subnet expiries. match self.long_lived_subscriptions.poll_next_unpin(cx) { - Poll::Ready(Some(Ok((subnet_id, end_slot)))) => { - self.handle_random_subnet_expiry(subnet_id, end_slot) + Poll::Ready(Some(Ok((subnet_id, _end_slot)))) => { + self.handle_random_subnet_expiry(subnet_id) } Poll::Ready(Some(Err(e))) => { error!(self.log, "Failed to check for random subnet cycles"; "error"=> e);