Search in sources :

Example 6 with SubmitDataError

use of tech.pegasys.teku.validator.api.SubmitDataError in project teku by ConsenSys.

the class SyncCommitteeProductionDutyTest method shouldReportPartialFailureWhenBeaconNodeRejectsSomeMessages.

@Test
void shouldReportPartialFailureWhenBeaconNodeRejectsSomeMessages() {
    final UInt64 slot = UInt64.valueOf(48);
    final int validatorIndex1 = 11;
    final int validatorIndex2 = 22;
    final Validator validator2 = createValidator();
    final BLSSignature signature1 = dataStructureUtil.randomSignature();
    final BLSSignature signature2 = dataStructureUtil.randomSignature();
    final SyncCommitteeProductionDuty duties = createDuty(committeeAssignment(validator, validatorIndex1, 1, 2, 3), committeeAssignment(validator2, validatorIndex2, 1, 5));
    when(validator.getSigner().signSyncCommitteeMessage(slot, blockRoot, forkInfo)).thenReturn(SafeFuture.completedFuture(signature1));
    when(validator2.getSigner().signSyncCommitteeMessage(slot, blockRoot, forkInfo)).thenReturn(SafeFuture.completedFuture(signature2));
    when(validatorApiChannel.sendSyncCommitteeMessages(any())).thenReturn(SafeFuture.completedFuture(List.of(new SubmitDataError(UInt64.ZERO, "API Rejected"))));
    produceMessagesAndReport(duties, slot);
    assertSentMessages(createMessage(slot, blockRoot, validatorIndex1, signature1), createMessage(slot, blockRoot, validatorIndex2, signature2));
    verify(validatorLogger).dutyCompleted(MESSAGE_TYPE, slot, 1, Set.of(blockRoot));
    verify(validatorLogger).dutyFailed(eq(MESSAGE_TYPE), eq(slot), eq(Set.of(validator.getPublicKey().toAbbreviatedString())), argThat(error -> error.getMessage().equals("API Rejected")));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) SchemaDefinitionsAltair(tech.pegasys.teku.spec.schemas.SchemaDefinitionsAltair) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) Signer(tech.pegasys.teku.core.signatures.Signer) ArgumentCaptor(org.mockito.ArgumentCaptor) ForkProvider(tech.pegasys.teku.validator.client.ForkProvider) Arrays.asList(java.util.Arrays.asList) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) Spec(tech.pegasys.teku.spec.Spec) Bytes32(org.apache.tuweni.bytes.Bytes32) DutyResult(tech.pegasys.teku.validator.client.duties.DutyResult) ValidatorLogger(tech.pegasys.teku.infrastructure.logging.ValidatorLogger) BLSSignature(tech.pegasys.teku.bls.BLSSignature) Collections.emptyList(java.util.Collections.emptyList) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) List(java.util.List) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) SyncCommitteeMessage(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage) IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Optional(java.util.Optional) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Mockito.mock(org.mockito.Mockito.mock) Validator(tech.pegasys.teku.validator.client.Validator) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Validator(tech.pegasys.teku.validator.client.Validator) BLSSignature(tech.pegasys.teku.bls.BLSSignature) Test(org.junit.jupiter.api.Test)

Example 7 with SubmitDataError

use of tech.pegasys.teku.validator.api.SubmitDataError in project teku by ConsenSys.

the class ValidatorDataProviderTest method submitAttestation_shouldSubmitAnInternalAttestationStructure.

@TestTemplate
void submitAttestation_shouldSubmitAnInternalAttestationStructure() {
    tech.pegasys.teku.spec.datastructures.operations.Attestation internalAttestation = dataStructureUtil.randomAttestation();
    Attestation attestation = new Attestation(internalAttestation);
    final List<SubmitDataError> errors = List.of(new SubmitDataError(ZERO, "Nope"));
    final SafeFuture<List<SubmitDataError>> result = SafeFuture.completedFuture(errors);
    when(validatorApiChannel.sendSignedAttestations(any())).thenReturn(result);
    assertThatSafeFuture(provider.submitAttestations(List.of(attestation))).isCompletedWithOptionalContaining(new PostDataFailureResponse(SC_BAD_REQUEST, ValidatorDataProvider.PARTIAL_PUBLISH_FAILURE_MESSAGE, List.of(new PostDataFailure(ZERO, "Nope"))));
    verify(validatorApiChannel).sendSignedAttestations(args.capture());
    assertThat(args.getValue()).hasSize(1);
    assertThatSszData(args.getValue().get(0)).isEqualByAllMeansTo(internalAttestation);
}
Also used : PostDataFailureResponse(tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse) PostDataFailure(tech.pegasys.teku.api.response.v1.beacon.PostDataFailure) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) IntList(it.unimi.dsi.fastutil.ints.IntList) Attestation(tech.pegasys.teku.api.schema.Attestation) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) TestTemplate(org.junit.jupiter.api.TestTemplate)

Example 8 with SubmitDataError

use of tech.pegasys.teku.validator.api.SubmitDataError in project teku by ConsenSys.

the class RemoteValidatorApiHandlerTest method sendSignedAttestation_InvokeApiWithCorrectRequest.

@Test
public void sendSignedAttestation_InvokeApiWithCorrectRequest() {
    final Attestation attestation = dataStructureUtil.randomAttestation();
    final PostDataFailureResponse failureResponse = new PostDataFailureResponse(SC_BAD_REQUEST, "Oh no", List.of(new PostDataFailure(UInt64.ZERO, "Bad")));
    when(apiClient.sendSignedAttestations(any())).thenReturn(Optional.of(failureResponse));
    final tech.pegasys.teku.api.schema.Attestation schemaAttestation = new tech.pegasys.teku.api.schema.Attestation(attestation);
    @SuppressWarnings("unchecked") ArgumentCaptor<List<tech.pegasys.teku.api.schema.Attestation>> argumentCaptor = ArgumentCaptor.forClass(List.class);
    final SafeFuture<List<SubmitDataError>> result = apiHandler.sendSignedAttestations(List.of(attestation));
    asyncRunner.executeQueuedActions();
    verify(apiClient).sendSignedAttestations(argumentCaptor.capture());
    assertThat(argumentCaptor.getValue()).usingRecursiveComparison().isEqualTo(List.of(schemaAttestation));
    assertThat(result).isCompletedWithValue(List.of(new SubmitDataError(UInt64.ZERO, "Bad")));
}
Also used : Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) PostDataFailureResponse(tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse) PostDataFailure(tech.pegasys.teku.api.response.v1.beacon.PostDataFailure) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) IntList(it.unimi.dsi.fastutil.ints.IntList) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Test(org.junit.jupiter.api.Test)

Example 9 with SubmitDataError

use of tech.pegasys.teku.validator.api.SubmitDataError in project teku by ConsenSys.

the class ValidatorApiHandlerTest method sendSignedAttestations_shouldNotAddToDutyMetricsAndPerformanceTrackerWhenInvalid.

@Test
void sendSignedAttestations_shouldNotAddToDutyMetricsAndPerformanceTrackerWhenInvalid() {
    final Attestation attestation = dataStructureUtil.randomAttestation();
    when(attestationManager.onAttestation(any(ValidateableAttestation.class))).thenReturn(completedFuture(AttestationProcessingResult.invalid("Bad juju")));
    final SafeFuture<List<SubmitDataError>> result = validatorApiHandler.sendSignedAttestations(List.of(attestation));
    assertThat(result).isCompletedWithValue(List.of(new SubmitDataError(ZERO, "Bad juju")));
    verify(dutyMetrics, never()).onAttestationPublished(attestation.getData().getSlot());
    verify(performanceTracker, never()).saveProducedAttestation(attestation);
}
Also used : Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) IntList(it.unimi.dsi.fastutil.ints.IntList) SszMutableList(tech.pegasys.teku.infrastructure.ssz.SszMutableList) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Test(org.junit.jupiter.api.Test)

Example 10 with SubmitDataError

use of tech.pegasys.teku.validator.api.SubmitDataError in project teku by ConsenSys.

the class PostSyncCommitteesIntegrationTest method shouldSubmitSyncCommitteesAndGetResponse.

@Test
void shouldSubmitSyncCommitteesAndGetResponse() throws IOException {
    spec = TestSpecFactory.createMinimalAltair();
    DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
    startRestAPIAtGenesis(SpecMilestone.ALTAIR);
    final List<SyncCommitteeMessage> requestBody = List.of(new SyncCommitteeMessage(UInt64.ONE, dataStructureUtil.randomBytes32(), dataStructureUtil.randomUInt64(), new BLSSignature(dataStructureUtil.randomSignature())));
    final SafeFuture<List<SubmitDataError>> future = SafeFuture.completedFuture(List.of(new SubmitDataError(UInt64.ZERO, errorString)));
    when(validatorApiChannel.sendSyncCommitteeMessages(requestBody.get(0).asInternalCommitteeSignature(spec).stream().collect(Collectors.toList()))).thenReturn(future);
    Response response = post(PostSyncCommittees.ROUTE, jsonProvider.objectToJSON(requestBody));
    assertThat(response.code()).isEqualTo(SC_BAD_REQUEST);
    final PostDataFailureResponse responseBody = jsonProvider.jsonToObject(response.body().string(), PostDataFailureResponse.class);
    assertThat(responseBody.failures.get(0).message).isEqualTo(errorString);
}
Also used : PostDataFailureResponse(tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse) Response(okhttp3.Response) PostDataFailureResponse(tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse) List(java.util.List) SyncCommitteeMessage(tech.pegasys.teku.api.schema.altair.SyncCommitteeMessage) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) BLSSignature(tech.pegasys.teku.api.schema.BLSSignature) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Aggregations

SubmitDataError (tech.pegasys.teku.validator.api.SubmitDataError)11 List (java.util.List)10 Test (org.junit.jupiter.api.Test)9 Collections.emptyList (java.util.Collections.emptyList)8 IntList (it.unimi.dsi.fastutil.ints.IntList)6 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)6 DataStructureUtil (tech.pegasys.teku.spec.util.DataStructureUtil)5 Optional (java.util.Optional)4 Bytes32 (org.apache.tuweni.bytes.Bytes32)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Mockito.mock (org.mockito.Mockito.mock)4 Mockito.when (org.mockito.Mockito.when)4 BLSSignature (tech.pegasys.teku.bls.BLSSignature)4 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)4 SszMutableList (tech.pegasys.teku.infrastructure.ssz.SszMutableList)4 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)4 TestSpecFactory (tech.pegasys.teku.spec.TestSpecFactory)4 SyncCommitteeMessage (tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage)4 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3