diff --git a/validator/client/src/main/java/tech/pegasys/teku/validator/client/BeaconProposerPreparer.java b/validator/client/src/main/java/tech/pegasys/teku/validator/client/BeaconProposerPreparer.java index 0802fe3e329..94b0bfb91de 100644 --- a/validator/client/src/main/java/tech/pegasys/teku/validator/client/BeaconProposerPreparer.java +++ b/validator/client/src/main/java/tech/pegasys/teku/validator/client/BeaconProposerPreparer.java @@ -87,12 +87,13 @@ public void onSlot(UInt64 slot) { private List buildBeaconPreparableProposerList( Optional maybeProposerConfig, - Map blsPublicKeyIntegerMap) { - return blsPublicKeyIntegerMap.entrySet().stream() + Map> blsPublicKeyToIndexMap) { + return blsPublicKeyToIndexMap.entrySet().stream() + .filter(blsPublicKeyOptionalEntry -> blsPublicKeyOptionalEntry.getValue().isPresent()) .map( blsPublicKeyIntegerEntry -> new BeaconPreparableProposer( - UInt64.valueOf(blsPublicKeyIntegerEntry.getValue()), + UInt64.valueOf(blsPublicKeyIntegerEntry.getValue().get()), getFeeRecipient(maybeProposerConfig, blsPublicKeyIntegerEntry.getKey()))) .collect(Collectors.toList()); } diff --git a/validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorIndexProvider.java b/validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorIndexProvider.java index 0b8779f2db2..0c19990fe4f 100644 --- a/validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorIndexProvider.java +++ b/validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorIndexProvider.java @@ -110,14 +110,12 @@ public SafeFuture> getValidatorIndices() { .collect(toList())); } - public SafeFuture> getValidatorIndexesByPublicKey() { + public SafeFuture>> getValidatorIndexesByPublicKey() { // Wait for at least one successful load of validator indices before attempting to read return firstSuccessfulRequest.thenApply( __ -> ownedValidators.getActiveValidators().stream() .map(Validator::getPublicKey) - .collect( - Collectors.toMap( - Function.identity(), validatorIndexesByPublicKey::get))); + .collect(Collectors.toMap(Function.identity(), this::getValidatorIndex))); } } diff --git a/validator/client/src/test/java/tech/pegasys/teku/validator/client/BeaconProposerPreparerTest.java b/validator/client/src/test/java/tech/pegasys/teku/validator/client/BeaconProposerPreparerTest.java index a387722cb9a..b9dad0e0cde 100644 --- a/validator/client/src/test/java/tech/pegasys/teku/validator/client/BeaconProposerPreparerTest.java +++ b/validator/client/src/test/java/tech/pegasys/teku/validator/client/BeaconProposerPreparerTest.java @@ -66,10 +66,20 @@ void setUp(SpecContext specContext) { specContext.getDataStructureUtil().randomPublicKey(), mock(Signer.class), Optional::empty); + Validator validatorWithoutIndex = + new Validator( + specContext.getDataStructureUtil().randomPublicKey(), + mock(Signer.class), + Optional::empty); - Map validatorIndexesByPublicKey = + Map> validatorIndexesByPublicKey = Map.of( - validator1.getPublicKey(), validator1Index, validator2.getPublicKey(), validator2Index); + validator1.getPublicKey(), + Optional.of(validator1Index), + validator2.getPublicKey(), + Optional.of(validator2Index), + validatorWithoutIndex.getPublicKey(), + Optional.empty()); defaultFeeRecipient = specContext.getDataStructureUtil().randomEth1Address(); defaultFeeRecipientConfig = specContext.getDataStructureUtil().randomEth1Address();