Search in sources :

Example 1 with SyncCommitteeScheduledDuties

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())));
}
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 2 with SyncCommitteeScheduledDuties

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);
}
Also used : 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 SyncCommitteeScheduledDuties

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);
}
Also used : AttestationDutyFactory(tech.pegasys.teku.validator.client.duties.attestations.AttestationDutyFactory) BlockDutyFactory(tech.pegasys.teku.validator.client.duties.BlockDutyFactory) ValidatorLoader(tech.pegasys.teku.validator.client.loader.ValidatorLoader) DataDirLayout(tech.pegasys.teku.service.serviceutils.layout.DataDirLayout) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) ValidatorRestApiConfig(tech.pegasys.teku.validator.client.restapi.ValidatorRestApiConfig) Random(java.util.Random) LocalSlashingProtector(tech.pegasys.teku.core.signatures.LocalSlashingProtector) ArrayList(java.util.ArrayList) EventChannels(tech.pegasys.teku.infrastructure.events.EventChannels) ValidatorRestApi(tech.pegasys.teku.validator.client.restapi.ValidatorRestApi) PublicKeyLoader(tech.pegasys.teku.validator.client.loader.PublicKeyLoader) SlotBasedScheduledDuties(tech.pegasys.teku.validator.client.duties.SlotBasedScheduledDuties) JsonProvider(tech.pegasys.teku.provider.JsonProvider) ChainHeadTracker(tech.pegasys.teku.validator.client.duties.synccommittee.ChainHeadTracker) BeaconCommitteeSubscriptions(tech.pegasys.teku.validator.client.duties.BeaconCommitteeSubscriptions) Spec(tech.pegasys.teku.spec.Spec) Path(java.nio.file.Path) Service(tech.pegasys.teku.service.serviceutils.Service) ProposerConfigProvider(tech.pegasys.teku.validator.client.proposerconfig.ProposerConfigProvider) AsyncRunner(tech.pegasys.teku.infrastructure.async.AsyncRunner) ValidatorLogger(tech.pegasys.teku.infrastructure.logging.ValidatorLogger) SyncDataAccessor(tech.pegasys.teku.infrastructure.io.SyncDataAccessor) RestApi(tech.pegasys.teku.infrastructure.restapi.RestApi) ServiceConfig(tech.pegasys.teku.service.serviceutils.ServiceConfig) BeaconNodeApi(tech.pegasys.teku.validator.beaconnode.BeaconNodeApi) SyncCommitteeScheduledDuties(tech.pegasys.teku.validator.client.duties.synccommittee.SyncCommitteeScheduledDuties) List(java.util.List) Logger(org.apache.logging.log4j.Logger) TekuMetricCategory(tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) InProcessBeaconNodeApi(tech.pegasys.teku.validator.eventadapter.InProcessBeaconNodeApi) OwnedValidators(tech.pegasys.teku.validator.client.loader.OwnedValidators) SlashingProtector(tech.pegasys.teku.core.signatures.SlashingProtector) SystemSignalListener(tech.pegasys.teku.infrastructure.io.SystemSignalListener) GenesisDataProvider(tech.pegasys.teku.validator.beaconnode.GenesisDataProvider) ProposerConfigLoader(tech.pegasys.teku.validator.client.proposerconfig.loader.ProposerConfigLoader) SlashingProtectionLogger(tech.pegasys.teku.validator.client.loader.SlashingProtectionLogger) Optional(java.util.Optional) RemoteBeaconNodeApi(tech.pegasys.teku.validator.remote.RemoteBeaconNodeApi) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) LogManager(org.apache.logging.log4j.LogManager) SpecMilestone(tech.pegasys.teku.spec.SpecMilestone) ValidatorTimingChannel(tech.pegasys.teku.validator.api.ValidatorTimingChannel) AttestationDutyFactory(tech.pegasys.teku.validator.client.duties.attestations.AttestationDutyFactory) BlockDutyFactory(tech.pegasys.teku.validator.client.duties.BlockDutyFactory) ChainHeadTracker(tech.pegasys.teku.validator.client.duties.synccommittee.ChainHeadTracker) OwnedValidators(tech.pegasys.teku.validator.client.loader.OwnedValidators) BeaconCommitteeSubscriptions(tech.pegasys.teku.validator.client.duties.BeaconCommitteeSubscriptions) SyncCommitteeScheduledDuties(tech.pegasys.teku.validator.client.duties.synccommittee.SyncCommitteeScheduledDuties) ProposerConfigLoader(tech.pegasys.teku.validator.client.proposerconfig.loader.ProposerConfigLoader) JsonProvider(tech.pegasys.teku.provider.JsonProvider) SlotBasedScheduledDuties(tech.pegasys.teku.validator.client.duties.SlotBasedScheduledDuties) Random(java.util.Random)

Example 4 with SyncCommitteeScheduledDuties

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);
}
Also used : SyncCommitteeScheduledDuties(tech.pegasys.teku.validator.client.duties.synccommittee.SyncCommitteeScheduledDuties)

Example 5 with SyncCommitteeScheduledDuties

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;
}
Also used : SyncCommitteeScheduledDuties(tech.pegasys.teku.validator.client.duties.synccommittee.SyncCommitteeScheduledDuties)

Aggregations

SyncCommitteeScheduledDuties (tech.pegasys.teku.validator.client.duties.synccommittee.SyncCommitteeScheduledDuties)6 Test (org.junit.jupiter.api.Test)3 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)3 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Random (java.util.Random)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 MetricsSystem (org.hyperledger.besu.plugin.services.MetricsSystem)1 LocalSlashingProtector (tech.pegasys.teku.core.signatures.LocalSlashingProtector)1 SlashingProtector (tech.pegasys.teku.core.signatures.SlashingProtector)1 AsyncRunner (tech.pegasys.teku.infrastructure.async.AsyncRunner)1 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)1 EventChannels (tech.pegasys.teku.infrastructure.events.EventChannels)1 SyncDataAccessor (tech.pegasys.teku.infrastructure.io.SyncDataAccessor)1 SystemSignalListener (tech.pegasys.teku.infrastructure.io.SystemSignalListener)1 ValidatorLogger (tech.pegasys.teku.infrastructure.logging.ValidatorLogger)1 TekuMetricCategory (tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory)1