Search in sources :

Example 1 with GenesisDataProvider

use of tech.pegasys.teku.validator.beaconnode.GenesisDataProvider in project teku by ConsenSys.

the class RemoteBeaconNodeApi method create.

public static BeaconNodeApi create(final ServiceConfig serviceConfig, final AsyncRunner asyncRunner, final URI beaconNodeApiEndpoint, final Spec spec, final boolean generateEarlyAttestations) {
    final OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder().readTimeout(READ_TIMEOUT);
    HttpUrl apiEndpoint = HttpUrl.get(beaconNodeApiEndpoint);
    Preconditions.checkNotNull(apiEndpoint, String.format("Failed to convert remote api endpoint (%s) to a valid url", UrlSanitizer.sanitizePotentialUrl(beaconNodeApiEndpoint.toString())));
    OkHttpClientAuthLoggingIntercepter.addAuthenticator(apiEndpoint, httpClientBuilder);
    // Strip any authentication info from the URL to ensure it doesn't get logged.
    apiEndpoint = apiEndpoint.newBuilder().username("").password("").build();
    final OkHttpClient okHttpClient = httpClientBuilder.build();
    final OkHttpValidatorRestApiClient apiClient = new OkHttpValidatorRestApiClient(apiEndpoint, okHttpClient);
    final ValidatorApiChannel validatorApiChannel = new MetricRecordingValidatorApiChannel(serviceConfig.getMetricsSystem(), new RemoteValidatorApiHandler(spec, apiClient, asyncRunner));
    final ValidatorTimingChannel validatorTimingChannel = serviceConfig.getEventChannels().getPublisher(ValidatorTimingChannel.class);
    final BeaconChainEventAdapter beaconChainEventAdapter = new EventSourceBeaconChainEventAdapter(apiEndpoint, okHttpClient, new TimeBasedEventAdapter(new GenesisDataProvider(asyncRunner, validatorApiChannel), new RepeatingTaskScheduler(asyncRunner, serviceConfig.getTimeProvider()), serviceConfig.getTimeProvider(), validatorTimingChannel, spec), validatorTimingChannel, serviceConfig.getMetricsSystem(), generateEarlyAttestations);
    return new RemoteBeaconNodeApi(beaconChainEventAdapter, validatorApiChannel);
}
Also used : OkHttpClient(okhttp3.OkHttpClient) ValidatorTimingChannel(tech.pegasys.teku.validator.api.ValidatorTimingChannel) MetricRecordingValidatorApiChannel(tech.pegasys.teku.validator.beaconnode.metrics.MetricRecordingValidatorApiChannel) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) RepeatingTaskScheduler(tech.pegasys.teku.infrastructure.async.timed.RepeatingTaskScheduler) GenesisDataProvider(tech.pegasys.teku.validator.beaconnode.GenesisDataProvider) TimeBasedEventAdapter(tech.pegasys.teku.validator.beaconnode.TimeBasedEventAdapter) HttpUrl(okhttp3.HttpUrl) OkHttpValidatorRestApiClient(tech.pegasys.teku.validator.remote.apiclient.OkHttpValidatorRestApiClient) MetricRecordingValidatorApiChannel(tech.pegasys.teku.validator.beaconnode.metrics.MetricRecordingValidatorApiChannel) BeaconChainEventAdapter(tech.pegasys.teku.validator.beaconnode.BeaconChainEventAdapter)

Example 2 with GenesisDataProvider

use of tech.pegasys.teku.validator.beaconnode.GenesisDataProvider in project teku by ConsenSys.

the class InProcessBeaconNodeApi method create.

public static BeaconNodeApi create(final ServiceConfig services, final AsyncRunner asyncRunner, final boolean generateEarlyAttestations, final Spec spec) {
    final MetricsSystem metricsSystem = services.getMetricsSystem();
    final EventChannels eventChannels = services.getEventChannels();
    final ValidatorApiChannel validatorApiChannel = new MetricRecordingValidatorApiChannel(metricsSystem, eventChannels.getPublisher(ValidatorApiChannel.class, asyncRunner));
    final ValidatorTimingChannel validatorTimingChannel = eventChannels.getPublisher(ValidatorTimingChannel.class);
    final TimeBasedEventAdapter timeBasedEventAdapter = new TimeBasedEventAdapter(new GenesisDataProvider(asyncRunner, validatorApiChannel), new RepeatingTaskScheduler(asyncRunner, services.getTimeProvider()), services.getTimeProvider(), validatorTimingChannel, spec);
    final BeaconChainEventAdapter beaconChainEventAdapter = new IndependentTimerEventChannelEventAdapter(eventChannels, generateEarlyAttestations, timeBasedEventAdapter, validatorTimingChannel);
    return new InProcessBeaconNodeApi(validatorApiChannel, beaconChainEventAdapter);
}
Also used : MetricRecordingValidatorApiChannel(tech.pegasys.teku.validator.beaconnode.metrics.MetricRecordingValidatorApiChannel) BeaconChainEventAdapter(tech.pegasys.teku.validator.beaconnode.BeaconChainEventAdapter) ValidatorTimingChannel(tech.pegasys.teku.validator.api.ValidatorTimingChannel) EventChannels(tech.pegasys.teku.infrastructure.events.EventChannels) MetricRecordingValidatorApiChannel(tech.pegasys.teku.validator.beaconnode.metrics.MetricRecordingValidatorApiChannel) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) RepeatingTaskScheduler(tech.pegasys.teku.infrastructure.async.timed.RepeatingTaskScheduler) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) GenesisDataProvider(tech.pegasys.teku.validator.beaconnode.GenesisDataProvider) TimeBasedEventAdapter(tech.pegasys.teku.validator.beaconnode.TimeBasedEventAdapter)

Example 3 with GenesisDataProvider

use of tech.pegasys.teku.validator.beaconnode.GenesisDataProvider 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

ValidatorApiChannel (tech.pegasys.teku.validator.api.ValidatorApiChannel)3 ValidatorTimingChannel (tech.pegasys.teku.validator.api.ValidatorTimingChannel)3 GenesisDataProvider (tech.pegasys.teku.validator.beaconnode.GenesisDataProvider)3 MetricsSystem (org.hyperledger.besu.plugin.services.MetricsSystem)2 RepeatingTaskScheduler (tech.pegasys.teku.infrastructure.async.timed.RepeatingTaskScheduler)2 EventChannels (tech.pegasys.teku.infrastructure.events.EventChannels)2 BeaconChainEventAdapter (tech.pegasys.teku.validator.beaconnode.BeaconChainEventAdapter)2 TimeBasedEventAdapter (tech.pegasys.teku.validator.beaconnode.TimeBasedEventAdapter)2 MetricRecordingValidatorApiChannel (tech.pegasys.teku.validator.beaconnode.metrics.MetricRecordingValidatorApiChannel)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Random (java.util.Random)1 HttpUrl (okhttp3.HttpUrl)1 OkHttpClient (okhttp3.OkHttpClient)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 LocalSlashingProtector (tech.pegasys.teku.core.signatures.LocalSlashingProtector)1 SlashingProtector (tech.pegasys.teku.core.signatures.SlashingProtector)1