use of tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.ValidatorStatus 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);
}
}
}
use of tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.ValidatorStatus in project teku by ConsenSys.
the class ValidatorStatusFactoryAltair method processParticipation.
@Override
protected void processParticipation(final List<ValidatorStatus> statuses, final BeaconState genericState, final UInt64 previousEpoch, final UInt64 currentEpoch) {
final BeaconStateAltair state = BeaconStateAltair.required(genericState);
final SszList<SszByte> previousParticipation = state.getPreviousEpochParticipation();
final SszList<SszByte> currentParticipation = state.getCurrentEpochParticipation();
for (int i = 0; i < statuses.size(); i++) {
final ValidatorStatus status = statuses.get(i);
if (status.isActiveInPreviousEpoch()) {
final byte previousParticipationFlags = previousParticipation.get(i).get();
if (miscHelpersAltair.hasFlag(previousParticipationFlags, ParticipationFlags.TIMELY_SOURCE_FLAG_INDEX)) {
status.updatePreviousEpochSourceAttester(true);
}
if (miscHelpersAltair.hasFlag(previousParticipationFlags, ParticipationFlags.TIMELY_TARGET_FLAG_INDEX)) {
status.updatePreviousEpochTargetAttester(true);
}
if (miscHelpersAltair.hasFlag(previousParticipationFlags, ParticipationFlags.TIMELY_HEAD_FLAG_INDEX)) {
status.updatePreviousEpochHeadAttester(true);
}
}
if (status.isActiveInCurrentEpoch()) {
final byte currentParticipationFlags = currentParticipation.get(i).get();
if (miscHelpersAltair.hasFlag(currentParticipationFlags, ParticipationFlags.TIMELY_SOURCE_FLAG_INDEX)) {
status.updateCurrentEpochSourceAttester(true);
}
if (miscHelpersAltair.hasFlag(currentParticipationFlags, ParticipationFlags.TIMELY_TARGET_FLAG_INDEX)) {
status.updateCurrentEpochTargetAttester(true);
}
}
}
}
use of tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.ValidatorStatus in project teku by ConsenSys.
the class RewardsAndPenaltiesCalculatorPhase0 method getDeltas.
public RewardAndPenaltyDeltas getDeltas(final Step step) throws IllegalArgumentException {
final RewardAndPenaltyDeltas deltas = new RewardAndPenaltyDeltas(validatorStatuses.getValidatorCount());
final TotalBalances totalBalances = validatorStatuses.getTotalBalances();
final List<ValidatorStatus> statuses = validatorStatuses.getStatuses();
final UInt64 finalityDelay = getFinalityDelay();
final UInt64 totalActiveBalanceSquareRoot = squareRootOrZero(totalBalances.getCurrentEpochActiveValidators());
for (int index = 0; index < statuses.size(); index++) {
final ValidatorStatus validator = statuses.get(index);
if (!validator.isEligibleValidator()) {
continue;
}
final UInt64 baseReward = getBaseReward(validator, totalActiveBalanceSquareRoot);
final RewardAndPenalty delta = deltas.getDelta(index);
step.apply(deltas, totalBalances, finalityDelay, validator, baseReward, delta);
}
return deltas;
}
use of tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.ValidatorStatus in project teku by ConsenSys.
the class RewardsAndPenaltiesCalculatorAltair method processFlagIndexDeltas.
/**
* Corresponds to altair beacon chain accessor get_flag_index_deltas
*
* @see <a
* href="https://github.com/ethereum/eth2.0-specs/blob/master/specs/altair/beacon-chain.md#beacon-state-accessors">Altair
* beacon-chain.md</a>
* @param deltas The deltas accumulator (holding deltas for all validators) to be updated
* @param flagIndex The flag index to process
*/
public void processFlagIndexDeltas(final RewardAndPenaltyDeltas deltas, final int flagIndex) {
final List<ValidatorStatus> statusList = validatorStatuses.getStatuses();
final TotalBalances totalBalances = validatorStatuses.getTotalBalances();
final UInt64 effectiveBalanceIncrement = specConfigAltair.getEffectiveBalanceIncrement();
final UInt64 unslashedParticipatingIncrements = getPrevEpochTotalParticipatingBalance(flagIndex).dividedBy(effectiveBalanceIncrement);
final UInt64 weight = PARTICIPATION_FLAG_WEIGHTS.get(flagIndex);
final UInt64 activeIncrements = totalBalances.getCurrentEpochActiveValidators().dividedBy(effectiveBalanceIncrement);
for (int i = 0; i < statusList.size(); i++) {
final ValidatorStatus validator = statusList.get(i);
if (!validator.isEligibleValidator()) {
continue;
}
final RewardAndPenalty validatorDeltas = deltas.getDelta(i);
final UInt64 baseReward = getBaseReward(i);
if (isUnslashedPrevEpochParticipatingIndex(validator, flagIndex)) {
if (!isInactivityLeak()) {
final UInt64 rewardNumerator = baseReward.times(weight).times(unslashedParticipatingIncrements);
validatorDeltas.reward(rewardNumerator.dividedBy(activeIncrements.times(WEIGHT_DENOMINATOR)));
}
} else if (flagIndex != TIMELY_HEAD_FLAG_INDEX) {
validatorDeltas.penalize(baseReward.times(weight).dividedBy(WEIGHT_DENOMINATOR));
}
}
}
use of tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.ValidatorStatus in project teku by ConsenSys.
the class RewardsAndPenaltiesCalculatorAltair method processInactivityPenaltyDeltas.
/**
* Corresponds to altair beacon chain accessor get_inactivity_penalty_deltas
*
* @see <a
* href="https://github.com/ethereum/eth2.0-specs/blob/master/specs/altair/beacon-chain.md#beacon-state-accessors">Altair
* beacon-chain.md</a>
* @param deltas The deltas accumulator (holding deltas for all validators) to be updated
*/
public void processInactivityPenaltyDeltas(final RewardAndPenaltyDeltas deltas) {
final List<ValidatorStatus> statusList = validatorStatuses.getStatuses();
for (int i = 0; i < statusList.size(); i++) {
final ValidatorStatus validator = statusList.get(i);
if (!validator.isEligibleValidator()) {
continue;
}
if (validator.isPreviousEpochTargetAttester() && !validator.isSlashed()) {
continue;
}
final UInt64 penaltyNumerator = validator.getCurrentEpochEffectiveBalance().times(stateAltair.getInactivityScores().get(i).get());
final UInt64 penaltyDenominator = specConfigAltair.getInactivityScoreBias().times(getInactivityPenaltyQuotient());
final UInt64 penalty = penaltyNumerator.dividedBy(penaltyDenominator);
deltas.getDelta(i).penalize(penalty);
}
}
Aggregations