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);
});
}
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));
}
}
Aggregations