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