use of tech.pegasys.teku.spec.datastructures.state.PendingAttestation 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));
}
});
}
}
use of tech.pegasys.teku.spec.datastructures.state.PendingAttestation in project teku by ConsenSys.
the class BeaconChainMetricsTest method currentLiveValidators_treatSameBitIndexInDifferentSlotAsUnique.
@Test
void currentLiveValidators_treatSameBitIndexInDifferentSlotAsUnique() {
final SszBitlist bitlist = bitlistOf(1, 3, 5, 7);
final List<PendingAttestation> attestations = Stream.concat(createAttestations(13, 1, bitlist), createAttestations(14, 1, bitlist)).collect(toList());
withCurrentEpochAttestations(attestations);
assertThat(beaconChainMetrics.updateMetrics()).isCompleted();
assertThat(metricsSystem.getGauge(BEACON, "current_live_validators").getValue()).isEqualTo(8);
}
use of tech.pegasys.teku.spec.datastructures.state.PendingAttestation in project teku by ConsenSys.
the class BeaconChainMetricsTest method currentCorrectValidators_withStateAtFirstSlotOfEpoch.
@Test
void currentCorrectValidators_withStateAtFirstSlotOfEpoch() {
Bytes32 blockRoot = dataStructureUtil.randomBytes32();
final UInt64 slot = spec.computeStartSlotAtEpoch(UInt64.ONE);
Checkpoint target = new Checkpoint(spec.computeEpochAtSlot(slot), blockRoot);
List<Bytes32> blockRootsList = new ArrayList<>(Collections.nCopies(33, dataStructureUtil.randomBytes32()));
blockRootsList.set(slot.mod(slotsPerHistoricalRoot).intValue(), blockRoot);
setBlockRoots(blockRootsList);
final SszBitlist bitlist1 = bitlistOf(1, 3, 5, 7);
final SszBitlist bitlist2 = bitlistOf(2, 4, 6, 8);
List<PendingAttestation> allAttestations = Stream.concat(createAttestationsWithTargetCheckpoint(slot.intValue(), 1, target, bitlist1), createAttestationsWithTargetCheckpoint(slot.intValue(), 1, new Checkpoint(spec.computeEpochAtSlot(slot), blockRoot.not()), bitlist2)).collect(toList());
withCurrentEpochAttestations(allAttestations, slot);
// Make sure we don't try to get the block root for the state's own slot from block roots array
// Otherwise this will fail.
assertThat(beaconChainMetrics.updateMetrics()).isCompleted();
}
use of tech.pegasys.teku.spec.datastructures.state.PendingAttestation in project teku by ConsenSys.
the class BeaconChainMetricsTest method previousLiveValidators_treatSameBitIndexInDifferentSlotAsUnique.
@Test
void previousLiveValidators_treatSameBitIndexInDifferentSlotAsUnique() {
final SszBitlist bitlist = bitlistOf(1, 3, 5, 7);
final List<PendingAttestation> attestations = Stream.concat(createAttestations(13, 1, bitlist), createAttestations(14, 1, bitlist)).collect(toList());
withPreviousEpochAttestations(100, attestations);
assertThat(beaconChainMetrics.updateMetrics()).isCompleted();
assertThat(metricsSystem.getGauge(BEACON, "previous_live_validators").getValue()).isEqualTo(8);
}
use of tech.pegasys.teku.spec.datastructures.state.PendingAttestation in project teku by ConsenSys.
the class BlockProcessorPhase0 method processAttestation.
@Override
protected void processAttestation(final MutableBeaconState genericState, final Attestation attestation, final IndexedAttestationProvider indexedAttestationProvider) {
final MutableBeaconStatePhase0 state = MutableBeaconStatePhase0.required(genericState);
final AttestationData data = attestation.getData();
PendingAttestation pendingAttestation = state.getBeaconStateSchema().getPendingAttestationSchema().create(attestation.getAggregationBits(), data, state.getSlot().minus(data.getSlot()), UInt64.valueOf(beaconStateAccessors.getBeaconProposerIndex(state)));
if (data.getTarget().getEpoch().equals(beaconStateAccessors.getCurrentEpoch(state))) {
state.getCurrent_epoch_attestations().append(pendingAttestation);
} else {
state.getPrevious_epoch_attestations().append(pendingAttestation);
}
}
Aggregations