Search in sources :

Example 1 with SyncCommitteeSubnetSubscription

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);
}
Also used : SyncCommitteeSubnetSubscription(tech.pegasys.teku.validator.api.SyncCommitteeSubnetSubscription) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Example 2 with SyncCommitteeSubnetSubscription

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())));
}
Also used : SyncCommitteeSubnetSubscription(tech.pegasys.teku.validator.api.SyncCommitteeSubnetSubscription) SyncCommitteeDuty(tech.pegasys.teku.validator.api.SyncCommitteeDuty) SyncCommitteeDuties(tech.pegasys.teku.validator.api.SyncCommitteeDuties) SyncCommitteeScheduledDuties(tech.pegasys.teku.validator.client.duties.synccommittee.SyncCommitteeScheduledDuties) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Example 3 with SyncCommitteeSubnetSubscription

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));
    }
}
Also used : SyncCommitteeSubnetSubscription(tech.pegasys.teku.validator.api.SyncCommitteeSubnetSubscription) SyncCommitteeUtil(tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil) IntSet(it.unimi.dsi.fastutil.ints.IntSet) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64)

Aggregations

UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)3 SyncCommitteeSubnetSubscription (tech.pegasys.teku.validator.api.SyncCommitteeSubnetSubscription)3 Test (org.junit.jupiter.api.Test)2 IntSet (it.unimi.dsi.fastutil.ints.IntSet)1 SyncCommitteeUtil (tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil)1 SyncCommitteeDuties (tech.pegasys.teku.validator.api.SyncCommitteeDuties)1 SyncCommitteeDuty (tech.pegasys.teku.validator.api.SyncCommitteeDuty)1 SyncCommitteeScheduledDuties (tech.pegasys.teku.validator.client.duties.synccommittee.SyncCommitteeScheduledDuties)1