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();
}
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();
}
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();
}
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());
}
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());
}
Aggregations