Search in sources :

Example 26 with Validator

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

the class ValidatorLoaderTest method initializeValidatorsWithDuplicateKeysInLocalAndExternalSignersTakesExternalAsPriority.

@Test
void initializeValidatorsWithDuplicateKeysInLocalAndExternalSignersTakesExternalAsPriority(@TempDir Path tempDir) throws Exception {
    writeKeystore(tempDir);
    final ValidatorConfig config = ValidatorConfig.builder().validatorExternalSignerUrl(SIGNER_URL).validatorExternalSignerPublicKeySources(Collections.singletonList(PUBLIC_KEY1.toString())).validatorKeys(List.of(tempDir.toAbsolutePath() + File.pathSeparator + tempDir.toAbsolutePath())).build();
    final ValidatorLoader validatorLoader = ValidatorLoader.create(spec, config, disabledInteropConfig, httpClientFactory, slashingProtector, slashingProtectionLogger, publicKeyLoader, asyncRunner, metricsSystem, Optional.empty());
    validatorLoader.loadValidators();
    final OwnedValidators validators = validatorLoader.getOwnedValidators();
    // Both local and external validators get loaded.
    assertThat(validators.getValidatorCount()).isEqualTo(1);
    // Local validators are listed first
    final Validator validator = validators.getValidator(PUBLIC_KEY1).orElseThrow();
    assertThat(validator).isNotNull();
    assertThat(validator.getPublicKey()).isEqualTo(PUBLIC_KEY1);
    assertThat(validator.getSigner().isLocal()).isFalse();
}
Also used : Validator(tech.pegasys.teku.validator.client.Validator) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test)

Example 27 with Validator

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

the class ValidatorLoaderTest method shouldLoadPublicKeysFromUrls.

@Test
void shouldLoadPublicKeysFromUrls() {
    final PublicKeyLoader publicKeyLoader = mock(PublicKeyLoader.class);
    final List<BLSPublicKey> expectedKeys = List.of(PUBLIC_KEY1, PUBLIC_KEY2);
    final String publicKeysUrl = "http://example.com";
    when(publicKeyLoader.getPublicKeys(List.of(publicKeysUrl))).thenReturn(expectedKeys);
    final ValidatorConfig config = ValidatorConfig.builder().validatorExternalSignerUrl(SIGNER_URL).validatorExternalSignerPublicKeySources(Collections.singletonList(publicKeysUrl)).validatorExternalSignerSlashingProtectionEnabled(true).build();
    final ValidatorLoader validatorLoader = ValidatorLoader.create(spec, config, disabledInteropConfig, httpClientFactory, slashingProtector, slashingProtectionLogger, publicKeyLoader, asyncRunner, metricsSystem, Optional.empty());
    validatorLoader.loadValidators();
    final OwnedValidators validators = validatorLoader.getOwnedValidators();
    assertThat(validators.getValidatorCount()).isEqualTo(2);
    final Validator validator1 = validators.getValidator(PUBLIC_KEY1).orElseThrow();
    assertThat(validator1).isNotNull();
    assertThat(validator1.getPublicKey()).isEqualTo(PUBLIC_KEY1);
    assertThat(validator1.getSigner().isLocal()).isFalse();
    final Validator validator2 = validators.getValidator(PUBLIC_KEY2).orElseThrow();
    assertThat(validator2).isNotNull();
    assertThat(validator2.getPublicKey()).isEqualTo(PUBLIC_KEY2);
    assertThat(validator2.getSigner().isLocal()).isFalse();
}
Also used : BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) Validator(tech.pegasys.teku.validator.client.Validator) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test)

Example 28 with Validator

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

the class ValidatorLoaderTest method initializeValidatorsWithBothLocalAndExternalSigners.

@Test
void initializeValidatorsWithBothLocalAndExternalSigners(@TempDir Path tempDir) throws Exception {
    writeKeystore(tempDir);
    final ValidatorConfig config = ValidatorConfig.builder().validatorExternalSignerUrl(SIGNER_URL).validatorExternalSignerPublicKeySources(Collections.singletonList(PUBLIC_KEY2.toString())).validatorKeys(List.of(tempDir.toAbsolutePath() + File.pathSeparator + tempDir.toAbsolutePath())).build();
    final ValidatorLoader validatorLoader = ValidatorLoader.create(spec, config, disabledInteropConfig, httpClientFactory, slashingProtector, slashingProtectionLogger, publicKeyLoader, asyncRunner, metricsSystem, Optional.empty());
    validatorLoader.loadValidators();
    final OwnedValidators validators = validatorLoader.getOwnedValidators();
    assertThat(validators.getValidatorCount()).isEqualTo(2);
    final Validator validator1 = validators.getValidator(PUBLIC_KEY1).orElseThrow();
    assertThat(validator1).isNotNull();
    assertThat(validator1.getPublicKey()).isEqualTo(PUBLIC_KEY1);
    assertThat(validator1.getSigner().isLocal()).isTrue();
    final Validator validator2 = validators.getValidator(PUBLIC_KEY2).orElseThrow();
    assertThat(validator2).isNotNull();
    assertThat(validator2.getPublicKey()).isEqualTo(PUBLIC_KEY2);
    assertThat(validator2.getSigner().isLocal()).isFalse();
}
Also used : Validator(tech.pegasys.teku.validator.client.Validator) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test)

Example 29 with Validator

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

the class ValidatorLoaderTest method initializeValidatorsWithExternalSignerAndNoSlashingProtection.

@Test
void initializeValidatorsWithExternalSignerAndNoSlashingProtection() {
    final ValidatorConfig config = ValidatorConfig.builder().validatorExternalSignerUrl(SIGNER_URL).validatorExternalSignerPublicKeySources(Collections.singletonList(PUBLIC_KEY1.toString())).validatorExternalSignerSlashingProtectionEnabled(false).build();
    final ValidatorLoader validatorLoader = ValidatorLoader.create(spec, config, disabledInteropConfig, httpClientFactory, slashingProtector, slashingProtectionLogger, publicKeyLoader, asyncRunner, metricsSystem, Optional.empty());
    validatorLoader.loadValidators();
    final OwnedValidators validators = validatorLoader.getOwnedValidators();
    assertThat(validators.getValidatorCount()).isEqualTo(1);
    final Validator validator = validators.getValidator(PUBLIC_KEY1).orElseThrow();
    assertThat(validator).isNotNull();
    assertThat(validator.getPublicKey()).isEqualTo(PUBLIC_KEY1);
    assertThat(validator.getSigner().isLocal()).isFalse();
    final BeaconBlock block = dataStructureUtil.randomBeaconBlock(10);
    final ForkInfo forkInfo = dataStructureUtil.randomForkInfo();
    when(slashingProtector.maySignBlock(PUBLIC_KEY1, forkInfo.getGenesisValidatorsRoot(), block.getSlot())).thenReturn(SafeFuture.completedFuture(true));
    when(httpClient.sendAsync(any(), any())).thenReturn(new SafeFuture<>());
    final SafeFuture<BLSSignature> result = validator.getSigner().signBlock(block, forkInfo);
    assertThat(result).isNotDone();
    // Confirm request was sent without checking with the slashing protector
    verifyNoInteractions(slashingProtector);
    verify(httpClient).sendAsync(any(), any());
}
Also used : ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) Validator(tech.pegasys.teku.validator.client.Validator) BLSSignature(tech.pegasys.teku.bls.BLSSignature) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test)

Example 30 with Validator

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

the class SlashingProtectionLoggerTest method shouldLogLoadedButOutdatedProtectionValidator.

@Test
public void shouldLogLoadedButOutdatedProtectionValidator() 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.onSlot(spec.computeStartSlotAtEpoch(UInt64.valueOf(1000)));
    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, times(1)).outdatedSlashingProtection(eq(protectedValidatorKeys), 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)

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