Search in sources :

Example 1 with SyncAggregateSchema

use of tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregateSchema in project teku by ConsenSys.

the class BeaconBlockBodyAltair method asInternalBeaconBlockBody.

@Override
public tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody asInternalBeaconBlockBody(final SpecVersion spec, Consumer<BeaconBlockBodyBuilder> builderRef) {
    BeaconBlockBodySchemaAltair<?> schema = (BeaconBlockBodySchemaAltair<?>) spec.getSchemaDefinitions().getBeaconBlockBodySchema();
    SyncAggregateSchema syncAggregateSchema = schema.getSyncAggregateSchema();
    return super.asInternalBeaconBlockBody(spec, (builder) -> {
        builderRef.accept(builder);
        builder.syncAggregate(() -> syncAggregateSchema.create(syncAggregateSchema.getSyncCommitteeBitsSchema().fromBytes(syncAggregate.syncCommitteeBits).getAllSetBits(), syncAggregate.syncCommitteeSignature.asInternalBLSSignature()));
    });
}
Also used : SyncAggregateSchema(tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregateSchema) BeaconBlockBodySchemaAltair(tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.BeaconBlockBodySchemaAltair)

Example 2 with SyncAggregateSchema

use of tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregateSchema in project teku by ConsenSys.

the class SyncCommitteeUtil method createSyncAggregate.

public SyncAggregate createSyncAggregate(final Iterable<SyncCommitteeContribution> contributions) {
    final SyncAggregateSchema schema = BeaconBlockBodySchemaAltair.required(schemaDefinitionsAltair.getBeaconBlockBodySchema()).getSyncAggregateSchema();
    final IntList participantIndices = new IntArrayList();
    final List<BLSSignature> signatures = new ArrayList<>();
    for (SyncCommitteeContribution contribution : contributions) {
        final int subcommitteeIndex = contribution.getSubcommitteeIndex().intValue();
        final int subcommitteeOffset = getSubcommitteeSize() * subcommitteeIndex;
        contribution.getAggregationBits().streamAllSetBits().forEach(index -> participantIndices.add(subcommitteeOffset + index));
        signatures.add(contribution.getSignature());
    }
    if (signatures.isEmpty()) {
        return schema.createEmpty();
    } else {
        return schema.create(participantIndices, BLS.aggregate(signatures));
    }
}
Also used : SyncAggregateSchema(tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregateSchema) ArrayList(java.util.ArrayList) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) SyncCommitteeContribution(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContribution) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) BLSSignature(tech.pegasys.teku.bls.BLSSignature) IntList(it.unimi.dsi.fastutil.ints.IntList)

Aggregations

SyncAggregateSchema (tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregateSchema)2 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)1 IntList (it.unimi.dsi.fastutil.ints.IntList)1 ArrayList (java.util.ArrayList)1 BLSSignature (tech.pegasys.teku.bls.BLSSignature)1 BeaconBlockBodySchemaAltair (tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.BeaconBlockBodySchemaAltair)1 SyncCommitteeContribution (tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContribution)1