Skip to content

Commit

Permalink
rely on internal ownedValidator to calculate validator indices
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr committed Feb 1, 2022
1 parent 29db0c0 commit 6194e5a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ public void onSlot(UInt64 slot) {

private List<BeaconPreparableProposer> buildBeaconPreparableProposerList(
Optional<ProposerConfig> maybeProposerConfig,
Map<BLSPublicKey, Integer> blsPublicKeyIntegerMap) {
return blsPublicKeyIntegerMap.entrySet().stream()
Map<BLSPublicKey, Optional<Integer>> 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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,12 @@ public SafeFuture<Collection<Integer>> getValidatorIndices() {
.collect(toList()));
}

public SafeFuture<Map<BLSPublicKey, Integer>> getValidatorIndexesByPublicKey() {
public SafeFuture<Map<BLSPublicKey, Optional<Integer>>> 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.<BLSPublicKey, BLSPublicKey, Integer>toMap(
Function.identity(), validatorIndexesByPublicKey::get)));
.collect(Collectors.toMap(Function.identity(), this::getValidatorIndex)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<BLSPublicKey, Integer> validatorIndexesByPublicKey =
Map<BLSPublicKey, Optional<Integer>> 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();
Expand Down

0 comments on commit 6194e5a

Please sign in to comment.