Search in sources :

Example 11 with Validator

use of tech.pegasys.teku.validator.client.Validator in project teku by ConsenSys.

the class ValidatorLoader method addValidator.

private void addValidator(final Signer signer, final BLSPublicKey publicKey) {
    ownedValidators.addValidator(new Validator(publicKey, new DeletableSigner(signer), graffitiProvider, false));
    LOG.info("Added validator: {}", publicKey.toString());
}
Also used : DeletableSigner(tech.pegasys.teku.core.signatures.DeletableSigner) Validator(tech.pegasys.teku.validator.client.Validator)

Example 12 with Validator

use of tech.pegasys.teku.validator.client.Validator in project teku by ConsenSys.

the class SyncCommitteeAggregationDuty method performAggregationIfRequired.

private SafeFuture<AggregationResult> performAggregationIfRequired(final SyncCommitteeUtil syncCommitteeUtil, final ForkInfo forkInfo, final ValidatorAndCommitteeIndices assignment, final int subcommitteeIndex, final UInt64 slot, final Bytes32 beaconBlockRoot) {
    final SyncAggregatorSelectionData selectionData = syncCommitteeUtil.createSyncAggregatorSelectionData(slot, UInt64.valueOf(subcommitteeIndex));
    final Validator validator = assignment.getValidator();
    return validator.getSigner().signSyncCommitteeSelectionProof(selectionData, forkInfo).thenCompose(selectionProof -> {
        if (syncCommitteeUtil.isSyncCommitteeAggregator(selectionProof)) {
            return performAggregation(syncCommitteeUtil, forkInfo, assignment, subcommitteeIndex, slot, beaconBlockRoot, selectionProof);
        } else {
            return SafeFuture.completedFuture(new AggregationResult(validator.getPublicKey(), DutyResult.NO_OP));
        }
    }).exceptionally(error -> new AggregationResult(validator.getPublicKey(), DutyResult.forError(validator.getPublicKey(), error)));
}
Also used : ValidatorLogger(tech.pegasys.teku.infrastructure.logging.ValidatorLogger) BLSSignature(tech.pegasys.teku.bls.BLSSignature) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) SyncAggregatorSelectionData(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncAggregatorSelectionData) Collection(java.util.Collection) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) Collectors(java.util.stream.Collectors) ContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.ContributionAndProof) SignedContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Stream(java.util.stream.Stream) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) ForkProvider(tech.pegasys.teku.validator.client.ForkProvider) SyncCommitteeUtil(tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil) Optional(java.util.Optional) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) Spec(tech.pegasys.teku.spec.Spec) Bytes32(org.apache.tuweni.bytes.Bytes32) DutyResult(tech.pegasys.teku.validator.client.duties.DutyResult) SyncCommitteeContribution(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContribution) Validator(tech.pegasys.teku.validator.client.Validator) SyncAggregatorSelectionData(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncAggregatorSelectionData) Validator(tech.pegasys.teku.validator.client.Validator)

Example 13 with Validator

use of tech.pegasys.teku.validator.client.Validator in project teku by ConsenSys.

the class MultithreadedValidatorLoader method loadValidators.

public static void loadValidators(final OwnedValidators ownedValidators, final Map<BLSPublicKey, ValidatorProvider> providers, final GraffitiProvider graffitiProvider) {
    final int totalValidatorCount = providers.size();
    STATUS_LOG.loadingValidators(totalValidatorCount);
    final ExecutorService executorService = Executors.newFixedThreadPool(Math.min(4, Runtime.getRuntime().availableProcessors()));
    try {
        final AtomicInteger numberOfLoadedKeys = new AtomicInteger(0);
        final List<Future<Validator>> futures = providers.values().stream().map(provider -> executorService.submit(() -> {
            final Validator validator = new Validator(provider.getPublicKey(), new DeletableSigner(provider.createSigner()), graffitiProvider, provider.isReadOnly());
            int loadedValidatorCount = numberOfLoadedKeys.incrementAndGet();
            if (loadedValidatorCount % 10 == 0) {
                STATUS_LOG.atLoadedValidatorNumber(loadedValidatorCount, totalValidatorCount);
            }
            return validator;
        })).collect(toList());
        final List<Validator> addedValidators = new ArrayList<>();
        for (Future<Validator> future : futures) {
            final Validator validator = future.get();
            addedValidators.add(validator);
        }
        // Only start adding validators once we've successfully loaded all keys
        addedValidators.forEach(ownedValidators::addValidator);
        STATUS_LOG.validatorsInitialised(addedValidators.stream().map(validator -> validator.getPublicKey().toAbbreviatedString()).collect(toList()));
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted while attempting to load validator key files", e);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw new RuntimeException("Unable to load validator key files", e);
    } finally {
        executorService.shutdownNow();
    }
}
Also used : GraffitiProvider(tech.pegasys.teku.validator.api.GraffitiProvider) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) DeletableSigner(tech.pegasys.teku.core.signatures.DeletableSigner) Executors(java.util.concurrent.Executors) ValidatorProvider(tech.pegasys.teku.validator.client.loader.ValidatorSource.ValidatorProvider) ArrayList(java.util.ArrayList) ExecutionException(java.util.concurrent.ExecutionException) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Future(java.util.concurrent.Future) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) STATUS_LOG(tech.pegasys.teku.infrastructure.logging.StatusLogger.STATUS_LOG) ExecutorService(java.util.concurrent.ExecutorService) Validator(tech.pegasys.teku.validator.client.Validator) DeletableSigner(tech.pegasys.teku.core.signatures.DeletableSigner) ArrayList(java.util.ArrayList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) Validator(tech.pegasys.teku.validator.client.Validator)

Example 14 with Validator

use of tech.pegasys.teku.validator.client.Validator in project teku by ConsenSys.

the class SlashingProtectionLoggerTest method shouldLogLoadedProtectionValidator.

@Test
public void shouldLogLoadedProtectionValidator() throws Exception {
    Validator validator = createProtectedValidator(publicKey);
    List<Validator> protectedValidators = new ArrayList<>();
    protectedValidators.add(validator);
    when(slashingProtector.getSigningRecord(validator.getPublicKey())).thenReturn(Optional.of(new ValidatorSigningRecord(Bytes32.ZERO, UInt64.ZERO, null, null)));
    slashingProtectionLogger.protectionSummary(protectedValidators);
    asyncRunner.executeQueuedActions();
    Set<String> protectedValidatorKeys = new HashSet<>();
    protectedValidatorKeys.add(validator.getPublicKey().toAbbreviatedString());
    verify(validatorLogger, times(1)).loadedSlashingProtection(protectedValidatorKeys);
    verify(validatorLogger, never()).notLoadedSlashingProtection(any());
    verify(validatorLogger, never()).outdatedSlashingProtection(any(), any());
}
Also used : ArrayList(java.util.ArrayList) ValidatorSigningRecord(tech.pegasys.teku.data.signingrecord.ValidatorSigningRecord) Validator(tech.pegasys.teku.validator.client.Validator) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 15 with Validator

use of tech.pegasys.teku.validator.client.Validator in project teku by ConsenSys.

the class SlashingProtectionLoggerTest method createProtectedValidator.

private Validator createProtectedValidator(BLSPublicKey publicKey) {
    Signer localSigner = new NoOpLocalSigner();
    Signer signer = new SlashingProtectedSigner(publicKey, slashingProtector, localSigner);
    return new Validator(publicKey, signer, mock(GraffitiProvider.class));
}
Also used : Signer(tech.pegasys.teku.core.signatures.Signer) ExternalSigner(tech.pegasys.teku.validator.client.signer.ExternalSigner) SlashingProtectedSigner(tech.pegasys.teku.core.signatures.SlashingProtectedSigner) NoOpLocalSigner(tech.pegasys.teku.core.signatures.NoOpLocalSigner) SlashingProtectedSigner(tech.pegasys.teku.core.signatures.SlashingProtectedSigner) GraffitiProvider(tech.pegasys.teku.validator.api.GraffitiProvider) NoOpLocalSigner(tech.pegasys.teku.core.signatures.NoOpLocalSigner) Validator(tech.pegasys.teku.validator.client.Validator)

Aggregations

Validator (tech.pegasys.teku.validator.client.Validator)40 Test (org.junit.jupiter.api.Test)32 Optional (java.util.Optional)15 ValidatorConfig (tech.pegasys.teku.validator.api.ValidatorConfig)10 BLSSignature (tech.pegasys.teku.bls.BLSSignature)7 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)7 AttestationData (tech.pegasys.teku.spec.datastructures.operations.AttestationData)7 List (java.util.List)6 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)6 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)6 ForkInfo (tech.pegasys.teku.spec.datastructures.state.ForkInfo)6 ArrayList (java.util.ArrayList)5 SimpleDataDirLayout (tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout)4 Signer (tech.pegasys.teku.core.signatures.Signer)3 ValidatorSigningRecord (tech.pegasys.teku.data.signingrecord.ValidatorSigningRecord)3 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)3 ValidatorLogger (tech.pegasys.teku.infrastructure.logging.ValidatorLogger)3 DataDirLayout (tech.pegasys.teku.service.serviceutils.layout.DataDirLayout)3 Spec (tech.pegasys.teku.spec.Spec)3 BeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock)3