Search in sources :

Example 1 with PostKeyResult

use of tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult in project teku by ConsenSys.

the class ActiveKeyManager method importExternalValidators.

@Override
public List<PostKeyResult> importExternalValidators(final List<ExternalValidator> validators) {
    final List<PostKeyResult> importResults = new ArrayList<>();
    boolean reloadRequired = false;
    for (ExternalValidator v : validators) {
        try {
            importResults.add(validatorLoader.loadExternalMutableValidator(v.getPublicKey(), v.getUrl()));
            if (importResults.get(importResults.size() - 1).getImportStatus() == ImportStatus.IMPORTED) {
                reloadRequired = true;
            }
        } catch (Exception e) {
            importResults.add(PostKeyResult.error(e.getMessage()));
        }
    }
    if (reloadRequired) {
        validatorTimingChannel.onValidatorsAdded();
    }
    return importResults;
}
Also used : ExternalValidator(tech.pegasys.teku.validator.client.restapi.apis.schema.ExternalValidator) PostKeyResult(tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult) ArrayList(java.util.ArrayList) KeyStoreValidationException(tech.pegasys.signers.bls.keystore.KeyStoreValidationException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with PostKeyResult

use of tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult in project teku by ConsenSys.

the class ValidatorLoaderTest method shouldNotLoadMutableValidatorIfNotEnabled.

@Test
void shouldNotLoadMutableValidatorIfNotEnabled() {
    final ValidatorConfig config = ValidatorConfig.builder().build();
    final ValidatorLoader validatorLoader = ValidatorLoader.create(spec, config, disabledInteropConfig, httpClientFactory, slashingProtector, slashingProtectionLogger, publicKeyLoader, asyncRunner, metricsSystem, Optional.empty());
    validatorLoader.loadValidators();
    final PostKeyResult result = validatorLoader.loadLocalMutableValidator(null, "", Optional.empty());
    assertThat(result).isEqualTo(PostKeyResult.error("Not able to add validator"));
}
Also used : PostKeyResult(tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test)

Example 3 with PostKeyResult

use of tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult in project teku by ConsenSys.

the class ValidatorLoaderTest method shouldLoadMutableValidatorIfEnabled.

@Test
void shouldLoadMutableValidatorIfEnabled(@TempDir final Path tempDir) throws Exception {
    final ValidatorConfig config = ValidatorConfig.builder().build();
    final ValidatorLoader validatorLoader = ValidatorLoader.create(spec, config, disabledInteropConfig, httpClientFactory, slashingProtector, slashingProtectionLogger, publicKeyLoader, asyncRunner, metricsSystem, Optional.of(new SimpleDataDirLayout(tempDir)));
    validatorLoader.loadValidators();
    final String keystoreString = Resources.toString(Resources.getResource("pbkdf2TestVector.json"), StandardCharsets.UTF_8);
    PostKeyResult result = validatorLoader.loadLocalMutableValidator(KeyStoreLoader.loadFromString(keystoreString), "testpassword", Optional.empty());
    assertThat(result.getImportStatus()).isEqualTo(ImportStatus.IMPORTED);
    final Optional<Validator> validator = validatorLoader.getOwnedValidators().getValidator(PUBLIC_KEY1);
    assertThat(validator).isPresent();
    assertThat(validator.orElseThrow().getSigner()).isInstanceOf(DeletableSigner.class);
}
Also used : SimpleDataDirLayout(tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout) PostKeyResult(tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult) Validator(tech.pegasys.teku.validator.client.Validator) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test)

Example 4 with PostKeyResult

use of tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult in project teku by ConsenSys.

the class PostRemoteKeysTest method validResponse_shouldGiveValidPostKeyResults.

@Test
void validResponse_shouldGiveValidPostKeyResults() throws JsonProcessingException, MalformedURLException {
    final PostRemoteKeys endpoint = new PostRemoteKeys(keyManager);
    List<ExternalValidator> externalValidators = List.of(new ExternalValidator(BLSTestUtil.randomKeyPair(1).getPublicKey(), Optional.of(new URL("http://host.com"))), new ExternalValidator(BLSTestUtil.randomKeyPair(2).getPublicKey(), Optional.empty()));
    final PostRemoteKeysRequest body = new PostRemoteKeysRequest(externalValidators);
    when(request.getRequestBody()).thenReturn(body);
    List<PostKeyResult> results = List.of(PostKeyResult.success(), PostKeyResult.success());
    when(keyManager.importExternalValidators(externalValidators)).thenReturn(results);
    endpoint.handle(request);
    verify(request).respondOk(results);
}
Also used : ExternalValidator(tech.pegasys.teku.validator.client.restapi.apis.schema.ExternalValidator) PostKeyResult(tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult) PostRemoteKeysRequest(tech.pegasys.teku.validator.client.restapi.apis.schema.PostRemoteKeysRequest) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 5 with PostKeyResult

use of tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult in project teku by ConsenSys.

the class PostRemoteKeysTest method duplicate_shouldGiveDuplicateResponse.

@Test
void duplicate_shouldGiveDuplicateResponse() throws JsonProcessingException, MalformedURLException {
    final PostRemoteKeys endpoint = new PostRemoteKeys(keyManager);
    BLSPublicKey publicKey = BLSTestUtil.randomKeyPair(1).getPublicKey();
    URL url = new URL("http://host.com");
    List<ExternalValidator> externalValidators = List.of(new ExternalValidator(publicKey, Optional.of(url)), new ExternalValidator(publicKey, Optional.of(url)));
    final PostRemoteKeysRequest body = new PostRemoteKeysRequest(externalValidators);
    when(request.getRequestBody()).thenReturn(body);
    List<PostKeyResult> results = List.of(PostKeyResult.success(), PostKeyResult.duplicate());
    when(keyManager.importExternalValidators(externalValidators)).thenReturn(results);
    endpoint.handle(request);
    verify(request).respondOk(results);
}
Also used : ExternalValidator(tech.pegasys.teku.validator.client.restapi.apis.schema.ExternalValidator) PostKeyResult(tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult) PostRemoteKeysRequest(tech.pegasys.teku.validator.client.restapi.apis.schema.PostRemoteKeysRequest) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Aggregations

PostKeyResult (tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult)5 Test (org.junit.jupiter.api.Test)4 ExternalValidator (tech.pegasys.teku.validator.client.restapi.apis.schema.ExternalValidator)3 URL (java.net.URL)2 ValidatorConfig (tech.pegasys.teku.validator.api.ValidatorConfig)2 PostRemoteKeysRequest (tech.pegasys.teku.validator.client.restapi.apis.schema.PostRemoteKeysRequest)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ArrayList (java.util.ArrayList)1 KeyStoreValidationException (tech.pegasys.signers.bls.keystore.KeyStoreValidationException)1 SimpleDataDirLayout (tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout)1 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)1 Validator (tech.pegasys.teku.validator.client.Validator)1