use of tech.pegasys.teku.spec.datastructures.operations.AttestationData in project teku by ConsenSys.
the class ValidatorApiHandlerTest method createAttestationData_shouldUseCorrectSourceWhenEpochTransitionRequired.
@Test
public void createAttestationData_shouldUseCorrectSourceWhenEpochTransitionRequired() {
final UInt64 slot = spec.computeStartSlotAtEpoch(EPOCH);
when(chainDataClient.getCurrentSlot()).thenReturn(slot);
// Slot is from before the current epoch, so we need to ensure we process the epoch transition
final UInt64 blockSlot = slot.minus(1);
final BeaconState wrongState = createStateWithActiveValidators(blockSlot);
final BeaconState rightState = createStateWithActiveValidators(slot);
final SignedBeaconBlock block = dataStructureUtil.randomSignedBeaconBlock(wrongState.getSlot(), wrongState);
final SignedBlockAndState blockAndState = new SignedBlockAndState(block, wrongState);
final SafeFuture<Optional<SignedBlockAndState>> blockAndStateResult = completedFuture(Optional.of(blockAndState));
when(chainDataClient.getSignedBlockAndStateInEffectAtSlot(slot)).thenReturn(blockAndStateResult);
when(chainDataClient.getCheckpointState(EPOCH, blockAndState)).thenReturn(SafeFuture.completedFuture(CheckpointState.create(spec, new Checkpoint(EPOCH, block.getRoot()), block, rightState)));
when(forkChoiceTrigger.prepareForAttestationProduction(slot)).thenReturn(SafeFuture.COMPLETE);
final int committeeIndex = 0;
final SafeFuture<Optional<AttestationData>> result = validatorApiHandler.createAttestationData(slot, committeeIndex);
assertThat(result).isCompleted();
final Optional<AttestationData> maybeAttestation = result.join();
assertThat(maybeAttestation).isPresent();
final AttestationData attestationData = maybeAttestation.orElseThrow();
assertThat(attestationData).isEqualTo(spec.getGenericAttestationData(slot, rightState, block.getMessage(), UInt64.valueOf(committeeIndex)));
assertThat(attestationData.getSlot()).isEqualTo(slot);
}
use of tech.pegasys.teku.spec.datastructures.operations.AttestationData in project teku by ConsenSys.
the class LocalSignerTest method shouldSignAttestationData.
@Test
public void shouldSignAttestationData() {
final AttestationData attestationData = dataStructureUtil.randomAttestationData();
final BLSSignature expectedSignature = BLSSignature.fromBytesCompressed(Bytes.fromBase64String("l1DUv3fmbvZanhCaaraMk2PKAl+33sf3UHMbxkv18CKILzzIz+Hr6hnLXCHqWQYEGKTtLcf6OLV7Z+Y21BW2bBtJHXJqqzvWkec/j0X0hWaEoWOSAs20sipO1WSIUY2m"));
final SafeFuture<BLSSignature> result = signer.signAttestationData(attestationData, fork);
asyncRunner.executeQueuedActions();
assertThat(result).isCompletedWithValue(expectedSignature);
}
use of tech.pegasys.teku.spec.datastructures.operations.AttestationData in project teku by ConsenSys.
the class SlashingProtectedSignerTest method signAttestationData_shouldNotSignWhenSlashingProtectionRejects.
@Test
void signAttestationData_shouldNotSignWhenSlashingProtectionRejects() {
final AttestationData attestationData = dataStructureUtil.randomAttestationData();
when(slashingProtector.maySignAttestation(publicKey, forkInfo.getGenesisValidatorsRoot(), attestationData.getSource().getEpoch(), attestationData.getTarget().getEpoch())).thenReturn(SafeFuture.completedFuture(false));
when(delegate.signAttestationData(attestationData, forkInfo)).thenReturn(signatureFuture);
assertThatSafeFuture(signer.signAttestationData(attestationData, forkInfo)).isCompletedExceptionallyWith(SlashableConditionException.class);
}
use of tech.pegasys.teku.spec.datastructures.operations.AttestationData in project teku by ConsenSys.
the class AttestationUtil method getGenericAttestationData.
// Get attestation data that does not include attester specific shard or crosslink information
public AttestationData getGenericAttestationData(UInt64 slot, BeaconState state, BeaconBlockSummary block, final UInt64 committeeIndex) {
UInt64 epoch = miscHelpers.computeEpochAtSlot(slot);
// Get variables necessary that can be shared among Attestations of all validators
Bytes32 beacon_block_root = block.getRoot();
UInt64 start_slot = miscHelpers.computeStartSlotAtEpoch(epoch);
Bytes32 epoch_boundary_block_root = start_slot.compareTo(slot) == 0 || state.getSlot().compareTo(start_slot) <= 0 ? block.getRoot() : beaconStateAccessors.getBlockRootAtSlot(state, start_slot);
Checkpoint source = state.getCurrent_justified_checkpoint();
Checkpoint target = new Checkpoint(epoch, epoch_boundary_block_root);
// Set attestation data
return new AttestationData(slot, committeeIndex, beacon_block_root, source, target);
}
use of tech.pegasys.teku.spec.datastructures.operations.AttestationData in project teku by ConsenSys.
the class AltairStateUpgrade method translateParticipation.
private void translateParticipation(final MutableBeaconStateAltair state, final SszList<PendingAttestation> pendingAttestations) {
for (PendingAttestation attestation : pendingAttestations) {
final AttestationData data = attestation.getData();
final UInt64 inclusionDelay = attestation.getInclusion_delay();
// Translate attestation inclusion info to flag indices
final List<Integer> participationFlagIndices = beaconStateAccessors.getAttestationParticipationFlagIndices(state, data, inclusionDelay);
// Apply flags to all attesting validators
final SszMutableList<SszByte> epochParticipation = state.getPreviousEpochParticipation();
attestationUtil.streamAttestingIndices(state, data, attestation.getAggregation_bits()).forEach(index -> {
final byte previousFlags = epochParticipation.get(index).get();
byte newFlags = previousFlags;
for (int flagIndex : participationFlagIndices) {
newFlags = miscHelpersAltair.addFlag(newFlags, flagIndex);
}
if (previousFlags != newFlags) {
epochParticipation.set(index, SszByte.of(newFlags));
}
});
}
}
Aggregations