Skip to content

Commit

Permalink
Report when validator indices are unavailable because the best state …
Browse files Browse the repository at this point in the history
…is not set (#3310)
  • Loading branch information
ajsutton committed Nov 25, 2020
1 parent 6442aac commit 2fdb4c2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

package tech.pegasys.teku.validator.coordinator;

import static java.util.Collections.emptyMap;
import static java.util.stream.Collectors.toList;
import static tech.pegasys.teku.datastructures.util.BeaconStateUtil.compute_epoch_at_slot;
import static tech.pegasys.teku.datastructures.util.BeaconStateUtil.compute_start_slot_at_epoch;
Expand Down Expand Up @@ -147,19 +146,20 @@ public SafeFuture<Optional<GenesisData>> getGenesisData() {
@Override
public SafeFuture<Map<BLSPublicKey, Integer>> getValidatorIndices(
final List<BLSPublicKey> publicKeys) {
return SafeFuture.completedFuture(
combinedChainDataClient
.getBestState()
.map(
state -> {
final Map<BLSPublicKey, Integer> results = new HashMap<>();
publicKeys.forEach(
publicKey ->
ValidatorsUtil.getValidatorIndex(state, publicKey)
.ifPresent(index -> results.put(publicKey, index)));
return results;
})
.orElse(emptyMap()));
return SafeFuture.of(
() ->
combinedChainDataClient
.getBestState()
.map(
state -> {
final Map<BLSPublicKey, Integer> results = new HashMap<>();
publicKeys.forEach(
publicKey ->
ValidatorsUtil.getValidatorIndex(state, publicKey)
.ifPresent(index -> results.put(publicKey, index)));
return results;
})
.orElseThrow(() -> new IllegalStateException("Head state is not yet available")));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package tech.pegasys.teku.validator.coordinator;

import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -526,12 +525,14 @@ public void sendAggregateAndProof_shouldPostAggregateAndProof() {
}

@Test
void getValidatorIndices_shouldReturnEmptyMapWhenBestStateNotAvailable() {
void getValidatorIndices_shouldThrowExceptionWhenBestStateNotAvailable() {
when(chainDataClient.getBestState()).thenReturn(Optional.empty());

// The validator client needs to be able to differentiate between the state not yet being loaded
// and the requested validators not existing so it doesn't skip scheduling duties.
assertThatSafeFuture(
validatorApiHandler.getValidatorIndices(List.of(dataStructureUtil.randomPublicKey())))
.isCompletedWithValue(emptyMap());
.isCompletedExceptionallyWith(IllegalStateException.class);
}

@Test
Expand Down

0 comments on commit 2fdb4c2

Please sign in to comment.