use of tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation in project teku by ConsenSys.
the class EventSubscriptionManager method onNewAttestation.
protected void onNewAttestation(final ValidateableAttestation attestation) {
final Attestation attestationEvent = new Attestation(attestation.getAttestation());
notifySubscribersOfEvent(EventType.attestation, attestationEvent);
}
use of tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation in project teku by ConsenSys.
the class ForkChoiceTest method applyAttestationFromValidator.
private UInt64 applyAttestationFromValidator(final UInt64 validatorIndex, final SignedBlockAndState targetBlock) {
// Note this attestation is wildly invalid but we're going to shove it straight into fork choice
// as pre-validated.
final UInt64 updatedAttestationSlot = UInt64.valueOf(20);
final ValidateableAttestation updatedVote = ValidateableAttestation.from(spec, attestationSchema.create(attestationSchema.getAggregationBitsSchema().ofBits(16), new AttestationData(updatedAttestationSlot, UInt64.ONE, targetBlock.getRoot(), recentChainData.getStore().getJustifiedCheckpoint(), new Checkpoint(spec.computeEpochAtSlot(updatedAttestationSlot), targetBlock.getRoot())), dataStructureUtil.randomSignature()));
final IndexedAttestationSchema indexedAttestationSchema = spec.atSlot(updatedAttestationSlot).getSchemaDefinitions().getIndexedAttestationSchema();
updatedVote.setIndexedAttestation(indexedAttestationSchema.create(indexedAttestationSchema.getAttestingIndicesSchema().of(validatorIndex), updatedVote.getData(), updatedVote.getAttestation().getAggregateSignature()));
forkChoice.applyIndexedAttestations(List.of(updatedVote));
return updatedAttestationSlot;
}
use of tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation in project teku by ConsenSys.
the class AttestationManagerTest method shouldProcessAttestationsThatAreReadyImmediately.
@Test
public void shouldProcessAttestationsThatAreReadyImmediately() {
final ValidateableAttestation attestation = ValidateableAttestation.from(spec, dataStructureUtil.randomAttestation());
when(forkChoice.onAttestation(any())).thenReturn(completedFuture(SUCCESSFUL));
attestationManager.onAttestation(attestation).reportExceptions();
verifyAttestationProcessed(attestation);
verify(attestationPool).add(attestation);
assertThat(futureAttestations.size()).isEqualTo(0);
assertThat(pendingAttestations.size()).isEqualTo(0);
}
use of tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation in project teku by ConsenSys.
the class AggregateAttestationValidatorTest method shouldRejectWhenAttestationValidatorSavesForFutureAndAggregateChecksFail.
@Test
public void shouldRejectWhenAttestationValidatorSavesForFutureAndAggregateChecksFail() {
final SignedAggregateAndProof aggregate = generator.generator().blockAndState(storageSystem.getChainHead()).aggregatorIndex(ONE).selectionProof(dataStructureUtil.randomSignature()).generate();
ValidateableAttestation attestation = ValidateableAttestation.aggregateFromValidator(spec, aggregate);
when(attestationValidator.singleOrAggregateAttestationChecks(any(), eq(attestation), eq(OptionalInt.empty()))).thenReturn(SafeFuture.completedFuture(InternalValidationResult.SAVE_FOR_FUTURE));
assertThat(validator.validate(attestation)).isCompletedWithValueMatching(InternalValidationResult::isReject);
}
use of tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation in project teku by ConsenSys.
the class AggregateAttestationValidatorTest method whenAttestationIsValid.
private void whenAttestationIsValid(final SignedAggregateAndProof aggregate) {
ValidateableAttestation attestation = ValidateableAttestation.aggregateFromValidator(spec, aggregate);
when(attestationValidator.singleOrAggregateAttestationChecks(any(), eq(attestation), eq(OptionalInt.empty()))).thenReturn(SafeFuture.completedFuture(InternalValidationResult.ACCEPT));
}
Aggregations