Search in sources :

Example 1 with ValidateableSyncCommitteeMessage

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

the class SyncCommitteeMessagePoolTest method shouldCreateContributionFromSingleMatchingMessage.

@Test
void shouldCreateContributionFromSingleMatchingMessage() {
    final ValidateableSyncCommitteeMessage message = ValidateableSyncCommitteeMessage.fromValidator(dataStructureUtil.randomSyncCommitteeMessage());
    final int subcommitteeIndex = 3;
    message.setSubcommitteeAssignments(SyncSubcommitteeAssignments.builder().addAssignment(1, 1).addAssignment(subcommitteeIndex, 3).build());
    addValid(message);
    final Optional<SyncCommitteeContribution> contribution = pool.createContribution(message.getSlot(), message.getBeaconBlockRoot(), subcommitteeIndex);
    assertThat(contribution).contains(createContributionFrom(subcommitteeIndex, message));
}
Also used : ValidateableSyncCommitteeMessage(tech.pegasys.teku.spec.datastructures.operations.versions.altair.ValidateableSyncCommitteeMessage) SyncCommitteeContribution(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContribution) Test(org.junit.jupiter.api.Test)

Example 2 with ValidateableSyncCommitteeMessage

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

the class SyncCommitteeMessagePoolTest method shouldExcludeMessagesWhereSlotDoesNotMatch.

@Test
void shouldExcludeMessagesWhereSlotDoesNotMatch() {
    final ValidateableSyncCommitteeMessage message = ValidateableSyncCommitteeMessage.fromValidator(dataStructureUtil.randomSyncCommitteeMessage());
    final int subcommitteeIndex = 3;
    message.setSubcommitteeAssignments(SyncSubcommitteeAssignments.builder().addAssignment(subcommitteeIndex, 3).build());
    addValid(message);
    final Optional<SyncCommitteeContribution> contribution = pool.createContribution(UInt64.ZERO, message.getBeaconBlockRoot(), subcommitteeIndex);
    assertThat(contribution).isEmpty();
}
Also used : ValidateableSyncCommitteeMessage(tech.pegasys.teku.spec.datastructures.operations.versions.altair.ValidateableSyncCommitteeMessage) SyncCommitteeContribution(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContribution) Test(org.junit.jupiter.api.Test)

Example 3 with ValidateableSyncCommitteeMessage

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

the class SyncCommitteeMessagePoolTest method shouldIncludeMessageInContributionForAllApplicableSubnets.

@Test
void shouldIncludeMessageInContributionForAllApplicableSubnets() {
    final ValidateableSyncCommitteeMessage message = ValidateableSyncCommitteeMessage.fromValidator(dataStructureUtil.randomSyncCommitteeMessage());
    message.setSubcommitteeAssignments(SyncSubcommitteeAssignments.builder().addAssignment(1, 1).addAssignment(3, 3).addAssignment(5, 3).build());
    addValid(message);
    final UInt64 slot = message.getSlot();
    final Bytes32 blockRoot = message.getBeaconBlockRoot();
    // One message but gets included for all three subnets.
    assertThat(pool.createContribution(slot, blockRoot, 1)).contains(createContributionFrom(1, message));
    assertThat(pool.createContribution(slot, blockRoot, 3)).contains(createContributionFrom(3, message));
    assertThat(pool.createContribution(slot, blockRoot, 5)).contains(createContributionFrom(5, message));
}
Also used : ValidateableSyncCommitteeMessage(tech.pegasys.teku.spec.datastructures.operations.versions.altair.ValidateableSyncCommitteeMessage) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) Test(org.junit.jupiter.api.Test)

Example 4 with ValidateableSyncCommitteeMessage

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

the class SyncCommitteeMessagePoolTest method shouldExcludeMessagesWhereBlockRootDoesNotMatch.

@Test
void shouldExcludeMessagesWhereBlockRootDoesNotMatch() {
    final ValidateableSyncCommitteeMessage message = ValidateableSyncCommitteeMessage.fromValidator(dataStructureUtil.randomSyncCommitteeMessage());
    final int subcommitteeIndex = 3;
    message.setSubcommitteeAssignments(SyncSubcommitteeAssignments.builder().addAssignment(subcommitteeIndex, 3).build());
    addValid(message);
    final Bytes32 blockRoot = dataStructureUtil.randomBytes32();
    final Optional<SyncCommitteeContribution> contribution = pool.createContribution(message.getSlot(), blockRoot, subcommitteeIndex);
    assertThat(contribution).isEmpty();
}
Also used : ValidateableSyncCommitteeMessage(tech.pegasys.teku.spec.datastructures.operations.versions.altair.ValidateableSyncCommitteeMessage) SyncCommitteeContribution(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContribution) Bytes32(org.apache.tuweni.bytes.Bytes32) Test(org.junit.jupiter.api.Test)

Example 5 with ValidateableSyncCommitteeMessage

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

the class SyncCommitteeMessagePoolTest method createContributionFrom.

private SyncCommitteeContribution createContributionFrom(final int subnetId, final ValidateableSyncCommitteeMessage... messages) {
    checkArgument(messages.length > 0, "Must specify at least one message");
    final ValidateableSyncCommitteeMessage template = messages[0];
    final IntSet participantIds = new IntOpenHashSet();
    final List<BLSSignature> blsSignatures = new ArrayList<>();
    for (ValidateableSyncCommitteeMessage message : messages) {
        participantIds.addAll(message.getSubcommitteeAssignments().orElseThrow().getParticipationBitIndices(subnetId));
        blsSignatures.add(message.getMessage().getSignature());
    }
    return spec.getSyncCommitteeUtilRequired(template.getSlot()).createSyncCommitteeContribution(template.getSlot(), template.getBeaconBlockRoot(), UInt64.valueOf(subnetId), participantIds, BLS.aggregate(blsSignatures));
}
Also used : IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) IntSet(it.unimi.dsi.fastutil.ints.IntSet) ArrayList(java.util.ArrayList) ValidateableSyncCommitteeMessage(tech.pegasys.teku.spec.datastructures.operations.versions.altair.ValidateableSyncCommitteeMessage) BLSSignature(tech.pegasys.teku.bls.BLSSignature)

Aggregations

ValidateableSyncCommitteeMessage (tech.pegasys.teku.spec.datastructures.operations.versions.altair.ValidateableSyncCommitteeMessage)19 Test (org.junit.jupiter.api.Test)15 SyncCommitteeContribution (tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContribution)6 Bytes32 (org.apache.tuweni.bytes.Bytes32)4 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)4 SyncCommitteeMessage (tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage)3 SyncSubcommitteeAssignments (tech.pegasys.teku.spec.datastructures.util.SyncSubcommitteeAssignments)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 BLSSignature (tech.pegasys.teku.bls.BLSSignature)2 BeaconStateAltair (tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.BeaconStateAltair)2 SyncCommitteeUtil (tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil)2 IntOpenHashSet (it.unimi.dsi.fastutil.ints.IntOpenHashSet)1 IntSet (it.unimi.dsi.fastutil.ints.IntSet)1 ArrayList (java.util.ArrayList)1 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)1