Search in sources :

Example 1 with ValidateableAttestation

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);
}
Also used : Attestation(tech.pegasys.teku.api.schema.Attestation) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation)

Example 2 with ValidateableAttestation

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;
}
Also used : IndexedAttestationSchema(tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation.IndexedAttestationSchema) AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation)

Example 3 with ValidateableAttestation

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);
}
Also used : ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) Test(org.junit.jupiter.api.Test)

Example 4 with ValidateableAttestation

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);
}
Also used : SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) Test(org.junit.jupiter.api.Test)

Example 5 with ValidateableAttestation

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));
}
Also used : ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation)

Aggregations

ValidateableAttestation (tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation)65 Test (org.junit.jupiter.api.Test)51 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)16 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)16 InternalValidationResult (tech.pegasys.teku.statetransition.validation.InternalValidationResult)16 StateAndBlockSummary (tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary)9 ValidationResult (io.libp2p.core.pubsub.ValidationResult)8 Spec (tech.pegasys.teku.spec.Spec)8 SignedAggregateAndProof (tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof)8 Bytes (org.apache.tuweni.bytes.Bytes)7 AttestationGenerator (tech.pegasys.teku.core.AttestationGenerator)7 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)7 AttestationData (tech.pegasys.teku.spec.datastructures.operations.AttestationData)7 Set (java.util.Set)6 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)6 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)6 HashSet (java.util.HashSet)5 Optional (java.util.Optional)5 Bytes32 (org.apache.tuweni.bytes.Bytes32)5 ArrayList (java.util.ArrayList)4