diff --git a/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/v1/validator/PostRegisterValidatorTest.java b/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/v1/validator/PostRegisterValidatorTest.java index 280a29dc00a..ded367018a3 100644 --- a/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/v1/validator/PostRegisterValidatorTest.java +++ b/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/v1/validator/PostRegisterValidatorTest.java @@ -71,7 +71,7 @@ void shouldReturnOk() throws IOException { dataStructureUtil.randomSignedValidatorRegistrations(10); when(validatorApiChannel.registerValidators(request)).thenReturn(SafeFuture.COMPLETE); - try (Response response = + try (final Response response = post( PostRegisterValidator.ROUTE, JsonUtil.serialize( @@ -88,7 +88,7 @@ void shouldReturnServerErrorWhenThereIsAnExceptionWhileRegistering() throws IOEx when(validatorApiChannel.registerValidators(request)) .thenReturn(SafeFuture.failedFuture(new IllegalStateException("oopsy"))); - try (Response response = + try (final Response response = post( PostRegisterValidator.ROUTE, JsonUtil.serialize( @@ -106,7 +106,7 @@ void shouldReturnServerErrorWhenThereIsAnExceptionWhileGettingStatuses() throws when(validatorApiChannel.getValidatorStatuses(anyCollection())) .thenReturn(SafeFuture.failedFuture(new IllegalStateException("oopsy"))); - try (Response response = + try (final Response response = post( PostRegisterValidator.ROUTE, JsonUtil.serialize( @@ -121,7 +121,7 @@ void shouldReturnServerErrorWhenThereIsAnExceptionWhileGettingStatuses() throws @ValueSource(strings = {"[{}]", "{}", "invalid"}) void shouldReturnBadRequest(final String body) throws IOException { when(validatorApiChannel.registerValidators(any())).thenReturn(SafeFuture.COMPLETE); - try (Response response = post(PostRegisterValidator.ROUTE, body)) { + try (final Response response = post(PostRegisterValidator.ROUTE, body)) { assertThat(response.code()).isEqualTo(SC_BAD_REQUEST); } verifyNoInteractions(validatorApiChannel); @@ -130,7 +130,7 @@ void shouldReturnBadRequest(final String body) throws IOException { @Test void shouldHandleEmptyRequest() throws IOException { when(validatorApiChannel.registerValidators(any())).thenReturn(SafeFuture.COMPLETE); - try (Response response = post(PostRegisterValidator.ROUTE, "[]")) { + try (final Response response = post(PostRegisterValidator.ROUTE, "[]")) { assertThat(response.code()).isEqualTo(SC_OK); } } diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/PostRegisterValidator.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/PostRegisterValidator.java index 70352c7aa95..42940ef13c9 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/PostRegisterValidator.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/PostRegisterValidator.java @@ -23,6 +23,7 @@ import java.util.Optional; import tech.pegasys.teku.api.DataProvider; import tech.pegasys.teku.api.ValidatorDataProvider; +import tech.pegasys.teku.infrastructure.exceptions.ExceptionUtil; import tech.pegasys.teku.infrastructure.restapi.endpoints.AsyncApiResponse; import tech.pegasys.teku.infrastructure.restapi.endpoints.EndpointMetadata; import tech.pegasys.teku.infrastructure.restapi.endpoints.RestApiEndpoint; @@ -69,11 +70,8 @@ public void handleRequest(final RestApiRequest request) throws JsonProcessingExc .handle( (__, error) -> { if (error != null) { - final String message = - error.getCause() == null - ? error.getMessage() - : error.getCause().getMessage(); - return AsyncApiResponse.respondWithError(SC_INTERNAL_SERVER_ERROR, message); + return AsyncApiResponse.respondWithError( + SC_INTERNAL_SERVER_ERROR, ExceptionUtil.getRootCauseMessage(error)); } return AsyncApiResponse.respondOk(null); })); diff --git a/data/provider/src/main/java/tech/pegasys/teku/api/ValidatorDataProvider.java b/data/provider/src/main/java/tech/pegasys/teku/api/ValidatorDataProvider.java index 7317e14abe0..61af75420af 100644 --- a/data/provider/src/main/java/tech/pegasys/teku/api/ValidatorDataProvider.java +++ b/data/provider/src/main/java/tech/pegasys/teku/api/ValidatorDataProvider.java @@ -256,7 +256,7 @@ public SafeFuture> createAggregate( } public SafeFuture> sendAggregateAndProofs( - List aggregateAndProofs) { + final List aggregateAndProofs) { return validatorApiChannel.sendAggregateAndProofs(aggregateAndProofs); } @@ -295,12 +295,12 @@ public SafeFuture sendContributionAndProofs( } public SafeFuture prepareBeaconProposer( - List beaconPreparableProposers) { + final List beaconPreparableProposers) { return validatorApiChannel.prepareBeaconProposer(beaconPreparableProposers); } public SafeFuture registerValidators( - SszList validatorRegistrations) { + final SszList validatorRegistrations) { return validatorApiChannel .getValidatorStatuses( validatorRegistrations.stream() diff --git a/validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorClientService.java b/validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorClientService.java index 7943c0443f4..2bce5040376 100644 --- a/validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorClientService.java +++ b/validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorClientService.java @@ -198,7 +198,7 @@ public static ValidatorClientService create( proposerConfigManager = Optional.empty(); } - ValidatorClientService validatorClientService = + final ValidatorClientService validatorClientService = new ValidatorClientService( eventChannels, validatorLoader, @@ -273,12 +273,12 @@ public static ValidatorClientService create( } private void initializeDoppelgangerDetector( - AsyncRunner asyncRunner, - ValidatorApiChannel validatorApiChannel, - Spec spec, - TimeProvider timeProvider, - GenesisDataProvider genesisDataProvider) { - DoppelgangerDetector doppelgangerDetector = + final AsyncRunner asyncRunner, + final ValidatorApiChannel validatorApiChannel, + final Spec spec, + final TimeProvider timeProvider, + final GenesisDataProvider genesisDataProvider) { + final DoppelgangerDetector doppelgangerDetector = new DoppelgangerDetector( asyncRunner, validatorApiChannel, diff --git a/validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorStatusLogger.java b/validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorStatusLogger.java index 19675f9ada8..420c851d107 100644 --- a/validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorStatusLogger.java +++ b/validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorStatusLogger.java @@ -31,14 +31,14 @@ public class ValidatorStatusLogger implements ValidatorStatusesChannel { final AtomicReference> latestValidatorStatuses = new AtomicReference<>(); - public ValidatorStatusLogger(OwnedValidators validators) { + public ValidatorStatusLogger(final OwnedValidators validators) { this.validators = validators; } @Override public void onNewValidatorStatuses( final Map newValidatorStatuses) { - Map oldValidatorStatuses = + final Map oldValidatorStatuses = latestValidatorStatuses.getAndSet(newValidatorStatuses); // first run if (oldValidatorStatuses == null) { @@ -51,10 +51,10 @@ public void onNewValidatorStatuses( } // updates - for (Map.Entry entry : newValidatorStatuses.entrySet()) { - BLSPublicKey key = entry.getKey(); - ValidatorStatus newStatus = entry.getValue(); - ValidatorStatus oldStatus = oldValidatorStatuses.get(key); + for (final Map.Entry entry : newValidatorStatuses.entrySet()) { + final BLSPublicKey key = entry.getKey(); + final ValidatorStatus newStatus = entry.getValue(); + final ValidatorStatus oldStatus = oldValidatorStatuses.get(key); // report the status of a new validator if (oldStatus == null) { @@ -70,9 +70,9 @@ public void onNewValidatorStatuses( } private void printValidatorStatusesOneByOne( - Map validatorStatuses) { - for (BLSPublicKey publicKey : validators.getPublicKeys()) { - Optional maybeValidatorStatus = + final Map validatorStatuses) { + for (final BLSPublicKey publicKey : validators.getPublicKeys()) { + final Optional maybeValidatorStatus = Optional.ofNullable(validatorStatuses.get(publicKey)); maybeValidatorStatus.ifPresentOrElse( validatorStatus -> @@ -81,22 +81,24 @@ private void printValidatorStatusesOneByOne( } } - private void printValidatorStatusSummary(Map validatorStatuses) { - Map validatorStatusCount = new HashMap<>(); + private void printValidatorStatusSummary( + final Map validatorStatuses) { + final Map validatorStatusCount = new HashMap<>(); final AtomicInteger unknownValidatorCountReference = new AtomicInteger(0); - for (BLSPublicKey publicKey : validators.getPublicKeys()) { - Optional maybeValidatorStatus = + for (final BLSPublicKey publicKey : validators.getPublicKeys()) { + final Optional maybeValidatorStatus = Optional.ofNullable(validatorStatuses.get(publicKey)); maybeValidatorStatus.ifPresentOrElse( status -> { - AtomicInteger count = + final AtomicInteger count = validatorStatusCount.computeIfAbsent(status, __ -> new AtomicInteger(0)); count.incrementAndGet(); }, unknownValidatorCountReference::incrementAndGet); } - for (Map.Entry statusCount : validatorStatusCount.entrySet()) { + for (final Map.Entry statusCount : + validatorStatusCount.entrySet()) { STATUS_LOG.validatorStatusSummary(statusCount.getValue().get(), statusCount.getKey().name()); } diff --git a/validator/client/src/test/java/tech/pegasys/teku/validator/client/ValidatorRegistrationSigningServiceTest.java b/validator/client/src/test/java/tech/pegasys/teku/validator/client/ValidatorRegistrationSigningServiceTest.java index 9c7be05a9a4..25ab59e554f 100644 --- a/validator/client/src/test/java/tech/pegasys/teku/validator/client/ValidatorRegistrationSigningServiceTest.java +++ b/validator/client/src/test/java/tech/pegasys/teku/validator/client/ValidatorRegistrationSigningServiceTest.java @@ -56,7 +56,7 @@ class ValidatorRegistrationSigningServiceTest { private DataStructureUtil dataStructureUtil; @BeforeEach - void setUp(SpecContext specContext) { + void setUp(final SpecContext specContext) { dataStructureUtil = specContext.getDataStructureUtil(); feeRecipient = dataStructureUtil.randomEth1Address(); gasLimit = dataStructureUtil.randomUInt64(); diff --git a/validator/client/src/test/java/tech/pegasys/teku/validator/client/ValidatorRegistratorTest.java b/validator/client/src/test/java/tech/pegasys/teku/validator/client/ValidatorRegistratorTest.java index f5bb25db9df..d9212c9ebf2 100644 --- a/validator/client/src/test/java/tech/pegasys/teku/validator/client/ValidatorRegistratorTest.java +++ b/validator/client/src/test/java/tech/pegasys/teku/validator/client/ValidatorRegistratorTest.java @@ -83,7 +83,7 @@ class ValidatorRegistratorTest { @BeforeEach @SuppressWarnings("unchecked") - void setUp(SpecContext specContext) { + void setUp(final SpecContext specContext) { this.specContext = specContext; slotsPerEpoch = specContext.getSpec().getGenesisSpecConfig().getSlotsPerEpoch(); dataStructureUtil = specContext.getDataStructureUtil();