Search in sources :

Example 1 with ValidatorRestApiConfig

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

the class DebugToolsCommand method generateSwaggerDocs.

@Command(name = "generate-swagger-docs", description = "Generate swagger-docs for rest APIs.", mixinStandardHelpOptions = true, showDefaultValues = true, abbreviateSynopsis = true, versionProvider = PicoCliVersionProvider.class, synopsisHeading = "%n", descriptionHeading = "%nDescription:%n%n", optionListHeading = "%nOptions:%n", footerHeading = "%n", footer = "Teku is licensed under the Apache License 2.0")
public int generateSwaggerDocs(@Option(required = true, names = { "--output", "-o" }, description = "Directory to write swagger docs to.") final Path outputPath) throws Exception {
    if (!outputPath.toFile().mkdirs() && !outputPath.toFile().isDirectory()) {
        throw new InvalidConfigurationException(String.format("Destination path %s could not be created or is not a directory", outputPath.toAbsolutePath()));
    }
    ValidatorRestApiConfig config = ValidatorRestApiConfig.builder().restApiDocsEnabled(true).build();
    final Path tempDir = Files.createTempDirectory("teku_debug_tools");
    if (!tempDir.toFile().mkdirs() && !tempDir.toFile().isDirectory()) {
        System.err.println("Could not create temp directory");
        return 1;
    }
    tempDir.toFile().deleteOnExit();
    DataDirLayout dataDirLayout = new SeparateServiceDataDirLayout(tempDir, Optional.empty(), Optional.empty());
    final KeyManager keyManager = new NoOpKeyManager();
    RestApi api = ValidatorRestApi.create(config, keyManager, dataDirLayout);
    if (api.getRestApiDocs().isPresent()) {
        final String docs = api.getRestApiDocs().get();
        final Path validatorApiPath = outputPath.resolve("validator-api.json");
        System.out.println("Writing validator-api to " + validatorApiPath.toAbsolutePath());
        try (FileWriter fileWriter = new FileWriter(validatorApiPath.toFile(), StandardCharsets.UTF_8)) {
            fileWriter.write(docs);
        } catch (IOException e) {
            System.err.println("Failed to write validator-api.json: " + e.getMessage());
            return 1;
        }
    } else {
        System.err.println("Failed to create rest api document for the validator api.");
        return 1;
    }
    return 0;
}
Also used : Path(java.nio.file.Path) ValidatorRestApi(tech.pegasys.teku.validator.client.restapi.ValidatorRestApi) RestApi(tech.pegasys.teku.infrastructure.restapi.RestApi) NoOpKeyManager(tech.pegasys.teku.validator.client.NoOpKeyManager) FileWriter(java.io.FileWriter) IOException(java.io.IOException) DataDirLayout(tech.pegasys.teku.service.serviceutils.layout.DataDirLayout) SeparateServiceDataDirLayout(tech.pegasys.teku.service.serviceutils.layout.SeparateServiceDataDirLayout) ValidatorRestApiConfig(tech.pegasys.teku.validator.client.restapi.ValidatorRestApiConfig) KeyManager(tech.pegasys.teku.validator.client.KeyManager) NoOpKeyManager(tech.pegasys.teku.validator.client.NoOpKeyManager) InvalidConfigurationException(tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException) SeparateServiceDataDirLayout(tech.pegasys.teku.service.serviceutils.layout.SeparateServiceDataDirLayout) Command(picocli.CommandLine.Command)

Example 2 with ValidatorRestApiConfig

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

the class ValidatorClientService method create.

public static ValidatorClientService create(final ServiceConfig services, final ValidatorClientConfiguration config) {
    final EventChannels eventChannels = services.getEventChannels();
    final AsyncRunner asyncRunner = services.createAsyncRunner("validator");
    final boolean generateEarlyAttestations = config.getValidatorConfig().generateEarlyAttestations();
    final BeaconNodeApi beaconNodeApi = config.getValidatorConfig().getBeaconNodeApiEndpoint().map(endpoint -> RemoteBeaconNodeApi.create(services, asyncRunner, endpoint, config.getSpec(), generateEarlyAttestations)).orElseGet(() -> InProcessBeaconNodeApi.create(services, asyncRunner, generateEarlyAttestations, config.getSpec()));
    final ValidatorApiChannel validatorApiChannel = beaconNodeApi.getValidatorApi();
    final GenesisDataProvider genesisDataProvider = new GenesisDataProvider(asyncRunner, validatorApiChannel);
    final ForkProvider forkProvider = new ForkProvider(config.getSpec(), genesisDataProvider);
    final ValidatorLoader validatorLoader = createValidatorLoader(config, asyncRunner, services);
    final ValidatorRestApiConfig validatorApiConfig = config.getValidatorRestApiConfig();
    Optional<RestApi> validatorRestApi = Optional.empty();
    if (validatorApiConfig.isRestApiEnabled()) {
        validatorRestApi = Optional.of(ValidatorRestApi.create(validatorApiConfig, new ActiveKeyManager(validatorLoader, services.getEventChannels().getPublisher(ValidatorTimingChannel.class)), services.getDataDirLayout()));
    } else {
        LOG.info("validator-api-enabled is false, not starting rest api.");
    }
    ValidatorClientService validatorClientService = new ValidatorClientService(eventChannels, validatorLoader, beaconNodeApi, validatorRestApi, forkProvider, config.getSpec(), services.getMetricsSystem());
    asyncRunner.runAsync(() -> validatorClientService.initializeValidators(config, validatorApiChannel, asyncRunner)).propagateTo(validatorClientService.initializationComplete);
    return validatorClientService;
}
Also used : BlockDutyFactory(tech.pegasys.teku.validator.client.duties.BlockDutyFactory) ValidatorLoader(tech.pegasys.teku.validator.client.loader.ValidatorLoader) DataDirLayout(tech.pegasys.teku.service.serviceutils.layout.DataDirLayout) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) ValidatorRestApiConfig(tech.pegasys.teku.validator.client.restapi.ValidatorRestApiConfig) Random(java.util.Random) LocalSlashingProtector(tech.pegasys.teku.core.signatures.LocalSlashingProtector) ArrayList(java.util.ArrayList) EventChannels(tech.pegasys.teku.infrastructure.events.EventChannels) ValidatorRestApi(tech.pegasys.teku.validator.client.restapi.ValidatorRestApi) PublicKeyLoader(tech.pegasys.teku.validator.client.loader.PublicKeyLoader) SlotBasedScheduledDuties(tech.pegasys.teku.validator.client.duties.SlotBasedScheduledDuties) JsonProvider(tech.pegasys.teku.provider.JsonProvider) ChainHeadTracker(tech.pegasys.teku.validator.client.duties.synccommittee.ChainHeadTracker) BeaconCommitteeSubscriptions(tech.pegasys.teku.validator.client.duties.BeaconCommitteeSubscriptions) Spec(tech.pegasys.teku.spec.Spec) Path(java.nio.file.Path) Service(tech.pegasys.teku.service.serviceutils.Service) ProposerConfigProvider(tech.pegasys.teku.validator.client.proposerconfig.ProposerConfigProvider) AsyncRunner(tech.pegasys.teku.infrastructure.async.AsyncRunner) ValidatorLogger(tech.pegasys.teku.infrastructure.logging.ValidatorLogger) SyncDataAccessor(tech.pegasys.teku.infrastructure.io.SyncDataAccessor) RestApi(tech.pegasys.teku.infrastructure.restapi.RestApi) ServiceConfig(tech.pegasys.teku.service.serviceutils.ServiceConfig) BeaconNodeApi(tech.pegasys.teku.validator.beaconnode.BeaconNodeApi) SyncCommitteeScheduledDuties(tech.pegasys.teku.validator.client.duties.synccommittee.SyncCommitteeScheduledDuties) List(java.util.List) Logger(org.apache.logging.log4j.Logger) TekuMetricCategory(tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) InProcessBeaconNodeApi(tech.pegasys.teku.validator.eventadapter.InProcessBeaconNodeApi) OwnedValidators(tech.pegasys.teku.validator.client.loader.OwnedValidators) SlashingProtector(tech.pegasys.teku.core.signatures.SlashingProtector) SystemSignalListener(tech.pegasys.teku.infrastructure.io.SystemSignalListener) GenesisDataProvider(tech.pegasys.teku.validator.beaconnode.GenesisDataProvider) ProposerConfigLoader(tech.pegasys.teku.validator.client.proposerconfig.loader.ProposerConfigLoader) SlashingProtectionLogger(tech.pegasys.teku.validator.client.loader.SlashingProtectionLogger) Optional(java.util.Optional) RemoteBeaconNodeApi(tech.pegasys.teku.validator.remote.RemoteBeaconNodeApi) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) LogManager(org.apache.logging.log4j.LogManager) SpecMilestone(tech.pegasys.teku.spec.SpecMilestone) ValidatorTimingChannel(tech.pegasys.teku.validator.api.ValidatorTimingChannel) AttestationDutyFactory(tech.pegasys.teku.validator.client.duties.attestations.AttestationDutyFactory) ValidatorRestApi(tech.pegasys.teku.validator.client.restapi.ValidatorRestApi) RestApi(tech.pegasys.teku.infrastructure.restapi.RestApi) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) GenesisDataProvider(tech.pegasys.teku.validator.beaconnode.GenesisDataProvider) BeaconNodeApi(tech.pegasys.teku.validator.beaconnode.BeaconNodeApi) InProcessBeaconNodeApi(tech.pegasys.teku.validator.eventadapter.InProcessBeaconNodeApi) RemoteBeaconNodeApi(tech.pegasys.teku.validator.remote.RemoteBeaconNodeApi) AsyncRunner(tech.pegasys.teku.infrastructure.async.AsyncRunner) ValidatorLoader(tech.pegasys.teku.validator.client.loader.ValidatorLoader) EventChannels(tech.pegasys.teku.infrastructure.events.EventChannels) ValidatorRestApiConfig(tech.pegasys.teku.validator.client.restapi.ValidatorRestApiConfig)

Aggregations

Path (java.nio.file.Path)2 RestApi (tech.pegasys.teku.infrastructure.restapi.RestApi)2 DataDirLayout (tech.pegasys.teku.service.serviceutils.layout.DataDirLayout)2 ValidatorRestApi (tech.pegasys.teku.validator.client.restapi.ValidatorRestApi)2 ValidatorRestApiConfig (tech.pegasys.teku.validator.client.restapi.ValidatorRestApiConfig)2 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Random (java.util.Random)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 MetricsSystem (org.hyperledger.besu.plugin.services.MetricsSystem)1 Command (picocli.CommandLine.Command)1 LocalSlashingProtector (tech.pegasys.teku.core.signatures.LocalSlashingProtector)1 SlashingProtector (tech.pegasys.teku.core.signatures.SlashingProtector)1 AsyncRunner (tech.pegasys.teku.infrastructure.async.AsyncRunner)1 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)1 EventChannels (tech.pegasys.teku.infrastructure.events.EventChannels)1