@Test public void getActiveValidatorsCount() { BeaconState beaconState = dataStructureUtil.randomBeaconState(); System.out.println(beaconState.hashTreeRoot()); SSZList<Validator> allValidators = beaconState.getValidators(); long originalActiveValidatorCount = BeaconValidators.getEffectiveListSize( getValidators(beaconState), true, BeaconStateUtil.compute_epoch_at_slot(beaconState.getSlot())); int originalValidatorCount = allValidators.size(); assertThat(originalActiveValidatorCount) .isLessThanOrEqualTo(beaconState.getValidators().size()); Validator v = dataStructureUtil .randomValidator() .withActivation_eligibility_epoch(UInt64.ZERO) .withActivation_epoch(UInt64.valueOf(Constants.GENESIS_EPOCH)); BeaconState beaconStateW = beaconState.updated(state -> state.getValidators().add(v)); int updatedValidatorCount = beaconStateW.getValidators().size(); long updatedActiveValidatorCount = BeaconValidators.getEffectiveListSize( getValidators(beaconStateW), true, BeaconStateUtil.compute_epoch_at_slot(beaconStateW.getSlot())); SSZList<Validator> updatedValidators = beaconStateW.getValidators(); assertThat(updatedValidators).contains(v); assertThat(beaconStateW.getValidators()).contains(v); assertThat(updatedValidatorCount).isEqualTo(originalValidatorCount + 1); assertThat(updatedActiveValidatorCount).isLessThanOrEqualTo(updatedValidatorCount); assertThat(updatedValidatorCount - updatedActiveValidatorCount) .isEqualTo(originalValidatorCount - originalActiveValidatorCount); }
public static long getEffectiveListSize(List<Validator> list, boolean activeOnly, UInt64 epoch) { if (!activeOnly) { return list.size(); } else { return list.stream().filter(v -> is_active_validator(v, epoch)).count(); } }
BeaconValidators { public static long getEffectiveListSize(List<Validator> list, boolean activeOnly, UInt64 epoch) { if (!activeOnly) { return list.size(); } else { return list.stream().filter(v -> is_active_validator(v, epoch)).count(); } } }
BeaconValidators { public static long getEffectiveListSize(List<Validator> list, boolean activeOnly, UInt64 epoch) { if (!activeOnly) { return list.size(); } else { return list.stream().filter(v -> is_active_validator(v, epoch)).count(); } } @VisibleForTesting  BeaconValidators(tech.pegasys.teku.datastructures.state.BeaconState state); @VisibleForTesting  BeaconValidators(); @VisibleForTesting  BeaconValidators(
      tech.pegasys.teku.datastructures.state.BeaconState state,
      final boolean activeOnly,
      final UInt64 epoch,
      final int pageSize,
      final int pageToken);  BeaconValidators(
      tech.pegasys.teku.datastructures.state.BeaconState state, List<BLSPubKey> filter);  BeaconValidators(
      final BeaconState state, final boolean activeOnly, final int pageSize, final int pageToken);   BeaconValidators(
      final List<Validator> list,
      final List<UInt64> balances,
      final boolean activeOnly,
      final UInt64 epoch,
      final int pageSize,
      final int pageToken); }
BeaconValidators { public static long getEffectiveListSize(List<Validator> list, boolean activeOnly, UInt64 epoch) { if (!activeOnly) { return list.size(); } else { return list.stream().filter(v -> is_active_validator(v, epoch)).count(); } } @VisibleForTesting  BeaconValidators(tech.pegasys.teku.datastructures.state.BeaconState state); @VisibleForTesting  BeaconValidators(); @VisibleForTesting  BeaconValidators(
      tech.pegasys.teku.datastructures.state.BeaconState state,
      final boolean activeOnly,
      final UInt64 epoch,
      final int pageSize,
      final int pageToken);  BeaconValidators(
      tech.pegasys.teku.datastructures.state.BeaconState state, List<BLSPubKey> filter);  BeaconValidators(
      final BeaconState state, final boolean activeOnly, final int pageSize, final int pageToken);   BeaconValidators(
      final List<Validator> list,
      final List<UInt64> balances,
      final boolean activeOnly,
      final UInt64 epoch,
      final int pageSize,
      final int pageToken); static BeaconValidators emptySet(); static long getEffectiveListSize(List<Validator> list, boolean activeOnly, UInt64 epoch); }
BeaconValidators { public static long getEffectiveListSize(List<Validator> list, boolean activeOnly, UInt64 epoch) { if (!activeOnly) { return list.size(); } else { return list.stream().filter(v -> is_active_validator(v, epoch)).count(); } } @VisibleForTesting  BeaconValidators(tech.pegasys.teku.datastructures.state.BeaconState state); @VisibleForTesting  BeaconValidators(); @VisibleForTesting  BeaconValidators(
      tech.pegasys.teku.datastructures.state.BeaconState state,
      final boolean activeOnly,
      final UInt64 epoch,
      final int pageSize,
      final int pageToken);  BeaconValidators(
      tech.pegasys.teku.datastructures.state.BeaconState state, List<BLSPubKey> filter);  BeaconValidators(
      final BeaconState state, final boolean activeOnly, final int pageSize, final int pageToken);   BeaconValidators(
      final List<Validator> list,
      final List<UInt64> balances,
      final boolean activeOnly,
      final UInt64 epoch,
      final int pageSize,
      final int pageToken); static BeaconValidators emptySet(); static long getEffectiveListSize(List<Validator> list, boolean activeOnly, UInt64 epoch); static final int PAGE_SIZE_DEFAULT; static final int PAGE_TOKEN_DEFAULT; final List<ValidatorWithIndex> validators; final Long total_size; final Integer next_page_token; }