Search in sources :

Example 1 with InclusionInfo

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

the class ValidatorStatusFactoryPhase0 method processParticipation.

@Override
protected void processParticipation(final List<ValidatorStatus> statuses, final BeaconState genericState, final UInt64 previousEpoch, final UInt64 currentEpoch) {
    final BeaconStatePhase0 state = BeaconStatePhase0.required(genericState);
    Stream.concat(state.getPrevious_epoch_attestations().stream(), state.getCurrent_epoch_attestations().stream()).forEach(attestation -> {
        final AttestationData data = attestation.getData();
        final AttestationUpdates updates = new AttestationUpdates();
        final Checkpoint target = data.getTarget();
        if (target.getEpoch().equals(currentEpoch)) {
            updates.currentEpochSourceAttester = true;
            updates.currentEpochTargetAttester = matchesEpochStartBlock(state, currentEpoch, target.getRoot());
        } else if (target.getEpoch().equals(previousEpoch)) {
            updates.previousEpochSourceAttester = true;
            updates.inclusionInfo = Optional.of(new InclusionInfo(attestation.getInclusion_delay(), attestation.getProposer_index()));
            if (matchesEpochStartBlock(state, previousEpoch, target.getRoot())) {
                updates.previousEpochTargetAttester = true;
                updates.previousEpochHeadAttester = beaconStateAccessors.getBlockRootAtSlot(state, data.getSlot()).equals(data.getBeacon_block_root());
            }
        }
        // Apply flags to attestingIndices
        attestationUtil.streamAttestingIndices(state, data, attestation.getAggregation_bits()).mapToObj(statuses::get).forEach(updates::apply);
    });
}
Also used : AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) BeaconStatePhase0(tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.phase0.BeaconStatePhase0) InclusionInfo(tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.InclusionInfo)

Example 2 with InclusionInfo

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

the class RewardsAndPenaltiesCalculatorPhase0 method applyInclusionDelayDelta.

public void applyInclusionDelayDelta(final ValidatorStatus validator, final UInt64 baseReward, final RewardAndPenalty delta, final RewardAndPenaltyDeltas deltas) {
    if (validator.isPreviousEpochSourceAttester() && !validator.isSlashed()) {
        final InclusionInfo inclusionInfo = validator.getInclusionInfo().orElseThrow(() -> new IllegalStateException("Validator was active in previous epoch but has no inclusion information."));
        final UInt64 proposerReward = getProposerReward(baseReward);
        final UInt64 maxAttesterReward = baseReward.minus(proposerReward);
        delta.reward(maxAttesterReward.dividedBy(inclusionInfo.getDelay()));
        deltas.getDelta(inclusionInfo.getProposerIndex()).reward(getProposerReward(baseReward));
    }
}
Also used : UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) InclusionInfo(tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.InclusionInfo)

Aggregations

InclusionInfo (tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.InclusionInfo)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 AttestationData (tech.pegasys.teku.spec.datastructures.operations.AttestationData)1 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)1 BeaconStatePhase0 (tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.phase0.BeaconStatePhase0)1