use of tech.pegasys.teku.validator.api.ValidatorApiChannel in project teku by ConsenSys.
the class AttestationProductionDutyTest method shouldReportFailureWhenAttestationIsInvalid.
@Test
void shouldReportFailureWhenAttestationIsInvalid() {
final int committeeIndex = 3;
final int committeePosition = 6;
final int committeeSize = 22;
final Validator validator = createValidator();
final AttestationData attestationData = expectCreateAttestationData(committeeIndex);
final Attestation expectedAttestation = expectSignAttestation(validator, committeePosition, committeeSize, attestationData);
when(validatorApiChannel.sendSignedAttestations(List.of(expectedAttestation))).thenReturn(SafeFuture.completedFuture(List.of(new SubmitDataError(UInt64.ZERO, "Naughty attestation"))));
final SafeFuture<Optional<AttestationData>> attestationResult = duty.addValidator(validator, committeeIndex, committeePosition, 10, committeeSize);
performAndReportDuty();
assertThat(attestationResult).isCompletedWithValue(Optional.of(attestationData));
verify(validatorApiChannel).sendSignedAttestations(List.of(expectedAttestation));
verify(validatorLogger).dutyFailed(eq(TYPE), eq(SLOT), eq(Set.of(validator.getPublicKey().toAbbreviatedString())), argThat(error -> error instanceof RestApiReportedException && error.getMessage().equals("Naughty attestation")));
verifyNoMoreInteractions(validatorLogger);
}
use of tech.pegasys.teku.validator.api.ValidatorApiChannel in project teku by ConsenSys.
the class ValidatorClientService method initializeValidators.
private void initializeValidators(ValidatorClientConfiguration config, ValidatorApiChannel validatorApiChannel, AsyncRunner asyncRunner) {
validatorLoader.loadValidators();
final OwnedValidators validators = validatorLoader.getOwnedValidators();
this.validatorIndexProvider = new ValidatorIndexProvider(validators, validatorApiChannel, asyncRunner);
final BlockDutyFactory blockDutyFactory = new BlockDutyFactory(forkProvider, validatorApiChannel, spec);
final AttestationDutyFactory attestationDutyFactory = new AttestationDutyFactory(spec, forkProvider, validatorApiChannel);
final BeaconCommitteeSubscriptions beaconCommitteeSubscriptions = new BeaconCommitteeSubscriptions(validatorApiChannel);
final DutyLoader<?> attestationDutyLoader = new RetryingDutyLoader<>(asyncRunner, new AttestationDutyLoader(validatorApiChannel, forkProvider, dependentRoot -> new SlotBasedScheduledDuties<>(attestationDutyFactory, dependentRoot), validators, validatorIndexProvider, beaconCommitteeSubscriptions, spec));
final DutyLoader<?> blockDutyLoader = new RetryingDutyLoader<>(asyncRunner, new BlockProductionDutyLoader(validatorApiChannel, dependentRoot -> new SlotBasedScheduledDuties<>(blockDutyFactory, dependentRoot), validators, validatorIndexProvider));
validatorTimingChannels.add(new BlockDutyScheduler(metricsSystem, blockDutyLoader, spec));
validatorTimingChannels.add(new AttestationDutyScheduler(metricsSystem, attestationDutyLoader, spec));
validatorTimingChannels.add(validatorLoader.getSlashingProtectionLogger());
if (spec.isMilestoneSupported(SpecMilestone.ALTAIR)) {
final ChainHeadTracker chainHeadTracker = new ChainHeadTracker();
validatorTimingChannels.add(chainHeadTracker);
final DutyLoader<SyncCommitteeScheduledDuties> syncCommitteeDutyLoader = new RetryingDutyLoader<>(asyncRunner, new SyncCommitteeDutyLoader(validators, validatorIndexProvider, spec, validatorApiChannel, chainHeadTracker, forkProvider));
validatorTimingChannels.add(new SyncCommitteeScheduler(metricsSystem, spec, syncCommitteeDutyLoader, new Random()::nextInt));
}
if (spec.isMilestoneSupported(SpecMilestone.BELLATRIX)) {
proposerConfigProvider = Optional.of(ProposerConfigProvider.create(asyncRunner, config.getValidatorConfig().getRefreshProposerConfigFromSource(), new ProposerConfigLoader(new JsonProvider().getObjectMapper()), config.getValidatorConfig().getProposerConfigSource()));
validatorTimingChannels.add(new BeaconProposerPreparer(validatorApiChannel, validatorIndexProvider, proposerConfigProvider.get(), config.getValidatorConfig().getProposerDefaultFeeRecipient(), spec));
} else {
proposerConfigProvider = Optional.empty();
}
addValidatorCountMetric(metricsSystem, validators);
this.validatorStatusLogger = new DefaultValidatorStatusLogger(metricsSystem, validators, validatorApiChannel, asyncRunner);
}
use of tech.pegasys.teku.validator.api.ValidatorApiChannel 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);
}
use of tech.pegasys.teku.validator.api.ValidatorApiChannel 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);
}
use of tech.pegasys.teku.validator.api.ValidatorApiChannel in project teku by ConsenSys.
the class MetricRecordingValidatorApiChannelTest method getDataRequestArguments.
public static Stream<Arguments> getDataRequestArguments() {
final DataStructureUtil dataStructureUtil = new DataStructureUtil(TestSpecFactory.createMinimalAltair());
final UInt64 slot = dataStructureUtil.randomUInt64();
final BLSSignature signature = dataStructureUtil.randomSignature();
final AttestationData attestationData = dataStructureUtil.randomAttestationData();
final int subcommitteeIndex = dataStructureUtil.randomPositiveInt();
final Bytes32 beaconBlockRoot = dataStructureUtil.randomBytes32();
return Stream.of(requestDataTest("getGenesisData", ValidatorApiChannel::getGenesisData, MetricRecordingValidatorApiChannel.GENESIS_TIME_REQUESTS_COUNTER_NAME, new GenesisData(dataStructureUtil.randomUInt64(), Bytes32.random())), requestDataTest("createUnsignedBlock", channel -> channel.createUnsignedBlock(slot, signature, Optional.empty()), MetricRecordingValidatorApiChannel.UNSIGNED_BLOCK_REQUESTS_COUNTER_NAME, dataStructureUtil.randomBeaconBlock(slot)), requestDataTest("createAttestationData", channel -> channel.createAttestationData(slot, 4), MetricRecordingValidatorApiChannel.ATTESTATION_DATA_REQUEST_COUNTER_NAME, dataStructureUtil.randomAttestationData()), requestDataTest("createAggregate", channel -> channel.createAggregate(attestationData.getSlot(), attestationData.hashTreeRoot()), MetricRecordingValidatorApiChannel.AGGREGATE_REQUESTS_COUNTER_NAME, dataStructureUtil.randomAttestation()), requestDataTest("createSyncCommitteeContribution", channel -> channel.createSyncCommitteeContribution(slot, subcommitteeIndex, beaconBlockRoot), MetricRecordingValidatorApiChannel.CREATE_SYNC_COMMITTEE_CONTRIBUTION_REQUESTS_COUNTER_NAME, dataStructureUtil.randomSyncCommitteeContribution(slot)));
}
Aggregations