@Test public void getValidatorIndex_shouldNotCacheValidatorMissing() { final BeaconState state = dataStructureUtil.randomBeaconState(); final Validator validator = dataStructureUtil.randomValidator(); assertThat(ValidatorsUtil.getValidatorIndex(state, validator.getPubkey())).isEmpty(); final BeaconState nextState = state.updated(s -> s.getValidators().add(validator)); assertThat(ValidatorsUtil.getValidatorIndex(nextState, validator.getPubkey())) .contains(nextState.getValidators().size() - 1); }
@SuppressWarnings("DoNotReturnNullOptionals") public static Optional<Integer> getValidatorIndex(BeaconState state, BLSPublicKey publicKey) { final Integer validatorIndex = BeaconStateCache.getTransitionCaches(state) .getValidatorIndex() .get( publicKey, key -> { SSZList<Validator> validators = state.getValidators(); for (int i = 0; i < validators.size(); i++) { final Validator validator = validators.get(i); if (validator.getPubkey().equals(publicKey)) { return i; } } return null; }); return Optional.ofNullable(validatorIndex) .filter(index -> index < state.getValidators().size()); }
ValidatorsUtil { @SuppressWarnings("DoNotReturnNullOptionals") public static Optional<Integer> getValidatorIndex(BeaconState state, BLSPublicKey publicKey) { final Integer validatorIndex = BeaconStateCache.getTransitionCaches(state) .getValidatorIndex() .get( publicKey, key -> { SSZList<Validator> validators = state.getValidators(); for (int i = 0; i < validators.size(); i++) { final Validator validator = validators.get(i); if (validator.getPubkey().equals(publicKey)) { return i; } } return null; }); return Optional.ofNullable(validatorIndex) .filter(index -> index < state.getValidators().size()); } }
ValidatorsUtil { @SuppressWarnings("DoNotReturnNullOptionals") public static Optional<Integer> getValidatorIndex(BeaconState state, BLSPublicKey publicKey) { final Integer validatorIndex = BeaconStateCache.getTransitionCaches(state) .getValidatorIndex() .get( publicKey, key -> { SSZList<Validator> validators = state.getValidators(); for (int i = 0; i < validators.size(); i++) { final Validator validator = validators.get(i); if (validator.getPubkey().equals(publicKey)) { return i; } } return null; }); return Optional.ofNullable(validatorIndex) .filter(index -> index < state.getValidators().size()); }  }
ValidatorsUtil { @SuppressWarnings("DoNotReturnNullOptionals") public static Optional<Integer> getValidatorIndex(BeaconState state, BLSPublicKey publicKey) { final Integer validatorIndex = BeaconStateCache.getTransitionCaches(state) .getValidatorIndex() .get( publicKey, key -> { SSZList<Validator> validators = state.getValidators(); for (int i = 0; i < validators.size(); i++) { final Validator validator = validators.get(i); if (validator.getPubkey().equals(publicKey)) { return i; } } return null; }); return Optional.ofNullable(validatorIndex) .filter(index -> index < state.getValidators().size()); }  static boolean is_active_validator(Validator validator, UInt64 epoch); static boolean is_eligible_for_activation_queue(Validator validator); static boolean is_eligible_for_activation(BeaconState state, Validator validator); static Optional<BLSPublicKey> getValidatorPubKey(
      BeaconState state, UInt64 validatorIndex); static List<Integer> get_active_validator_indices(BeaconState state, UInt64 epoch); @SuppressWarnings("DoNotReturnNullOptionals") static Optional<Integer> getValidatorIndex(BeaconState state, BLSPublicKey publicKey); static void decrease_balance(MutableBeaconState state, int index, UInt64 delta); static void increase_balance(MutableBeaconState state, int index, UInt64 delta); static boolean is_slashable_validator(Validator validator, UInt64 epoch); }
ValidatorsUtil { @SuppressWarnings("DoNotReturnNullOptionals") public static Optional<Integer> getValidatorIndex(BeaconState state, BLSPublicKey publicKey) { final Integer validatorIndex = BeaconStateCache.getTransitionCaches(state) .getValidatorIndex() .get( publicKey, key -> { SSZList<Validator> validators = state.getValidators(); for (int i = 0; i < validators.size(); i++) { final Validator validator = validators.get(i); if (validator.getPubkey().equals(publicKey)) { return i; } } return null; }); return Optional.ofNullable(validatorIndex) .filter(index -> index < state.getValidators().size()); }  static boolean is_active_validator(Validator validator, UInt64 epoch); static boolean is_eligible_for_activation_queue(Validator validator); static boolean is_eligible_for_activation(BeaconState state, Validator validator); static Optional<BLSPublicKey> getValidatorPubKey(
      BeaconState state, UInt64 validatorIndex); static List<Integer> get_active_validator_indices(BeaconState state, UInt64 epoch); @SuppressWarnings("DoNotReturnNullOptionals") static Optional<Integer> getValidatorIndex(BeaconState state, BLSPublicKey publicKey); static void decrease_balance(MutableBeaconState state, int index, UInt64 delta); static void increase_balance(MutableBeaconState state, int index, UInt64 delta); static boolean is_slashable_validator(Validator validator, UInt64 epoch);  }