use of tech.pegasys.teku.infrastructure.ssz.SszMutableList in project teku by ConsenSys.
the class AbstractEpochProcessor method processRegistryUpdates.
/**
* Processes validator registry updates
*/
@Override
public void processRegistryUpdates(MutableBeaconState state, List<ValidatorStatus> statuses) throws EpochProcessingException {
try {
// Process activation eligibility and ejections
SszMutableList<Validator> validators = state.getValidators();
final UInt64 currentEpoch = beaconStateAccessors.getCurrentEpoch(state);
for (int index = 0; index < validators.size(); index++) {
final ValidatorStatus status = statuses.get(index);
// confirm it isn't already in the queue.
if (!status.isActiveInCurrentEpoch() && status.getCurrentEpochEffectiveBalance().equals(specConfig.getMaxEffectiveBalance())) {
final Validator validator = validators.get(index);
if (validator.getActivation_eligibility_epoch().equals(SpecConfig.FAR_FUTURE_EPOCH)) {
validators.set(index, validator.withActivation_eligibility_epoch(currentEpoch.plus(UInt64.ONE)));
}
}
if (status.isActiveInCurrentEpoch() && status.getCurrentEpochEffectiveBalance().isLessThanOrEqualTo(specConfig.getEjectionBalance())) {
beaconStateMutators.initiateValidatorExit(state, index);
}
}
// Queue validators eligible for activation and not yet dequeued for activation
List<Integer> activationQueue = IntStream.range(0, state.getValidators().size()).filter(index -> !statuses.get(index).isActiveInCurrentEpoch()).filter(index -> {
Validator validator = state.getValidators().get(index);
return validatorsUtil.isEligibleForActivation(state, validator);
}).boxed().sorted((index1, index2) -> {
int comparisonResult = state.getValidators().get(index1).getActivation_eligibility_epoch().compareTo(state.getValidators().get(index2).getActivation_eligibility_epoch());
if (comparisonResult == 0) {
return index1.compareTo(index2);
} else {
return comparisonResult;
}
}).collect(Collectors.toList());
// Dequeued validators for activation up to churn limit (without resetting activation epoch)
int churnLimit = beaconStateAccessors.getValidatorChurnLimit(state).intValue();
int sublistSize = Math.min(churnLimit, activationQueue.size());
for (Integer index : activationQueue.subList(0, sublistSize)) {
state.getValidators().update(index, validator -> validator.withActivation_epoch(miscHelpers.computeActivationExitEpoch(currentEpoch)));
}
} catch (IllegalArgumentException e) {
throw new EpochProcessingException(e);
}
}
Aggregations