Search in sources :

Example 1 with SignedContributionAndProof

use of tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof in project teku by ConsenSys.

the class BlockOperationSelectorFactoryTest method shouldIncludeValidOperations.

@Test
void shouldIncludeValidOperations() {
    final UInt64 slot = UInt64.valueOf(2);
    final BeaconState blockSlotState = dataStructureUtil.randomBeaconState(slot);
    final SignedVoluntaryExit voluntaryExit = dataStructureUtil.randomSignedVoluntaryExit();
    final ProposerSlashing proposerSlashing = dataStructureUtil.randomProposerSlashing();
    final AttesterSlashing attesterSlashing = dataStructureUtil.randomAttesterSlashing();
    final SignedContributionAndProof contribution = dataStructureUtil.randomSignedContributionAndProof(1, parentRoot);
    addToPool(voluntaryExitPool, voluntaryExit);
    addToPool(proposerSlashingPool, proposerSlashing);
    addToPool(attesterSlashingPool, attesterSlashing);
    assertThat(contributionPool.add(contribution)).isCompletedWithValue(ACCEPT);
    factory.createSelector(parentRoot, blockSlotState, randaoReveal, Optional.empty()).accept(bodyBuilder);
    assertThat(bodyBuilder.randaoReveal).isEqualTo(randaoReveal);
    assertThat(bodyBuilder.graffiti).isEqualTo(defaultGraffiti);
    assertThat(bodyBuilder.proposerSlashings).containsOnly(proposerSlashing);
    assertThat(bodyBuilder.attesterSlashings).containsOnly(attesterSlashing);
    assertThat(bodyBuilder.voluntaryExits).containsOnly(voluntaryExit);
    assertThat(bodyBuilder.syncAggregate).isEqualTo(spec.getSyncCommitteeUtilRequired(slot).createSyncAggregate(List.of(contribution.getMessage().getContribution())));
}
Also used : SignedVoluntaryExit(tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit) AttesterSlashing(tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing) ProposerSlashing(tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing) SignedContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 2 with SignedContributionAndProof

use of tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof in project teku by ConsenSys.

the class SyncCommitteeContributionPoolTest method shouldSelectBestContribution.

@Test
void shouldSelectBestContribution() {
    final SignedContributionAndProof proof = dataStructureUtil.randomSignedContributionAndProof(25);
    final SignedContributionAndProof bestProof = withParticipationBits(proof, 1, 2, 3);
    addValid(withParticipationBits(proof, 1, 3));
    addValid(bestProof);
    addValid(withParticipationBits(proof, 2));
    final SyncCommitteeContribution contribution = bestProof.getMessage().getContribution();
    final SyncAggregate result = pool.createSyncAggregateForBlock(contribution.getSlot().plus(1), contribution.getBeaconBlockRoot());
    assertSyncAggregateFromContribution(contribution, result);
}
Also used : SyncAggregateAssert.assertThatSyncAggregate(tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregateAssert.assertThatSyncAggregate) SyncAggregate(tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate) SignedContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof) SyncCommitteeContribution(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContribution) Test(org.junit.jupiter.api.Test)

Example 3 with SignedContributionAndProof

use of tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof in project teku by ConsenSys.

the class SignedContributionAndProofValidatorTest method shouldHandleBeaconBlockRootBeingFromBeforeCurrentSyncCommitteePeriod.

@Test
void shouldHandleBeaconBlockRootBeingFromBeforeCurrentSyncCommitteePeriod() {
    final Bytes32 blockRoot = chainBuilder.getLatestBlockAndState().getRoot();
    final UInt64 slot = UInt64.valueOf(config.getEpochsPerSyncCommitteePeriod() * config.getSlotsPerEpoch() + 1);
    final UInt64 slotSeconds = slot.times(spec.getSecondsPerSlot(slot));
    timeProvider.advanceTimeBy(Duration.ofSeconds(slotSeconds.longValue()));
    storageSystem.chainUpdater().advanceChain(slot);
    final SignedContributionAndProof message = chainBuilder.createValidSignedContributionAndProofBuilder().beaconBlockRoot(blockRoot).resetParticipantsToOnlyAggregator().build();
    assertThat(validator.validate(message)).isCompletedWithValue(ACCEPT);
}
Also used : SignedContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) Test(org.junit.jupiter.api.Test)

Example 4 with SignedContributionAndProof

use of tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof in project teku by ConsenSys.

the class SignedContributionAndProofValidatorTest method shouldRejectAggregateSignatureIsInvalid.

@Test
void shouldRejectAggregateSignatureIsInvalid() {
    final SignedContributionAndProof message = chainBuilder.createValidSignedContributionAndProofBuilder().addParticipantSignature(dataStructureUtil.randomSignature()).build();
    assertThat(validator.validate(message)).isCompletedWithValueMatching(InternalValidationResult::isReject);
}
Also used : SignedContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) Test(org.junit.jupiter.api.Test)

Example 5 with SignedContributionAndProof

use of tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof in project teku by ConsenSys.

the class SignedContributionAndProofValidatorTest method shouldIgnoreWhenContributionIsNotFromTheCurrentSlot.

@Test
void shouldIgnoreWhenContributionIsNotFromTheCurrentSlot() {
    final SignedContributionAndProof message = chainBuilder.createValidSignedContributionAndProofBuilder().build();
    final UInt64 slot = message.getMessage().getContribution().getSlot().plus(1);
    // disparity is 500 millis, so 1 second into next slot will be time
    final UInt64 slotSeconds = slot.times(spec.getSecondsPerSlot(slot)).plus(1);
    timeProvider.advanceTimeBy(Duration.ofSeconds(slotSeconds.longValue()));
    storageSystem.chainUpdater().setCurrentSlot(message.getMessage().getContribution().getSlot().plus(1));
    final SafeFuture<InternalValidationResult> result = validator.validate(message);
    assertThat(result).isCompletedWithValue(IGNORE);
}
Also used : SignedContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Aggregations

SignedContributionAndProof (tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof)28 Test (org.junit.jupiter.api.Test)25 InternalValidationResult (tech.pegasys.teku.statetransition.validation.InternalValidationResult)13 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)6 SyncCommitteeContribution (tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContribution)5 SyncAggregate (tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate)3 SyncAggregateAssert.assertThatSyncAggregate (tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregateAssert.assertThatSyncAggregate)3 ContributionAndProof (tech.pegasys.teku.spec.datastructures.operations.versions.altair.ContributionAndProof)3 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)3 SyncCommitteeUtil (tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil)3 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)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 FormatMethod (com.google.errorprone.annotations.FormatMethod)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1