use of tech.pegasys.teku.api.request.v1.validator.ValidatorLivenessRequest in project teku by ConsenSys.
the class PostValidatorLiveness method handle.
@OpenApi(path = ROUTE, method = HttpMethod.GET, summary = "Get Validator Liveness", tags = { TAG_EXPERIMENTAL }, requestBody = @OpenApiRequestBody(content = { @OpenApiContent(from = ValidatorLivenessRequest.class) }), description = "Requests the beacon node to indicate if a validator has been" + " observed to be live in a given epoch. The beacon node might detect liveness by" + " observing messages from the validator on the network, in the beacon chain," + " from its API or from any other source. It is important to note that the" + " values returned by the beacon node are not canonical; they are best-effort" + " and based upon a subjective view of the network.", responses = { @OpenApiResponse(status = RES_OK, content = @OpenApiContent(from = PostValidatorLivenessResponse.class)), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Invalid parameter supplied"), @OpenApiResponse(status = RES_INTERNAL_ERROR), @OpenApiResponse(status = RES_SERVICE_UNAVAILABLE, description = SERVICE_UNAVAILABLE) })
@Override
public void handle(Context ctx) throws Exception {
if (!chainDataProvider.isStoreAvailable() || syncDataProvider.isSyncing()) {
throw new ServiceUnavailableException();
}
try {
final ValidatorLivenessRequest request = parseRequestBody(ctx.body(), ValidatorLivenessRequest.class);
SafeFuture<Optional<PostValidatorLivenessResponse>> future = nodeDataProvider.getValidatorLiveness(request, chainDataProvider.getCurrentEpoch());
handleOptionalResult(ctx, future, this::handleResult, this::handleError, SC_SERVICE_UNAVAILABLE);
} catch (IllegalArgumentException ex) {
LOG.trace("Illegal argument in PostValidatorLiveness", ex);
ctx.status(SC_BAD_REQUEST);
ctx.json(BadRequest.badRequest(jsonProvider, ex.getMessage()));
}
}
use of tech.pegasys.teku.api.request.v1.validator.ValidatorLivenessRequest in project teku by ConsenSys.
the class PostValidatorLivenessIntegrationTest method shouldDetectActiveValidator.
@Test
public void shouldDetectActiveValidator() throws IOException {
final UInt64 epoch = UInt64.ZERO;
final UInt64 validatorIndex = UInt64.ONE;
startRestAPIAtGenesis(SpecMilestone.ALTAIR);
blockReceivedFromProposer(spec.computeStartSlotAtEpoch(epoch).plus(1), validatorIndex);
setCurrentSlot(12);
when(syncService.getCurrentSyncState()).thenReturn(SyncState.IN_SYNC);
final ValidatorLivenessRequest request = new ValidatorLivenessRequest(epoch, List.of(validatorIndex));
Response response = post(PostValidatorLiveness.ROUTE, jsonProvider.objectToJSON(request));
assertThat(response.code()).isEqualTo(SC_OK);
final PostValidatorLivenessResponse result = jsonProvider.jsonToObject(response.body().string(), PostValidatorLivenessResponse.class);
assertThat(result.data.get(0)).isEqualTo(new ValidatorLivenessAtEpoch(validatorIndex, epoch, true));
}
use of tech.pegasys.teku.api.request.v1.validator.ValidatorLivenessRequest in project teku by ConsenSys.
the class TekuNode method getValidatorLivenessAtEpoch.
private Map<UInt64, Boolean> getValidatorLivenessAtEpoch(final UInt64 epoch, List<UInt64> validators) throws IOException {
final ValidatorLivenessRequest request = new ValidatorLivenessRequest(epoch, validators);
final String response = httpClient.post(getRestApiUrl(), "/eth/v1/validator/liveness", jsonProvider.objectToJSON(request));
final PostValidatorLivenessResponse livenessResponse = jsonProvider.jsonToObject(response, PostValidatorLivenessResponse.class);
final Map<UInt64, Boolean> output = new HashMap<>();
for (ValidatorLivenessAtEpoch entry : livenessResponse.data) {
output.put(entry.index, entry.isLive);
}
return output;
}
Aggregations