Search in sources :

Example 1 with AttestationSchema

use of tech.pegasys.teku.spec.datastructures.operations.Attestation.AttestationSchema in project teku by ConsenSys.

the class AttestationProductionDutyTest method createExpectedAttestation.

public Attestation createExpectedAttestation(final AttestationData attestationData, final int committeePosition, final int committeeSize, final BLSSignature signature) {
    final AttestationSchema attestationSchema = spec.atSlot(attestationData.getSlot()).getSchemaDefinitions().getAttestationSchema();
    final SszBitlist expectedAggregationBits = attestationSchema.getAggregationBitsSchema().ofBits(committeeSize, committeePosition);
    return attestationSchema.create(expectedAggregationBits, attestationData, signature);
}
Also used : AttestationSchema(tech.pegasys.teku.spec.datastructures.operations.Attestation.AttestationSchema) SszBitlist(tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist)

Example 2 with AttestationSchema

use of tech.pegasys.teku.spec.datastructures.operations.Attestation.AttestationSchema in project teku by ConsenSys.

the class AttestationProductionDuty method createSignedAttestation.

private Attestation createSignedAttestation(final AttestationData attestationData, final ValidatorWithCommitteePositionAndIndex validator, final BLSSignature signature) {
    final AttestationSchema attestationSchema = spec.atSlot(attestationData.getSlot()).getSchemaDefinitions().getAttestationSchema();
    SszBitlist aggregationBits = attestationSchema.getAggregationBitsSchema().ofBits(validator.getCommitteeSize(), validator.getCommitteePosition());
    return attestationSchema.create(aggregationBits, attestationData, signature);
}
Also used : AttestationSchema(tech.pegasys.teku.spec.datastructures.operations.Attestation.AttestationSchema) SszBitlist(tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist)

Example 3 with AttestationSchema

use of tech.pegasys.teku.spec.datastructures.operations.Attestation.AttestationSchema in project teku by ConsenSys.

the class AttestationGenerator method aggregateAttestations.

/**
 * Aggregates passed attestations
 *
 * @param srcAttestations attestations which should have the same {@link Attestation#getData()}
 */
public static Attestation aggregateAttestations(List<Attestation> srcAttestations) {
    Preconditions.checkArgument(!srcAttestations.isEmpty(), "Expected at least one attestation");
    final AttestationSchema attestationSchema = srcAttestations.get(0).getSchema();
    int targetBitlistSize = srcAttestations.stream().mapToInt(a -> a.getAggregationBits().size()).max().getAsInt();
    SszBitlist targetBitlist = srcAttestations.stream().map(Attestation::getAggregationBits).reduce(attestationSchema.getAggregationBitsSchema().ofBits(targetBitlistSize), SszBitlist::or, SszBitlist::or);
    BLSSignature targetSig = BLS.aggregate(srcAttestations.stream().map(Attestation::getAggregateSignature).collect(Collectors.toList()));
    return attestationSchema.create(targetBitlist, srcAttestations.get(0).getData(), targetSig);
}
Also used : AttestationSchema(tech.pegasys.teku.spec.datastructures.operations.Attestation.AttestationSchema) SszBitlist(tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) BLSSignature(tech.pegasys.teku.bls.BLSSignature)

Example 4 with AttestationSchema

use of tech.pegasys.teku.spec.datastructures.operations.Attestation.AttestationSchema in project teku by ConsenSys.

the class AttestationManagerIntegrationTest method createAttestation.

private ValidateableAttestation createAttestation(final UInt64 attestationSlot, final SignedBlockAndState targetBlockAndState, final Fork fork) {
    final int validatorCommitteePosition = 0;
    final IntList committee = spec.getBeaconCommittee(targetBlockAndState.getState(), attestationSlot, COMMITTEE_INDEX);
    final int validatorId = committee.getInt(validatorCommitteePosition);
    final AttestationData attestationData = spec.getGenericAttestationData(attestationSlot, targetBlockAndState.getState(), targetBlockAndState, COMMITTEE_INDEX);
    final ForkInfo forkInfo = new ForkInfo(fork, targetBlockAndState.getState().getGenesis_validators_root());
    final BLSSignature signature = storageSystem.chainBuilder().sign(validatorId, signer -> signer.signAttestationData(attestationData, forkInfo));
    final AttestationSchema attestationSchema = spec.atSlot(attestationSlot).getSchemaDefinitions().getAttestationSchema();
    SszBitlist aggregationBits = attestationSchema.getAggregationBitsSchema().ofBits(committee.size(), validatorCommitteePosition);
    final Attestation attestation = attestationSchema.create(aggregationBits, attestationData, signature);
    return ValidateableAttestation.fromNetwork(spec, attestation, spec.computeSubnetForAttestation(targetBlockAndState.getState(), attestation));
}
Also used : AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) AttestationSchema(tech.pegasys.teku.spec.datastructures.operations.Attestation.AttestationSchema) SszBitlist(tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) BLSSignature(tech.pegasys.teku.bls.BLSSignature) IntList(it.unimi.dsi.fastutil.ints.IntList)

Aggregations

SszBitlist (tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist)4 AttestationSchema (tech.pegasys.teku.spec.datastructures.operations.Attestation.AttestationSchema)4 BLSSignature (tech.pegasys.teku.bls.BLSSignature)2 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)2 IntList (it.unimi.dsi.fastutil.ints.IntList)1 ValidateableAttestation (tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation)1 AttestationData (tech.pegasys.teku.spec.datastructures.operations.AttestationData)1 ForkInfo (tech.pegasys.teku.spec.datastructures.state.ForkInfo)1