Search in sources :

Example 1 with ValidationResult

use of io.libp2p.core.pubsub.ValidationResult in project teku by ConsenSys.

the class Eth2TopicHandler method handleMessageProcessingError.

protected ValidationResult handleMessageProcessingError(final PreparedGossipMessage message, final Throwable err) {
    final ValidationResult response;
    if (ExceptionUtil.getCause(err, DecodingException.class).isPresent()) {
        P2P_LOG.onGossipMessageDecodingError(getTopic(), message.getOriginalMessage(), err);
        response = ValidationResult.Invalid;
    } else if (ExceptionUtil.getCause(err, RejectedExecutionException.class).isPresent()) {
        LOG.warn("Discarding gossip message for topic {} because the executor queue is full", getTopic());
        response = ValidationResult.Ignore;
    } else {
        LOG.warn("Encountered exception while processing message for topic {}", getTopic(), err);
        response = ValidationResult.Invalid;
    }
    return response;
}
Also used : DecodingException(tech.pegasys.teku.networking.eth2.gossip.encoding.DecodingException) ValidationResult(io.libp2p.core.pubsub.ValidationResult) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult)

Example 2 with ValidationResult

use of io.libp2p.core.pubsub.ValidationResult in project teku by ConsenSys.

the class AttesterSlashingTopicHandlerTest method handleMessage_validSlashing.

@Test
public void handleMessage_validSlashing() {
    final AttesterSlashing slashing = dataStructureUtil.randomAttesterSlashing();
    when(processor.process(slashing)).thenReturn(SafeFuture.completedFuture(InternalValidationResult.ACCEPT));
    Bytes serialized = gossipEncoding.encode(slashing);
    final SafeFuture<ValidationResult> result = topicHandler.handleMessage(topicHandler.prepareMessage(serialized));
    asyncRunner.executeQueuedActions();
    assertThat(result).isCompletedWithValue(ValidationResult.Valid);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) AttesterSlashing(tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing) ValidationResult(io.libp2p.core.pubsub.ValidationResult) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) Test(org.junit.jupiter.api.Test)

Example 3 with ValidationResult

use of io.libp2p.core.pubsub.ValidationResult in project teku by ConsenSys.

the class SingleAttestationTopicHandlerTest method handleMessage_invalid.

@Test
public void handleMessage_invalid() {
    final AttestationGenerator attestationGenerator = new AttestationGenerator(spec, validatorKeys);
    final StateAndBlockSummary blockAndState = getChainHead();
    final ValidateableAttestation attestation = ValidateableAttestation.fromNetwork(spec, attestationGenerator.validAttestation(blockAndState), SUBNET_ID);
    when(processor.process(attestation)).thenReturn(SafeFuture.completedFuture(InternalValidationResult.reject("Nope")));
    final Bytes serialized = gossipEncoding.encode(attestation.getAttestation());
    final SafeFuture<ValidationResult> result = topicHandler.handleMessage(topicHandler.prepareMessage(serialized));
    asyncRunner.executeQueuedActions();
    assertThat(result).isCompletedWithValue(ValidationResult.Invalid);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) StateAndBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary) AttestationGenerator(tech.pegasys.teku.core.AttestationGenerator) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) ValidationResult(io.libp2p.core.pubsub.ValidationResult) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) Test(org.junit.jupiter.api.Test)

Example 4 with ValidationResult

use of io.libp2p.core.pubsub.ValidationResult in project teku by ConsenSys.

the class SingleAttestationTopicHandlerTest method handleMessage_ignored.

@Test
public void handleMessage_ignored() {
    final AttestationGenerator attestationGenerator = new AttestationGenerator(spec, validatorKeys);
    final StateAndBlockSummary blockAndState = getChainHead();
    final ValidateableAttestation attestation = ValidateableAttestation.fromNetwork(spec, attestationGenerator.validAttestation(blockAndState), SUBNET_ID);
    when(processor.process(attestation)).thenReturn(SafeFuture.completedFuture(InternalValidationResult.IGNORE));
    final Bytes serialized = gossipEncoding.encode(attestation.getAttestation());
    final SafeFuture<ValidationResult> result = topicHandler.handleMessage(topicHandler.prepareMessage(serialized));
    asyncRunner.executeQueuedActions();
    assertThat(result).isCompletedWithValue(ValidationResult.Ignore);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) StateAndBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary) AttestationGenerator(tech.pegasys.teku.core.AttestationGenerator) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) ValidationResult(io.libp2p.core.pubsub.ValidationResult) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) Test(org.junit.jupiter.api.Test)

Example 5 with ValidationResult

use of io.libp2p.core.pubsub.ValidationResult in project teku by ConsenSys.

the class AggregateTopicHandlerTest method handleMessage_validAggregate.

@Test
public void handleMessage_validAggregate() {
    final ValidateableAttestation aggregate = ValidateableAttestation.aggregateFromValidator(spec, dataStructureUtil.randomSignedAggregateAndProof());
    when(processor.process(aggregate)).thenReturn(SafeFuture.completedFuture(InternalValidationResult.ACCEPT));
    final SafeFuture<ValidationResult> result = topicHandler.handleMessage(topicHandler.prepareMessage(gossipEncoding.encode(aggregate.getSignedAggregateAndProof())));
    asyncRunner.executeQueuedActions();
    assertThat(result).isCompletedWithValue(ValidationResult.Valid);
}
Also used : ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) ValidationResult(io.libp2p.core.pubsub.ValidationResult) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) Test(org.junit.jupiter.api.Test)

Aggregations

ValidationResult (io.libp2p.core.pubsub.ValidationResult)36 Test (org.junit.jupiter.api.Test)34 InternalValidationResult (tech.pegasys.teku.statetransition.validation.InternalValidationResult)29 Bytes (org.apache.tuweni.bytes.Bytes)28 ValidateableAttestation (tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation)8 MockMessageApi (tech.pegasys.teku.network.p2p.jvmlibp2p.MockMessageApi)6 AttestationGenerator (tech.pegasys.teku.core.AttestationGenerator)4 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)4 StateAndBlockSummary (tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary)4 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)3 CompletionException (java.util.concurrent.CompletionException)2 DecodingException (tech.pegasys.teku.networking.eth2.gossip.encoding.DecodingException)2 AttesterSlashing (tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing)2 ProposerSlashing (tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing)2 SignedVoluntaryExit (tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit)2 Preconditions (com.google.common.base.Preconditions)1 PubsubApi (io.libp2p.core.pubsub.PubsubApi)1 PubsubApiKt (io.libp2p.core.pubsub.PubsubApiKt)1 PubsubPublisherApi (io.libp2p.core.pubsub.PubsubPublisherApi)1 FastIdSeenCache (io.libp2p.pubsub.FastIdSeenCache)1