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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations