use of tech.pegasys.teku.validator.client.duties.synccommittee.SyncCommitteeScheduledDuties 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.client.duties.synccommittee.SyncCommitteeScheduledDuties in project teku by ConsenSys.
the class SyncCommitteeSchedulerTest method shouldSwitchToNextCommitteePeriodWhenLastSlotOfSyncCommitteePeriodReached.
@Test
void shouldSwitchToNextCommitteePeriodWhenLastSlotOfSyncCommitteePeriodReached() {
when(earlySubscribeRandomSource.randomEpochCount(epochsPerSyncCommitteePeriod)).thenReturn(5);
final UInt64 nextSyncCommitteePeriodStartEpoch = syncCommitteeUtil.computeFirstEpochOfNextSyncCommitteePeriod(UInt64.ZERO);
final UInt64 subscribeEpoch = nextSyncCommitteePeriodStartEpoch.minus(5);
final UInt64 subscribeSlot = spec.computeStartSlotAtEpoch(subscribeEpoch);
final UInt64 nextSyncCommitteePeriodStartSlot = spec.computeStartSlotAtEpoch(nextSyncCommitteePeriodStartEpoch);
final SyncCommitteeScheduledDuties nextDuties = createScheduledDuties();
scheduler.onSlot(UInt64.valueOf(5));
verify(dutyLoader).loadDutiesForEpoch(getRequestEpochForCommitteePeriod(0));
getRequestedDutiesForSyncCommitteePeriod(0).complete(Optional.of(duties));
scheduler.onSlot(subscribeSlot);
verify(dutyLoader).loadDutiesForEpoch(getRequestEpochForCommitteePeriod(1));
getRequestedDutiesForSyncCommitteePeriod(1).complete(Optional.of(nextDuties));
// Subscribed, but still performing duties for first sync committee period
scheduler.onAttestationCreationDue(subscribeSlot);
verify(duties).performProductionDuty(subscribeSlot);
final UInt64 nextSyncCommitteeFirstDutySlot = nextSyncCommitteePeriodStartSlot.minus(1);
scheduler.onSlot(nextSyncCommitteeFirstDutySlot);
scheduler.onAttestationCreationDue(nextSyncCommitteeFirstDutySlot);
verify(nextDuties).performProductionDuty(nextSyncCommitteeFirstDutySlot);
verify(duties, never()).performProductionDuty(nextSyncCommitteeFirstDutySlot);
}
use of tech.pegasys.teku.validator.client.duties.synccommittee.SyncCommitteeScheduledDuties in project teku by ConsenSys.
the class ValidatorClientService method initializeValidators.
private void initializeValidators(ValidatorClientConfiguration config, ValidatorApiChannel validatorApiChannel, AsyncRunner asyncRunner) {
validatorLoader.loadValidators();
final OwnedValidators validators = validatorLoader.getOwnedValidators();
this.validatorIndexProvider = new ValidatorIndexProvider(validators, validatorApiChannel, asyncRunner);
final BlockDutyFactory blockDutyFactory = new BlockDutyFactory(forkProvider, validatorApiChannel, spec);
final AttestationDutyFactory attestationDutyFactory = new AttestationDutyFactory(spec, forkProvider, validatorApiChannel);
final BeaconCommitteeSubscriptions beaconCommitteeSubscriptions = new BeaconCommitteeSubscriptions(validatorApiChannel);
final DutyLoader<?> attestationDutyLoader = new RetryingDutyLoader<>(asyncRunner, new AttestationDutyLoader(validatorApiChannel, forkProvider, dependentRoot -> new SlotBasedScheduledDuties<>(attestationDutyFactory, dependentRoot), validators, validatorIndexProvider, beaconCommitteeSubscriptions, spec));
final DutyLoader<?> blockDutyLoader = new RetryingDutyLoader<>(asyncRunner, new BlockProductionDutyLoader(validatorApiChannel, dependentRoot -> new SlotBasedScheduledDuties<>(blockDutyFactory, dependentRoot), validators, validatorIndexProvider));
validatorTimingChannels.add(new BlockDutyScheduler(metricsSystem, blockDutyLoader, spec));
validatorTimingChannels.add(new AttestationDutyScheduler(metricsSystem, attestationDutyLoader, spec));
validatorTimingChannels.add(validatorLoader.getSlashingProtectionLogger());
if (spec.isMilestoneSupported(SpecMilestone.ALTAIR)) {
final ChainHeadTracker chainHeadTracker = new ChainHeadTracker();
validatorTimingChannels.add(chainHeadTracker);
final DutyLoader<SyncCommitteeScheduledDuties> syncCommitteeDutyLoader = new RetryingDutyLoader<>(asyncRunner, new SyncCommitteeDutyLoader(validators, validatorIndexProvider, spec, validatorApiChannel, chainHeadTracker, forkProvider));
validatorTimingChannels.add(new SyncCommitteeScheduler(metricsSystem, spec, syncCommitteeDutyLoader, new Random()::nextInt));
}
if (spec.isMilestoneSupported(SpecMilestone.BELLATRIX)) {
proposerConfigProvider = Optional.of(ProposerConfigProvider.create(asyncRunner, config.getValidatorConfig().getRefreshProposerConfigFromSource(), new ProposerConfigLoader(new JsonProvider().getObjectMapper()), config.getValidatorConfig().getProposerConfigSource()));
validatorTimingChannels.add(new BeaconProposerPreparer(validatorApiChannel, validatorIndexProvider, proposerConfigProvider.get(), config.getValidatorConfig().getProposerDefaultFeeRecipient(), spec));
} else {
proposerConfigProvider = Optional.empty();
}
addValidatorCountMetric(metricsSystem, validators);
this.validatorStatusLogger = new DefaultValidatorStatusLogger(metricsSystem, validators, validatorApiChannel, asyncRunner);
}
use of tech.pegasys.teku.validator.client.duties.synccommittee.SyncCommitteeScheduledDuties in project teku by ConsenSys.
the class SyncCommitteeDutyLoader method scheduleAllDuties.
@Override
protected SafeFuture<SyncCommitteeScheduledDuties> scheduleAllDuties(final UInt64 epoch, final SyncCommitteeDuties duties) {
final SyncCommitteeScheduledDuties.Builder dutyBuilder = SyncCommitteeScheduledDuties.builder().forkProvider(forkProvider).validatorApiChannel(validatorApiChannel).chainHeadTracker(chainHeadTracker).spec(spec).lastEpochInCommitteePeriod(spec.getSyncCommitteeUtilRequired(spec.computeStartSlotAtEpoch(epoch)).computeFirstEpochOfNextSyncCommitteePeriod(epoch).minusMinZero(1));
duties.getDuties().forEach(duty -> scheduleDuty(dutyBuilder, duty));
final SyncCommitteeScheduledDuties scheduledDuties = dutyBuilder.build();
scheduledDuties.subscribeToSubnets();
return SafeFuture.completedFuture(scheduledDuties);
}
use of tech.pegasys.teku.validator.client.duties.synccommittee.SyncCommitteeScheduledDuties in project teku by ConsenSys.
the class SyncCommitteeSchedulerTest method createScheduledDuties.
private SyncCommitteeScheduledDuties createScheduledDuties() {
final SyncCommitteeScheduledDuties duties = mock(SyncCommitteeScheduledDuties.class);
when(duties.performProductionDuty(any())).thenReturn(new SafeFuture<>());
when(duties.performAggregationDuty(any())).thenReturn(new SafeFuture<>());
return duties;
}
Aggregations