Search in sources :

Example 1 with PendingAttestation

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));
            }
        });
    }
}
Also used : PendingAttestation(tech.pegasys.teku.spec.datastructures.state.PendingAttestation) AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) SszByte(tech.pegasys.teku.infrastructure.ssz.primitive.SszByte) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SszUInt64(tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt64)

Example 2 with PendingAttestation

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);
}
Also used : PendingAttestation(tech.pegasys.teku.spec.datastructures.state.PendingAttestation) SszBitlist(tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist) Test(org.junit.jupiter.api.Test)

Example 3 with PendingAttestation

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();
}
Also used : PendingAttestation(tech.pegasys.teku.spec.datastructures.state.PendingAttestation) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) ArrayList(java.util.ArrayList) SszBitlist(tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) Test(org.junit.jupiter.api.Test)

Example 4 with PendingAttestation

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);
}
Also used : PendingAttestation(tech.pegasys.teku.spec.datastructures.state.PendingAttestation) SszBitlist(tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist) Test(org.junit.jupiter.api.Test)

Example 5 with PendingAttestation

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);
    }
}
Also used : PendingAttestation(tech.pegasys.teku.spec.datastructures.state.PendingAttestation) MutableBeaconStatePhase0(tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.phase0.MutableBeaconStatePhase0) AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData)

Aggregations

PendingAttestation (tech.pegasys.teku.spec.datastructures.state.PendingAttestation)9 Test (org.junit.jupiter.api.Test)7 SszBitlist (tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist)7 ArrayList (java.util.ArrayList)3 Bytes32 (org.apache.tuweni.bytes.Bytes32)3 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)3 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)2 AttestationData (tech.pegasys.teku.spec.datastructures.operations.AttestationData)2 SszByte (tech.pegasys.teku.infrastructure.ssz.primitive.SszByte)1 SszUInt64 (tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt64)1 MutableBeaconStatePhase0 (tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.phase0.MutableBeaconStatePhase0)1