Search in sources :

Example 1 with SubmitDataError

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

the class ValidatorApiHandlerTest method sendSignedAttestations_shouldProcessMixOfValidAndInvalidAttestations.

@Test
void sendSignedAttestations_shouldProcessMixOfValidAndInvalidAttestations() {
    final Attestation invalidAttestation = dataStructureUtil.randomAttestation();
    final Attestation validAttestation = dataStructureUtil.randomAttestation();
    when(attestationManager.onAttestation(validatableAttestationOf(invalidAttestation))).thenReturn(completedFuture(AttestationProcessingResult.invalid("Bad juju")));
    when(attestationManager.onAttestation(validatableAttestationOf(validAttestation))).thenReturn(completedFuture(SUCCESSFUL));
    final SafeFuture<List<SubmitDataError>> result = validatorApiHandler.sendSignedAttestations(List.of(invalidAttestation, validAttestation));
    assertThat(result).isCompletedWithValue(List.of(new SubmitDataError(ZERO, "Bad juju")));
    verify(dutyMetrics, never()).onAttestationPublished(invalidAttestation.getData().getSlot());
    verify(dutyMetrics).onAttestationPublished(validAttestation.getData().getSlot());
    verify(performanceTracker, never()).saveProducedAttestation(invalidAttestation);
    verify(performanceTracker).saveProducedAttestation(validAttestation);
}
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) 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 2 with SubmitDataError

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

the class ValidatorApiHandlerTest method sendSyncCommitteeMessages_shouldRaiseErrors.

@Test
void sendSyncCommitteeMessages_shouldRaiseErrors() {
    final SyncCommitteeMessage message = dataStructureUtil.randomSyncCommitteeMessage();
    final List<SyncCommitteeMessage> messages = List.of(message);
    when(syncCommitteeMessagePool.add(any())).thenReturn(SafeFuture.completedFuture(InternalValidationResult.create(ValidationResultCode.REJECT, "Rejected")));
    final SafeFuture<List<SubmitDataError>> result = validatorApiHandler.sendSyncCommitteeMessages(messages);
    assertThat(result).isCompletedWithValue(List.of(new SubmitDataError(UInt64.ZERO, "Rejected")));
    verify(performanceTracker, never()).saveProducedSyncCommitteeMessage(message);
}
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) SyncCommitteeMessage(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Test(org.junit.jupiter.api.Test)

Example 3 with SubmitDataError

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

the class ValidatorApiHandlerTest method sendAggregateAndProofs_shouldProcessMixOfValidAndInvalidAggregates.

@Test
void sendAggregateAndProofs_shouldProcessMixOfValidAndInvalidAggregates() {
    final SignedAggregateAndProof invalidAggregate = dataStructureUtil.randomSignedAggregateAndProof();
    final SignedAggregateAndProof validAggregate = dataStructureUtil.randomSignedAggregateAndProof();
    when(attestationManager.onAttestation(ValidateableAttestation.aggregateFromValidator(spec, invalidAggregate))).thenReturn(completedFuture(AttestationProcessingResult.invalid("Bad juju")));
    when(attestationManager.onAttestation(ValidateableAttestation.aggregateFromValidator(spec, validAggregate))).thenReturn(completedFuture(SUCCESSFUL));
    final SafeFuture<List<SubmitDataError>> result = validatorApiHandler.sendAggregateAndProofs(List.of(invalidAggregate, validAggregate));
    assertThat(result).isCompletedWithValue(List.of(new SubmitDataError(ZERO, "Bad juju")));
    // Should send both to the attestation manager.
    verify(attestationManager).onAttestation(argThat(validatableAttestation -> validatableAttestation.getSignedAggregateAndProof().equals(validAggregate)));
    verify(attestationManager).onAttestation(argThat(validatableAttestation -> validatableAttestation.getSignedAggregateAndProof().equals(invalidAggregate)));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CombinedChainDataClient(tech.pegasys.teku.storage.client.CombinedChainDataClient) SyncCommitteeSubscriptionManager(tech.pegasys.teku.networking.eth2.gossip.subnets.SyncCommitteeSubscriptionManager) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) AggregatingAttestationPool(tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool) SUCCESSFUL(tech.pegasys.teku.spec.datastructures.util.AttestationProcessingResult.SUCCESSFUL) ONE(tech.pegasys.teku.infrastructure.unsigned.UInt64.ONE) SafeFutureAssert.assertThatSafeFuture(tech.pegasys.teku.infrastructure.async.SafeFutureAssert.assertThatSafeFuture) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) BlockImportChannel(tech.pegasys.teku.statetransition.block.BlockImportChannel) AttesterDuties(tech.pegasys.teku.validator.api.AttesterDuties) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Map(java.util.Map) SyncCommitteeUtil(tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil) Bytes32(org.apache.tuweni.bytes.Bytes32) ChainDataProvider(tech.pegasys.teku.api.ChainDataProvider) SendSignedBlockResult(tech.pegasys.teku.validator.api.SendSignedBlockResult) DefaultPerformanceTracker(tech.pegasys.teku.validator.coordinator.performance.DefaultPerformanceTracker) BLSSignature(tech.pegasys.teku.bls.BLSSignature) DOES_NOT_DESCEND_FROM_LATEST_FINALIZED(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult.FailureReason.DOES_NOT_DESCEND_FROM_LATEST_FINALIZED) Collections.emptyList(java.util.Collections.emptyList) ValidationResultCode(tech.pegasys.teku.statetransition.validation.ValidationResultCode) Test(org.junit.jupiter.api.Test) List(java.util.List) SyncCommitteeContributionPool(tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool) SyncCommitteeDuties(tech.pegasys.teku.validator.api.SyncCommitteeDuties) Mockito.inOrder(org.mockito.Mockito.inOrder) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) ForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier) Optional(java.util.Optional) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BlockGossipChannel(tech.pegasys.teku.networking.eth2.gossip.BlockGossipChannel) AttestationProcessingResult(tech.pegasys.teku.spec.datastructures.util.AttestationProcessingResult) SyncCommitteeSubnetSubscription(tech.pegasys.teku.validator.api.SyncCommitteeSubnetSubscription) NodeSyncingException(tech.pegasys.teku.validator.api.NodeSyncingException) ForkChoiceTrigger(tech.pegasys.teku.statetransition.forkchoice.ForkChoiceTrigger) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) AttestationTopicSubscriber(tech.pegasys.teku.networking.eth2.gossip.subnets.AttestationTopicSubscriber) SafeFuture.completedFuture(tech.pegasys.teku.infrastructure.async.SafeFuture.completedFuture) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) SyncCommitteeMessagePool(tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessagePool) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) ZERO(tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) Validator(tech.pegasys.teku.spec.datastructures.state.Validator) CommitteeSubscriptionRequest(tech.pegasys.teku.validator.api.CommitteeSubscriptionRequest) InOrder(org.mockito.InOrder) StubForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.StubForkChoiceNotifier) AttestationManager(tech.pegasys.teku.statetransition.attestation.AttestationManager) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) Mockito.when(org.mockito.Mockito.when) SignedContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof) ProposerDuty(tech.pegasys.teku.validator.api.ProposerDuty) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) IntList(it.unimi.dsi.fastutil.ints.IntList) SyncState(tech.pegasys.teku.beacon.sync.events.SyncState) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) SyncCommitteeMessage(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage) AttesterDuty(tech.pegasys.teku.validator.api.AttesterDuty) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) SyncStateProvider(tech.pegasys.teku.beacon.sync.events.SyncStateProvider) IntSet(it.unimi.dsi.fastutil.ints.IntSet) CheckpointState(tech.pegasys.teku.spec.datastructures.state.CheckpointState) Comparator(java.util.Comparator) SszMutableList(tech.pegasys.teku.infrastructure.ssz.SszMutableList) SpecConfigAltair(tech.pegasys.teku.spec.config.SpecConfigAltair) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) ProposerDuties(tech.pegasys.teku.validator.api.ProposerDuties) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) IntList(it.unimi.dsi.fastutil.ints.IntList) SszMutableList(tech.pegasys.teku.infrastructure.ssz.SszMutableList) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Test(org.junit.jupiter.api.Test)

Example 4 with SubmitDataError

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

the class MetricRecordingValidatorApiChannelTest method getSendDataArguments.

public static Stream<Arguments> getSendDataArguments() {
    final DataStructureUtil dataStructureUtil = new DataStructureUtil(TestSpecFactory.createMinimalAltair());
    final List<SubmitDataError> submissionErrors = List.of(new SubmitDataError(UInt64.ZERO, "Nope"));
    final List<Attestation> attestations = List.of(dataStructureUtil.randomAttestation());
    final List<SyncCommitteeMessage> syncCommitteeMessages = List.of(dataStructureUtil.randomSyncCommitteeMessage());
    final List<SignedAggregateAndProof> aggregateAndProofs = List.of(dataStructureUtil.randomSignedAggregateAndProof());
    return Stream.of(sendDataTest("sendSignedAttestations", channel -> channel.sendSignedAttestations(attestations), MetricRecordingValidatorApiChannel.PUBLISHED_ATTESTATION_COUNTER_NAME, submissionErrors), sendDataTest("sendSyncCommitteeMessages", channel -> channel.sendSyncCommitteeMessages(syncCommitteeMessages), MetricRecordingValidatorApiChannel.SYNC_COMMITTEE_SEND_MESSAGES_NAME, submissionErrors), sendDataTest("sendAggregateAndProofs", channel -> channel.sendAggregateAndProofs(aggregateAndProofs), MetricRecordingValidatorApiChannel.PUBLISHED_AGGREGATE_COUNTER_NAME, submissionErrors));
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StubMetricsSystem(tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) Function(java.util.function.Function) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) Assertions(org.assertj.core.api.Assertions) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) RequestOutcome(tech.pegasys.teku.validator.beaconnode.metrics.BeaconChainRequestCounter.RequestOutcome) Bytes32(org.apache.tuweni.bytes.Bytes32) GenesisData(tech.pegasys.teku.spec.datastructures.genesis.GenesisData) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) MethodSource(org.junit.jupiter.params.provider.MethodSource) Collections.emptySet(java.util.Collections.emptySet) BLSSignature(tech.pegasys.teku.bls.BLSSignature) Collections.emptyList(java.util.Collections.emptyList) Mockito.when(org.mockito.Mockito.when) Arguments(org.junit.jupiter.params.provider.Arguments) Consumer(java.util.function.Consumer) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) TekuMetricCategory(tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) SyncCommitteeMessage(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Optional(java.util.Optional) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Mockito.mock(org.mockito.Mockito.mock) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) SyncCommitteeMessage(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil)

Example 5 with SubmitDataError

use of tech.pegasys.teku.validator.api.SubmitDataError 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);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) AttestationSchema(tech.pegasys.teku.spec.datastructures.operations.Attestation.AttestationSchema) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SszBitlist(tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) SafeFuture.completedFuture(tech.pegasys.teku.infrastructure.async.SafeFuture.completedFuture) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) Signer(tech.pegasys.teku.core.signatures.Signer) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) ForkProvider(tech.pegasys.teku.validator.client.ForkProvider) BatchAttestationSendingStrategy(tech.pegasys.teku.validator.client.duties.attestations.BatchAttestationSendingStrategy) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) SafeFuture.failedFuture(tech.pegasys.teku.infrastructure.async.SafeFuture.failedFuture) Spec(tech.pegasys.teku.spec.Spec) FileBackedGraffitiProvider(tech.pegasys.teku.validator.api.FileBackedGraffitiProvider) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) ValidatorLogger(tech.pegasys.teku.infrastructure.logging.ValidatorLogger) BLSSignature(tech.pegasys.teku.bls.BLSSignature) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) AttestationProductionDuty(tech.pegasys.teku.validator.client.duties.attestations.AttestationProductionDuty) List(java.util.List) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Optional(java.util.Optional) Collections(java.util.Collections) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Mockito.mock(org.mockito.Mockito.mock) Validator(tech.pegasys.teku.validator.client.Validator) AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) Optional(java.util.Optional) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Validator(tech.pegasys.teku.validator.client.Validator) Test(org.junit.jupiter.api.Test)

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