Search in sources :

Example 21 with ValidatorConfig

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();
}
Also used : InteropConfig(tech.pegasys.teku.validator.api.InteropConfig) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test)

Example 22 with ValidatorConfig

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());
}
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) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test)

Example 23 with ValidatorConfig

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();
}
Also used : Validator(tech.pegasys.teku.validator.client.Validator) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test)

Example 24 with ValidatorConfig

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();
}
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 25 with ValidatorConfig

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();
}
Also used : Validator(tech.pegasys.teku.validator.client.Validator) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test)

Aggregations

ValidatorConfig (tech.pegasys.teku.validator.api.ValidatorConfig)26 Test (org.junit.jupiter.api.Test)23 Validator (tech.pegasys.teku.validator.client.Validator)10 AbstractBeaconNodeCommandTest (tech.pegasys.teku.cli.AbstractBeaconNodeCommandTest)6 SimpleDataDirLayout (tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout)4 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)4 URL (java.net.URL)3 DataDirLayout (tech.pegasys.teku.service.serviceutils.layout.DataDirLayout)3 BeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock)3 ForkInfo (tech.pegasys.teku.spec.datastructures.state.ForkInfo)3 HttpClientExternalSignerFactory (tech.pegasys.teku.validator.client.loader.HttpClientExternalSignerFactory)3 BeforeEach (org.junit.jupiter.api.BeforeEach)2 BLSSignature (tech.pegasys.teku.bls.BLSSignature)2 InteropConfig (tech.pegasys.teku.validator.api.InteropConfig)2 PostKeyResult (tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult)2 DeleteKeyResult (tech.pegasys.teku.validator.client.restapi.apis.schema.DeleteKeyResult)1