Search in sources :

Example 1 with RewardAndPenaltyDeltas

use of tech.pegasys.teku.spec.logic.common.statetransition.epoch.RewardAndPenaltyDeltas 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;
}
Also used : TotalBalances(tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.TotalBalances) RewardAndPenalty(tech.pegasys.teku.spec.logic.common.statetransition.epoch.RewardAndPenaltyDeltas.RewardAndPenalty) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) ValidatorStatus(tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.ValidatorStatus) RewardAndPenaltyDeltas(tech.pegasys.teku.spec.logic.common.statetransition.epoch.RewardAndPenaltyDeltas)

Example 2 with RewardAndPenaltyDeltas

use of tech.pegasys.teku.spec.logic.common.statetransition.epoch.RewardAndPenaltyDeltas in project teku by ConsenSys.

the class RewardsTestExecutorAltair method assertDeltas.

private void assertDeltas(final TestDefinition testDefinition, final String expectedResultsFileName, final Supplier<RewardAndPenaltyDeltas> function) {
    final RewardAndPenaltyDeltas expectedDeltas = loadSsz(testDefinition, expectedResultsFileName, ExpectedDeltas.SSZ_SCHEMA).getDeltas();
    final RewardAndPenaltyDeltas actualDeltas = function.get();
    assertThat(actualDeltas).describedAs(expectedResultsFileName).isEqualToComparingFieldByField(expectedDeltas);
}
Also used : RewardAndPenaltyDeltas(tech.pegasys.teku.spec.logic.common.statetransition.epoch.RewardAndPenaltyDeltas)

Example 3 with RewardAndPenaltyDeltas

use of tech.pegasys.teku.spec.logic.common.statetransition.epoch.RewardAndPenaltyDeltas in project teku by ConsenSys.

the class ExpectedDeltas method getDeltas.

public RewardAndPenaltyDeltas getDeltas() {
    final SszUInt64List rewards = getField0();
    final SszUInt64List penalties = getField1();
    final RewardAndPenaltyDeltas deltas = new RewardAndPenaltyDeltas(rewards.size());
    for (int i = 0; i < rewards.size(); i++) {
        deltas.getDelta(i).reward(rewards.get(i).get());
        deltas.getDelta(i).penalize(penalties.get(i).get());
    }
    return deltas;
}
Also used : SszUInt64List(tech.pegasys.teku.infrastructure.ssz.collections.SszUInt64List) RewardAndPenaltyDeltas(tech.pegasys.teku.spec.logic.common.statetransition.epoch.RewardAndPenaltyDeltas)

Example 4 with RewardAndPenaltyDeltas

use of tech.pegasys.teku.spec.logic.common.statetransition.epoch.RewardAndPenaltyDeltas in project teku by ConsenSys.

the class RewardsAndPenaltiesCalculatorAltair method getDeltas.

/**
 * Return attestation reward/penalty deltas for each validator
 *
 * @return
 * @throws IllegalArgumentException
 */
@Override
public RewardAndPenaltyDeltas getDeltas() throws IllegalArgumentException {
    final RewardAndPenaltyDeltas deltas = new RewardAndPenaltyDeltas(validatorStatuses.getValidatorCount());
    for (int flagIndex = 0; flagIndex < PARTICIPATION_FLAG_WEIGHTS.size(); flagIndex++) {
        processFlagIndexDeltas(deltas, flagIndex);
    }
    processInactivityPenaltyDeltas(deltas);
    return deltas;
}
Also used : RewardAndPenaltyDeltas(tech.pegasys.teku.spec.logic.common.statetransition.epoch.RewardAndPenaltyDeltas)

Example 5 with RewardAndPenaltyDeltas

use of tech.pegasys.teku.spec.logic.common.statetransition.epoch.RewardAndPenaltyDeltas in project teku by ConsenSys.

the class RewardsTestExecutorPhase0 method assertDeltas.

private void assertDeltas(final TestDefinition testDefinition, final String expectedResultsFileName, final Supplier<RewardAndPenaltyDeltas> function) {
    final RewardAndPenaltyDeltas expectedDeltas = loadSsz(testDefinition, expectedResultsFileName, ExpectedDeltas.SSZ_SCHEMA).getDeltas();
    final RewardAndPenaltyDeltas actualDeltas = function.get();
    assertThat(actualDeltas).describedAs(expectedResultsFileName).isEqualToComparingFieldByField(expectedDeltas);
}
Also used : RewardAndPenaltyDeltas(tech.pegasys.teku.spec.logic.common.statetransition.epoch.RewardAndPenaltyDeltas)

Aggregations

RewardAndPenaltyDeltas (tech.pegasys.teku.spec.logic.common.statetransition.epoch.RewardAndPenaltyDeltas)5 SszUInt64List (tech.pegasys.teku.infrastructure.ssz.collections.SszUInt64List)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 RewardAndPenalty (tech.pegasys.teku.spec.logic.common.statetransition.epoch.RewardAndPenaltyDeltas.RewardAndPenalty)1 TotalBalances (tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.TotalBalances)1 ValidatorStatus (tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.ValidatorStatus)1