From ecf295908c566b6f1e026243907b3953d7ff96e0 Mon Sep 17 00:00:00 2001 From: figtracer <1gusredo@gmail.com> Date: Sun, 21 Dec 2025 01:49:33 +0000 Subject: [PATCH 1/3] small fix --- beacon_node/network/src/subnet_service/tests/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beacon_node/network/src/subnet_service/tests/mod.rs b/beacon_node/network/src/subnet_service/tests/mod.rs index bee6569b7b3..8551cee908f 100644 --- a/beacon_node/network/src/subnet_service/tests/mod.rs +++ b/beacon_node/network/src/subnet_service/tests/mod.rs @@ -338,7 +338,7 @@ mod test { // Unsubscription event should happen at slot 2 (since subnet id's are the same, unsubscription event should be at higher slot + 1) let expected = SubnetServiceMessage::Subscribe(Subnet::Attestation(subnet_id1)); - if subnet_service.is_subscribed(&Subnet::Attestation(subnet_id1)) { + if subnet_service.is_subscribed_permanent(&Subnet::Attestation(subnet_id1)) { // If we are permanently subscribed to this subnet, we won't see a subscribe message let _ = get_events_until_num_slots(&mut subnet_service, None, 1).await; } else { From 84c393a6dfa4a16f8fd4bb8c0d899674ec24ce87 Mon Sep 17 00:00:00 2001 From: figtracer <1gusredo@gmail.com> Date: Mon, 22 Dec 2025 08:36:47 +0000 Subject: [PATCH 2/3] fix --- beacon_node/network/src/subnet_service/tests/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/beacon_node/network/src/subnet_service/tests/mod.rs b/beacon_node/network/src/subnet_service/tests/mod.rs index 8551cee908f..d4a280aa253 100644 --- a/beacon_node/network/src/subnet_service/tests/mod.rs +++ b/beacon_node/network/src/subnet_service/tests/mod.rs @@ -356,6 +356,9 @@ mod test { assert_eq!([expected], unsubscribe_event[..]); } + // Ensure the subscription has been fully removed + let _ = get_events_until_num_slots(&mut subnet_service, None, 0).await; + // Should no longer be subscribed to any short lived subnets after unsubscription. assert_eq!(subnet_service.subscriptions().count(), 0); } From 53640f4ebfe8bb9f97dfcf04b332a45138700c75 Mon Sep 17 00:00:00 2001 From: figtracer <1gusredo@gmail.com> Date: Mon, 22 Dec 2025 13:04:13 +0000 Subject: [PATCH 3/3] new approach --- beacon_node/network/src/subnet_service/mod.rs | 7 ---- .../network/src/subnet_service/tests/mod.rs | 38 +++++++++---------- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/beacon_node/network/src/subnet_service/mod.rs b/beacon_node/network/src/subnet_service/mod.rs index be491e56d3e..008e7ab9ac8 100644 --- a/beacon_node/network/src/subnet_service/mod.rs +++ b/beacon_node/network/src/subnet_service/mod.rs @@ -198,13 +198,6 @@ impl SubnetService { self.permanent_attestation_subscriptions.iter() } - /// Returns whether we are subscribed to a subnet for testing purposes. - #[cfg(test)] - pub(crate) fn is_subscribed(&self, subnet: &Subnet) -> bool { - self.subscriptions.contains_key(subnet) - || self.permanent_attestation_subscriptions.contains(subnet) - } - /// Returns whether we are subscribed to a permanent subnet for testing purposes. #[cfg(test)] pub(crate) fn is_subscribed_permanent(&self, subnet: &Subnet) -> bool { diff --git a/beacon_node/network/src/subnet_service/tests/mod.rs b/beacon_node/network/src/subnet_service/tests/mod.rs index d4a280aa253..58aae6deb39 100644 --- a/beacon_node/network/src/subnet_service/tests/mod.rs +++ b/beacon_node/network/src/subnet_service/tests/mod.rs @@ -335,31 +335,27 @@ mod test { // submit the subscriptions subnet_service.validator_subscriptions(vec![sub1, sub2].into_iter()); - // Unsubscription event should happen at slot 2 (since subnet id's are the same, unsubscription event should be at higher slot + 1) - let expected = SubnetServiceMessage::Subscribe(Subnet::Attestation(subnet_id1)); + let subnet = Subnet::Attestation(subnet_id1); - if subnet_service.is_subscribed_permanent(&Subnet::Attestation(subnet_id1)) { - // If we are permanently subscribed to this subnet, we won't see a subscribe message - let _ = get_events_until_num_slots(&mut subnet_service, None, 1).await; + // If permanently subscribed, no Subscribe/Unsubscribe events will be generated + if subnet_service.is_subscribed_permanent(&subnet) { + let _ = get_events_until_num_slots(&mut subnet_service, None, 3).await; } else { - let subscription = get_events_until_num_slots(&mut subnet_service, None, 1).await; - assert_eq!(subscription, [expected]); - } - - // Get event for 1 more slot duration, we should get the unsubscribe event now. - let unsubscribe_event = get_events_until_num_slots(&mut subnet_service, None, 1).await; - - // If the long lived and short lived subnets are different, we should get an unsubscription - // event. - let expected = SubnetServiceMessage::Unsubscribe(Subnet::Attestation(subnet_id1)); - if !subnet_service.is_subscribed(&Subnet::Attestation(subnet_id1)) { - assert_eq!([expected], unsubscribe_event[..]); + // Wait for exactly 2 events (Subscribe + Unsubscribe) with a generous timeout + let expected = [ + SubnetServiceMessage::Subscribe(subnet), + SubnetServiceMessage::Unsubscribe(subnet), + ]; + let events = get_events_until_num_slots( + &mut subnet_service, + Some(2), + (MainnetEthSpec::slots_per_epoch()) as u32, + ) + .await; + assert_eq!(events, expected); } - // Ensure the subscription has been fully removed - let _ = get_events_until_num_slots(&mut subnet_service, None, 0).await; - - // Should no longer be subscribed to any short lived subnets after unsubscription. + // Should no longer be subscribed to any short lived subnets after unsubscription. assert_eq!(subnet_service.subscriptions().count(), 0); }