@Test void shouldSubscribeToAllSubnetsWhenNecessary() { ValidatorApiChannel validatorApiChannel = mock(ValidatorApiChannel.class); StableSubnetSubscriber stableSubnetSubscriber = new StableSubnetSubscriber( validatorApiChannel, new Random(), Constants.ATTESTATION_SUBNET_COUNT + 2); UInt64 slot = UInt64.valueOf(15); stableSubnetSubscriber.onSlot(slot); ArgumentCaptor<Set<SubnetSubscription>> subnetSubcriptions = ArgumentCaptor.forClass(Set.class); verify(validatorApiChannel).subscribeToPersistentSubnets(subnetSubcriptions.capture()); assertThat(subnetSubcriptions.getValue()).hasSize(Constants.ATTESTATION_SUBNET_COUNT); assertSubnetsAreDistinct(subnetSubcriptions.getValue()); assertUnsubscribeSlotsAreInBound(subnetSubcriptions.getValue(), UInt64.valueOf(15)); }
public void onSlot(UInt64 slot) { final Iterator<SubnetSubscription> iterator = subnetSubscriptions.iterator(); while (iterator.hasNext()) { final SubnetSubscription subnetSubscription = iterator.next(); if (subnetSubscription.getUnsubscriptionSlot().compareTo(slot) > 0) { break; } iterator.remove(); int subnetId = subnetSubscription.getSubnetId(); availableSubnetIndices.add(subnetId); } Set<SubnetSubscription> newSubnetSubscriptions = adjustNumberOfSubscriptionsToNumberOfValidators(slot, validatorCount); if (!newSubnetSubscriptions.isEmpty()) { validatorApiChannel.subscribeToPersistentSubnets(newSubnetSubscriptions); } }
StableSubnetSubscriber { public void onSlot(UInt64 slot) { final Iterator<SubnetSubscription> iterator = subnetSubscriptions.iterator(); while (iterator.hasNext()) { final SubnetSubscription subnetSubscription = iterator.next(); if (subnetSubscription.getUnsubscriptionSlot().compareTo(slot) > 0) { break; } iterator.remove(); int subnetId = subnetSubscription.getSubnetId(); availableSubnetIndices.add(subnetId); } Set<SubnetSubscription> newSubnetSubscriptions = adjustNumberOfSubscriptionsToNumberOfValidators(slot, validatorCount); if (!newSubnetSubscriptions.isEmpty()) { validatorApiChannel.subscribeToPersistentSubnets(newSubnetSubscriptions); } } }
StableSubnetSubscriber { public void onSlot(UInt64 slot) { final Iterator<SubnetSubscription> iterator = subnetSubscriptions.iterator(); while (iterator.hasNext()) { final SubnetSubscription subnetSubscription = iterator.next(); if (subnetSubscription.getUnsubscriptionSlot().compareTo(slot) > 0) { break; } iterator.remove(); int subnetId = subnetSubscription.getSubnetId(); availableSubnetIndices.add(subnetId); } Set<SubnetSubscription> newSubnetSubscriptions = adjustNumberOfSubscriptionsToNumberOfValidators(slot, validatorCount); if (!newSubnetSubscriptions.isEmpty()) { validatorApiChannel.subscribeToPersistentSubnets(newSubnetSubscriptions); } } StableSubnetSubscriber(
      ValidatorApiChannel validatorApiChannel, Random random, int validatorCount); }
StableSubnetSubscriber { public void onSlot(UInt64 slot) { final Iterator<SubnetSubscription> iterator = subnetSubscriptions.iterator(); while (iterator.hasNext()) { final SubnetSubscription subnetSubscription = iterator.next(); if (subnetSubscription.getUnsubscriptionSlot().compareTo(slot) > 0) { break; } iterator.remove(); int subnetId = subnetSubscription.getSubnetId(); availableSubnetIndices.add(subnetId); } Set<SubnetSubscription> newSubnetSubscriptions = adjustNumberOfSubscriptionsToNumberOfValidators(slot, validatorCount); if (!newSubnetSubscriptions.isEmpty()) { validatorApiChannel.subscribeToPersistentSubnets(newSubnetSubscriptions); } } StableSubnetSubscriber(
      ValidatorApiChannel validatorApiChannel, Random random, int validatorCount); void onSlot(UInt64 slot); void updateValidatorCount(final int validatorCount); }
StableSubnetSubscriber { public void onSlot(UInt64 slot) { final Iterator<SubnetSubscription> iterator = subnetSubscriptions.iterator(); while (iterator.hasNext()) { final SubnetSubscription subnetSubscription = iterator.next(); if (subnetSubscription.getUnsubscriptionSlot().compareTo(slot) > 0) { break; } iterator.remove(); int subnetId = subnetSubscription.getSubnetId(); availableSubnetIndices.add(subnetId); } Set<SubnetSubscription> newSubnetSubscriptions = adjustNumberOfSubscriptionsToNumberOfValidators(slot, validatorCount); if (!newSubnetSubscriptions.isEmpty()) { validatorApiChannel.subscribeToPersistentSubnets(newSubnetSubscriptions); } } StableSubnetSubscriber(
      ValidatorApiChannel validatorApiChannel, Random random, int validatorCount); void onSlot(UInt64 slot); void updateValidatorCount(final int validatorCount);  }