use of tech.pegasys.teku.spec.logic.common.statetransition.epoch.RewardAndPenaltyDeltas.RewardAndPenalty 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()));
}
}
use of tech.pegasys.teku.spec.logic.common.statetransition.epoch.RewardAndPenaltyDeltas.RewardAndPenalty 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.RewardAndPenaltyDeltas.RewardAndPenalty 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.RewardAndPenaltyDeltas.RewardAndPenalty 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()));
}
}
Aggregations