@Test void getValidatorsByValidatorsRequest_shouldIncludeValidators() throws ExecutionException, InterruptedException { final ChainDataProvider provider = new ChainDataProvider(recentChainData, mockCombinedChainDataClient); final tech.pegasys.teku.datastructures.state.BeaconState state = bestBlock.getState(); final SafeFuture<Optional<BeaconBlockAndState>> safeFuture = completedFuture(Optional.of(bestBlock.toUnsigned())); final ValidatorsRequest validatorsRequest = new ValidatorsRequest( compute_epoch_at_slot(beaconState.slot), List.of(beaconState.validators.get(0).pubkey, beaconState.validators.get(2).pubkey)); when(mockCombinedChainDataClient.isChainDataFullyAvailable()).thenReturn(true); when(mockCombinedChainDataClient.getBlockAndStateInEffectAtSlot(any())).thenReturn(safeFuture); final SafeFuture<Optional<BeaconValidators>> future = provider.getValidatorsByValidatorsRequest(validatorsRequest); final Optional<BeaconValidators> optionalValidators = future.get(); final BeaconValidators validators = optionalValidators.get(); assertThat(validators.validators.size()).isEqualTo(2); assertThat(validators.validators.get(0)) .usingRecursiveComparison() .isEqualTo(new ValidatorWithIndex(state.getValidators().get(0), state)); assertThat(validators.validators.get(1)) .usingRecursiveComparison() .isEqualTo(new ValidatorWithIndex(state.getValidators().get(2), state)); }
public SafeFuture<Optional<BeaconValidators>> getValidatorsByValidatorsRequest( final ValidatorsRequest request) { if (request.pubkeys.isEmpty()) { return SafeFuture.completedFuture(Optional.of(BeaconValidators.emptySet())); } if (!combinedChainDataClient.isChainDataFullyAvailable()) { return chainUnavailable(); } return SafeFuture.of( () -> { UInt64 slot = request.epoch == null ? combinedChainDataClient.getHeadSlot() : BeaconStateUtil.compute_start_slot_at_epoch(request.epoch); return combinedChainDataClient .getBlockAndStateInEffectAtSlot(slot) .thenApply( optionalState -> optionalState.map( state -> new BeaconValidators(state.getState(), request.pubkeys))); }); }
ChainDataProvider { public SafeFuture<Optional<BeaconValidators>> getValidatorsByValidatorsRequest( final ValidatorsRequest request) { if (request.pubkeys.isEmpty()) { return SafeFuture.completedFuture(Optional.of(BeaconValidators.emptySet())); } if (!combinedChainDataClient.isChainDataFullyAvailable()) { return chainUnavailable(); } return SafeFuture.of( () -> { UInt64 slot = request.epoch == null ? combinedChainDataClient.getHeadSlot() : BeaconStateUtil.compute_start_slot_at_epoch(request.epoch); return combinedChainDataClient .getBlockAndStateInEffectAtSlot(slot) .thenApply( optionalState -> optionalState.map( state -> new BeaconValidators(state.getState(), request.pubkeys))); }); } }
ChainDataProvider { public SafeFuture<Optional<BeaconValidators>> getValidatorsByValidatorsRequest( final ValidatorsRequest request) { if (request.pubkeys.isEmpty()) { return SafeFuture.completedFuture(Optional.of(BeaconValidators.emptySet())); } if (!combinedChainDataClient.isChainDataFullyAvailable()) { return chainUnavailable(); } return SafeFuture.of( () -> { UInt64 slot = request.epoch == null ? combinedChainDataClient.getHeadSlot() : BeaconStateUtil.compute_start_slot_at_epoch(request.epoch); return combinedChainDataClient .getBlockAndStateInEffectAtSlot(slot) .thenApply( optionalState -> optionalState.map( state -> new BeaconValidators(state.getState(), request.pubkeys))); }); } ChainDataProvider(
      final RecentChainData recentChainData,
      final CombinedChainDataClient combinedChainDataClient); }
ChainDataProvider { public SafeFuture<Optional<BeaconValidators>> getValidatorsByValidatorsRequest( final ValidatorsRequest request) { if (request.pubkeys.isEmpty()) { return SafeFuture.completedFuture(Optional.of(BeaconValidators.emptySet())); } if (!combinedChainDataClient.isChainDataFullyAvailable()) { return chainUnavailable(); } return SafeFuture.of( () -> { UInt64 slot = request.epoch == null ? combinedChainDataClient.getHeadSlot() : BeaconStateUtil.compute_start_slot_at_epoch(request.epoch); return combinedChainDataClient .getBlockAndStateInEffectAtSlot(slot) .thenApply( optionalState -> optionalState.map( state -> new BeaconValidators(state.getState(), request.pubkeys))); }); } ChainDataProvider(
      final RecentChainData recentChainData,
      final CombinedChainDataClient combinedChainDataClient); UInt64 getGenesisTime(); Optional<BeaconHead> getBeaconHead(); GetForkResponse getForkInfo(); SafeFuture<Optional<List<Committee>>> getCommitteesAtEpoch(final UInt64 epoch); SafeFuture<Optional<GetBlockResponse>> getBlockBySlot(final UInt64 slot); boolean isStoreAvailable(); Optional<Bytes32> getBestBlockRoot(); UInt64 getCurrentEpoch(); SafeFuture<Optional<GetBlockResponse>> getBlockByBlockRoot(final Bytes32 blockParam); SafeFuture<Optional<BeaconState>> getStateByBlockRoot(final Bytes32 blockRoot); SafeFuture<Optional<BeaconState>> getStateByStateRoot(final Bytes32 stateRoot); SafeFuture<Optional<BeaconState>> getStateAtSlot(final UInt64 slot); SafeFuture<Optional<Bytes32>> getStateRootAtSlot(final UInt64 slot); SafeFuture<Optional<BeaconValidators>> getValidatorsByValidatorsRequest(
      final ValidatorsRequest request); boolean isFinalized(final SignedBeaconBlock signedBeaconBlock); boolean isFinalized(final UInt64 slot); boolean isFinalizedEpoch(final UInt64 epoch); Optional<BeaconChainHead> getHeadState(); Optional<UInt64> stateParameterToSlot(final String pathParam); Optional<Integer> validatorParameterToIndex(final String validatorParameter); SafeFuture<Optional<Fork>> getForkAtSlot(final UInt64 slot); SafeFuture<Optional<ValidatorResponse>> getValidatorDetails(
      final Optional<UInt64> maybeSlot, final Optional<Integer> maybeIndex); Optional<Bytes32> getStateRootFromBlockRoot(final Bytes32 blockRoot); }
ChainDataProvider { public SafeFuture<Optional<BeaconValidators>> getValidatorsByValidatorsRequest( final ValidatorsRequest request) { if (request.pubkeys.isEmpty()) { return SafeFuture.completedFuture(Optional.of(BeaconValidators.emptySet())); } if (!combinedChainDataClient.isChainDataFullyAvailable()) { return chainUnavailable(); } return SafeFuture.of( () -> { UInt64 slot = request.epoch == null ? combinedChainDataClient.getHeadSlot() : BeaconStateUtil.compute_start_slot_at_epoch(request.epoch); return combinedChainDataClient .getBlockAndStateInEffectAtSlot(slot) .thenApply( optionalState -> optionalState.map( state -> new BeaconValidators(state.getState(), request.pubkeys))); }); } ChainDataProvider(
      final RecentChainData recentChainData,
      final CombinedChainDataClient combinedChainDataClient); UInt64 getGenesisTime(); Optional<BeaconHead> getBeaconHead(); GetForkResponse getForkInfo(); SafeFuture<Optional<List<Committee>>> getCommitteesAtEpoch(final UInt64 epoch); SafeFuture<Optional<GetBlockResponse>> getBlockBySlot(final UInt64 slot); boolean isStoreAvailable(); Optional<Bytes32> getBestBlockRoot(); UInt64 getCurrentEpoch(); SafeFuture<Optional<GetBlockResponse>> getBlockByBlockRoot(final Bytes32 blockParam); SafeFuture<Optional<BeaconState>> getStateByBlockRoot(final Bytes32 blockRoot); SafeFuture<Optional<BeaconState>> getStateByStateRoot(final Bytes32 stateRoot); SafeFuture<Optional<BeaconState>> getStateAtSlot(final UInt64 slot); SafeFuture<Optional<Bytes32>> getStateRootAtSlot(final UInt64 slot); SafeFuture<Optional<BeaconValidators>> getValidatorsByValidatorsRequest(
      final ValidatorsRequest request); boolean isFinalized(final SignedBeaconBlock signedBeaconBlock); boolean isFinalized(final UInt64 slot); boolean isFinalizedEpoch(final UInt64 epoch); Optional<BeaconChainHead> getHeadState(); Optional<UInt64> stateParameterToSlot(final String pathParam); Optional<Integer> validatorParameterToIndex(final String validatorParameter); SafeFuture<Optional<Fork>> getForkAtSlot(final UInt64 slot); SafeFuture<Optional<ValidatorResponse>> getValidatorDetails(
      final Optional<UInt64> maybeSlot, final Optional<Integer> maybeIndex); Optional<Bytes32> getStateRootFromBlockRoot(final Bytes32 blockRoot);  }