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