use of tech.pegasys.teku.validator.api.ValidatorConfig in project teku by ConsenSys.
the class ValidatorLoaderTest method doNotInitializeInteropValidatorsWhenInteropIsDisabled.
@Test
void doNotInitializeInteropValidatorsWhenInteropIsDisabled() {
final int ownedValidatorCount = 10;
final InteropConfig interopConfig = InteropConfig.builder().specProvider(spec).interopEnabled(false).interopOwnedValidatorCount(ownedValidatorCount).build();
final ValidatorConfig config = ValidatorConfig.builder().build();
final ValidatorLoader validatorLoader = ValidatorLoader.create(spec, config, interopConfig, httpClientFactory, slashingProtector, slashingProtectionLogger, publicKeyLoader, asyncRunner, metricsSystem, Optional.empty());
validatorLoader.loadValidators();
final OwnedValidators validators = validatorLoader.getOwnedValidators();
assertThat(validators.hasNoValidators()).isTrue();
}
use of tech.pegasys.teku.validator.api.ValidatorConfig in project teku by ConsenSys.
the class ValidatorLoaderTest method shouldEnableSlashingProtectionForLocalValidators.
@Test
void shouldEnableSlashingProtectionForLocalValidators(@TempDir Path tempDir) throws Exception {
writeKeystore(tempDir);
final ValidatorConfig config = ValidatorConfig.builder().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(1);
final Validator validator = validators.getValidator(PUBLIC_KEY1).orElseThrow();
final BeaconBlock block = dataStructureUtil.randomBeaconBlock(1);
final ForkInfo forkInfo = dataStructureUtil.randomForkInfo();
when(slashingProtector.maySignBlock(any(), any(), any())).thenReturn(new SafeFuture<>());
assertThat(validator.getSigner().signBlock(block, forkInfo)).isNotDone();
verify(slashingProtector).maySignBlock(validator.getPublicKey(), forkInfo.getGenesisValidatorsRoot(), block.getSlot());
}
use of tech.pegasys.teku.validator.api.ValidatorConfig 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.api.ValidatorConfig 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.api.ValidatorConfig 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();
}
Aggregations