Search in sources :

Example 1 with SszMutableUInt64List

use of tech.pegasys.teku.infrastructure.ssz.collections.SszMutableUInt64List in project teku by ConsenSys.

the class EpochTransitionBenchmark method applyDeltas.

@Benchmark
public void applyDeltas(Blackhole bh) {
    final SszMutableUInt64List balances = preEpochTransitionMutableState.getBalances();
    int validatorsSize = preEpochTransitionMutableState.getValidators().size();
    for (int i = 0; i < validatorsSize; i++) {
        final RewardAndPenalty delta = attestationDeltas.getDelta(i);
        balances.setElement(i, balances.getElement(i).plus(delta.getReward()).minusMinZero(delta.getPenalty()));
    }
}
Also used : RewardAndPenalty(tech.pegasys.teku.spec.logic.common.statetransition.epoch.RewardAndPenaltyDeltas.RewardAndPenalty) SszMutableUInt64List(tech.pegasys.teku.infrastructure.ssz.collections.SszMutableUInt64List) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 2 with SszMutableUInt64List

use of tech.pegasys.teku.infrastructure.ssz.collections.SszMutableUInt64List in project teku by ConsenSys.

the class EpochProcessorAltair method processInactivityUpdates.

@Override
public void processInactivityUpdates(final MutableBeaconState baseState, final ValidatorStatuses validatorStatuses) {
    if (beaconStateAccessors.getCurrentEpoch(baseState).equals(SpecConfig.GENESIS_EPOCH)) {
        return;
    }
    final MutableBeaconStateAltair state = MutableBeaconStateAltair.required(baseState);
    final SszMutableUInt64List inactivityScores = state.getInactivityScores();
    final List<ValidatorStatus> statuses = validatorStatuses.getStatuses();
    final boolean isInInactivityLeak = beaconStateAccessors.isInactivityLeak(state);
    for (int i = 0; i < statuses.size(); i++) {
        final ValidatorStatus validatorStatus = statuses.get(i);
        if (!validatorStatus.isEligibleValidator()) {
            continue;
        }
        // Increase inactivity score of inactive validators
        final UInt64 currentScore = inactivityScores.getElement(i);
        UInt64 newScore;
        if (validatorStatus.isNotSlashed() && validatorStatus.isPreviousEpochTargetAttester()) {
            newScore = currentScore.minusMinZero(1);
        } else {
            newScore = currentScore.plus(specConfigAltair.getInactivityScoreBias());
        }
        // Decrease the score of all validators for forgiveness when not during a leak
        if (!isInInactivityLeak) {
            newScore = newScore.minusMinZero(specConfigAltair.getInactivityScoreRecoveryRate());
        }
        if (!currentScore.equals(newScore)) {
            inactivityScores.setElement(i, newScore);
        }
    }
}
Also used : SszMutableUInt64List(tech.pegasys.teku.infrastructure.ssz.collections.SszMutableUInt64List) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) MutableBeaconStateAltair(tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.MutableBeaconStateAltair) ValidatorStatus(tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.ValidatorStatus)

Example 3 with SszMutableUInt64List

use of tech.pegasys.teku.infrastructure.ssz.collections.SszMutableUInt64List in project teku by ConsenSys.

the class AbstractEpochProcessor method applyDeltas.

protected void applyDeltas(final MutableBeaconState state, final RewardAndPenaltyDeltas attestationDeltas) {
    final SszMutableUInt64List balances = state.getBalances();
    // To optimize performance, calculate validator size once outside of the loop
    int validatorsCount = state.getValidators().size();
    for (int i = 0; i < validatorsCount; i++) {
        final RewardAndPenalty delta = attestationDeltas.getDelta(i);
        balances.setElement(i, balances.getElement(i).plus(delta.getReward()).minusMinZero(delta.getPenalty()));
    }
}
Also used : RewardAndPenalty(tech.pegasys.teku.spec.logic.common.statetransition.epoch.RewardAndPenaltyDeltas.RewardAndPenalty) SszMutableUInt64List(tech.pegasys.teku.infrastructure.ssz.collections.SszMutableUInt64List) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint)

Aggregations

SszMutableUInt64List (tech.pegasys.teku.infrastructure.ssz.collections.SszMutableUInt64List)3 RewardAndPenalty (tech.pegasys.teku.spec.logic.common.statetransition.epoch.RewardAndPenaltyDeltas.RewardAndPenalty)2 Benchmark (org.openjdk.jmh.annotations.Benchmark)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)1 MutableBeaconStateAltair (tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.MutableBeaconStateAltair)1 ValidatorStatus (tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.ValidatorStatus)1