use of tech.pegasys.teku.validator.api.SyncCommitteeSubnetSubscription in project teku by ConsenSys.
the class ValidatorApiHandlerTest method subscribeToSyncCommitteeSubnets_shouldConvertCommitteeIndexToSubnetId.
@Test
void subscribeToSyncCommitteeSubnets_shouldConvertCommitteeIndexToSubnetId() {
final SyncCommitteeSubnetSubscription subscription1 = new SyncCommitteeSubnetSubscription(1, IntSet.of(1, 2, 15, 30), UInt64.valueOf(44));
final SyncCommitteeSubnetSubscription subscription2 = new SyncCommitteeSubnetSubscription(1, IntSet.of(5, 10), UInt64.valueOf(35));
validatorApiHandler.subscribeToSyncCommitteeSubnets(List.of(subscription1, subscription2));
final UInt64 unsubscribeSlotSubscription1 = spec.computeStartSlotAtEpoch(UInt64.valueOf(44));
final UInt64 unsubscribeSlotSubscription2 = spec.computeStartSlotAtEpoch(UInt64.valueOf(35));
verify(syncCommitteeSubscriptionManager).subscribe(0, unsubscribeSlotSubscription1);
verify(syncCommitteeSubscriptionManager).subscribe(1, unsubscribeSlotSubscription1);
verify(syncCommitteeSubscriptionManager).subscribe(3, unsubscribeSlotSubscription1);
verify(syncCommitteeSubscriptionManager).subscribe(0, unsubscribeSlotSubscription2);
verify(syncCommitteeSubscriptionManager).subscribe(1, unsubscribeSlotSubscription2);
verifyNoMoreInteractions(syncCommitteeSubscriptionManager);
}
use of tech.pegasys.teku.validator.api.SyncCommitteeSubnetSubscription in project teku by ConsenSys.
the class SyncCommitteeDutyLoaderTest method shouldRetrieveDuties.
@Test
void shouldRetrieveDuties() {
final UInt64 epoch = UInt64.valueOf(56);
final UInt64 untilEpoch = spec.getSyncCommitteeUtilRequired(UInt64.ZERO).computeFirstEpochOfNextSyncCommitteePeriod(epoch).minusMinZero(1);
when(validatorApiChannel.getSyncCommitteeDuties(epoch, validatorIndices)).thenReturn(SafeFuture.completedFuture(Optional.of(new SyncCommitteeDuties(List.of(new SyncCommitteeDuty(validator1.getPublicKey(), validator1Index, IntSet.of(1, 6, 25)), new SyncCommitteeDuty(validator2.getPublicKey(), validator2Index, IntSet.of(7, 50, 38)))))));
final SyncCommitteeScheduledDuties duties = loadDuties(epoch);
assertThat(duties.countDuties()).isEqualTo(2);
// And should trigger subscription to subnets
verify(validatorApiChannel).subscribeToSyncCommitteeSubnets(Set.of(new SyncCommitteeSubnetSubscription(validator1Index, IntSet.of(1, 6, 25), untilEpoch.increment()), new SyncCommitteeSubnetSubscription(validator2Index, IntSet.of(7, 50, 38), untilEpoch.increment())));
}
use of tech.pegasys.teku.validator.api.SyncCommitteeSubnetSubscription in project teku by ConsenSys.
the class ValidatorApiHandler method subscribeToSyncCommitteeSubnets.
@Override
public void subscribeToSyncCommitteeSubnets(final Collection<SyncCommitteeSubnetSubscription> subscriptions) {
for (final SyncCommitteeSubnetSubscription subscription : subscriptions) {
// untilEpoch is exclusive, so it will unsubscribe at the first slot of the specified index
final UInt64 untilEpoch = subscription.getUntilEpoch();
final UInt64 unsubscribeSlot = spec.computeStartSlotAtEpoch(untilEpoch);
final SyncCommitteeUtil syncCommitteeUtil = spec.getSyncCommitteeUtilRequired(spec.computeStartSlotAtEpoch(untilEpoch));
final IntSet syncCommitteeIndices = subscription.getSyncCommitteeIndices();
performanceTracker.saveExpectedSyncCommitteeParticipant(subscription.getValidatorIndex(), syncCommitteeIndices, untilEpoch.decrement());
syncCommitteeUtil.getSyncSubcommittees(syncCommitteeIndices).forEach(index -> syncCommitteeSubscriptionManager.subscribe(index, unsubscribeSlot));
}
}
Aggregations