diff --git a/validator/api/src/main/java/tech/pegasys/teku/validator/api/ValidatorApiChannel.java b/validator/api/src/main/java/tech/pegasys/teku/validator/api/ValidatorApiChannel.java index 8a4d36f00b2..680153a8ed4 100644 --- a/validator/api/src/main/java/tech/pegasys/teku/validator/api/ValidatorApiChannel.java +++ b/validator/api/src/main/java/tech/pegasys/teku/validator/api/ValidatorApiChannel.java @@ -59,30 +59,30 @@ public SafeFuture> getGenesisData() { @Override public SafeFuture> getValidatorIndices( - Collection publicKeys) { + final Collection publicKeys) { return SafeFuture.completedFuture(Map.of()); } @Override public SafeFuture>> getValidatorStatuses( - Collection validatorIdentifiers) { + final Collection validatorIdentifiers) { return SafeFuture.completedFuture(Optional.empty()); } @Override public SafeFuture> getAttestationDuties( - UInt64 epoch, IntCollection validatorIndices) { + final UInt64 epoch, final IntCollection validatorIndices) { return SafeFuture.completedFuture(Optional.empty()); } @Override public SafeFuture> getSyncCommitteeDuties( - UInt64 epoch, IntCollection validatorIndices) { + final UInt64 epoch, final IntCollection validatorIndices) { return SafeFuture.completedFuture(Optional.empty()); } @Override - public SafeFuture> getProposerDuties(UInt64 epoch) { + public SafeFuture> getProposerDuties(final UInt64 epoch) { return SafeFuture.completedFuture(Optional.empty()); } @@ -93,95 +93,97 @@ public SafeFuture> getPeerCount() { @Override public SafeFuture> createUnsignedBlock( - UInt64 slot, - BLSSignature randaoReveal, - Optional graffiti, - Optional requestedBuilderBoostFactor) { + final UInt64 slot, + final BLSSignature randaoReveal, + final Optional graffiti, + final Optional requestedBuilderBoostFactor) { return SafeFuture.completedFuture(Optional.empty()); } @Override public SafeFuture> createAttestationData( - UInt64 slot, int committeeIndex) { + final UInt64 slot, final int committeeIndex) { return SafeFuture.completedFuture(Optional.empty()); } @Override public SafeFuture> createAggregate( - UInt64 slot, Bytes32 attestationHashTreeRoot, Optional committeeIndex) { + final UInt64 slot, + final Bytes32 attestationHashTreeRoot, + final Optional committeeIndex) { return SafeFuture.completedFuture(Optional.empty()); } @Override public SafeFuture> createSyncCommitteeContribution( - UInt64 slot, int subcommitteeIndex, Bytes32 beaconBlockRoot) { + final UInt64 slot, final int subcommitteeIndex, final Bytes32 beaconBlockRoot) { return SafeFuture.completedFuture(Optional.empty()); } @Override public SafeFuture subscribeToBeaconCommittee( - List requests) { + final List requests) { return SafeFuture.COMPLETE; } @Override public SafeFuture subscribeToSyncCommitteeSubnets( - Collection subscriptions) { + final Collection subscriptions) { return SafeFuture.COMPLETE; } @Override public SafeFuture subscribeToPersistentSubnets( - Set subnetSubscriptions) { + final Set subnetSubscriptions) { return SafeFuture.COMPLETE; } @Override public SafeFuture> sendSignedAttestations( - List attestations) { + final List attestations) { return SafeFuture.completedFuture(List.of()); } @Override public SafeFuture> sendAggregateAndProofs( - List aggregateAndProofs) { + final List aggregateAndProofs) { return SafeFuture.completedFuture(List.of()); } @Override public SafeFuture sendSignedBlock( - SignedBlockContainer blockContainer, - BroadcastValidationLevel broadcastValidationLevel) { + final SignedBlockContainer blockContainer, + final BroadcastValidationLevel broadcastValidationLevel) { return SafeFuture.completedFuture(SendSignedBlockResult.rejected("NO OP Implementation")); } @Override public SafeFuture> sendSyncCommitteeMessages( - List syncCommitteeMessages) { + final List syncCommitteeMessages) { return SafeFuture.completedFuture(List.of()); } @Override public SafeFuture sendSignedContributionAndProofs( - Collection signedContributionAndProofs) { + final Collection signedContributionAndProofs) { return SafeFuture.COMPLETE; } @Override public SafeFuture prepareBeaconProposer( - Collection beaconPreparableProposers) { + final Collection beaconPreparableProposers) { return SafeFuture.COMPLETE; } @Override public SafeFuture registerValidators( - SszList validatorRegistrations) { + final SszList validatorRegistrations) { return SafeFuture.COMPLETE; } @Override public SafeFuture>> getValidatorsLiveness( - List validatorIndices, UInt64 epoch) { + final List validatorIndices, final UInt64 epoch) { return SafeFuture.completedFuture(Optional.empty()); } diff --git a/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/FailoverValidatorApiHandler.java b/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/FailoverValidatorApiHandler.java index a9ca5453bcc..5a91550b170 100644 --- a/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/FailoverValidatorApiHandler.java +++ b/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/FailoverValidatorApiHandler.java @@ -47,6 +47,7 @@ import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.datastructures.blocks.BlockContainer; import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer; +import tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot; import tech.pegasys.teku.spec.datastructures.builder.SignedValidatorRegistration; import tech.pegasys.teku.spec.datastructures.genesis.GenesisData; import tech.pegasys.teku.spec.datastructures.metadata.BlockContainerAndMetaData; @@ -72,7 +73,7 @@ public class FailoverValidatorApiHandler implements ValidatorApiChannel { static final String REMOTE_BEACON_NODES_REQUESTS_COUNTER_NAME = "remote_beacon_nodes_requests_total"; - private final Map blindedBlockCreatorCache = + private final Map blindedBlockCreatorCache = LimitedMap.createSynchronizedLRU(2); private final BeaconNodeReadinessManager beaconNodeReadinessManager; @@ -172,7 +173,13 @@ public SafeFuture> createUnsignedBlock( .map(BlockContainerAndMetaData::blockContainer) .map(BlockContainer::isBlinded) .orElse(false)) { - blindedBlockCreatorCache.put(slot, apiChannel); + final SlotAndBlockRoot slotAndBlockRoot = + blockContainerAndMetaData + .orElseThrow() + .blockContainer() + .getBlock() + .getSlotAndBlockRoot(); + blindedBlockCreatorCache.put(slotAndBlockRoot, apiChannel); } }); return tryRequestUntilSuccess(request, BeaconNodeRequestLabels.CREATE_UNSIGNED_BLOCK_METHOD); @@ -254,12 +261,14 @@ public SafeFuture> sendAggregateAndProofs( public SafeFuture sendSignedBlock( final SignedBlockContainer blockContainer, final BroadcastValidationLevel broadcastValidationLevel) { - final UInt64 slot = blockContainer.getSlot(); - if (blockContainer.isBlinded() && blindedBlockCreatorCache.containsKey(slot)) { - final ValidatorApiChannel blockCreatorApiChannel = blindedBlockCreatorCache.remove(slot); + final SlotAndBlockRoot slotAndBlockRoot = blockContainer.getSignedBlock().getSlotAndBlockRoot(); + if (blockContainer.isBlinded() && blindedBlockCreatorCache.containsKey(slotAndBlockRoot)) { + final ValidatorApiChannel blockCreatorApiChannel = + blindedBlockCreatorCache.remove(slotAndBlockRoot); LOG.info( - "Block for slot {} was blinded and will only be sent to the beacon node which created it.", - slot); + "Block for slot {} and root {} was blinded and will only be sent to the beacon node which created it.", + slotAndBlockRoot.getSlot(), + slotAndBlockRoot.getBlockRoot().toHexString()); return blockCreatorApiChannel.sendSignedBlock(blockContainer, broadcastValidationLevel); } return relayRequest( diff --git a/validator/remote/src/test/java/tech/pegasys/teku/validator/remote/FailoverValidatorApiHandlerTest.java b/validator/remote/src/test/java/tech/pegasys/teku/validator/remote/FailoverValidatorApiHandlerTest.java index 0ace2806300..1ace735c94d 100644 --- a/validator/remote/src/test/java/tech/pegasys/teku/validator/remote/FailoverValidatorApiHandlerTest.java +++ b/validator/remote/src/test/java/tech/pegasys/teku/validator/remote/FailoverValidatorApiHandlerTest.java @@ -592,7 +592,7 @@ public void publishesBlindedBlockOnlyToTheBeaconNodeWhichCreatedIt() { SafeFutureAssert.assertThatSafeFuture(creationRequest.run(failoverApiHandler)).isCompleted(); final SignedBeaconBlock blindedSignedBlock = - DATA_STRUCTURE_UTIL.randomSignedBlindedBeaconBlock(UInt64.ONE); + DATA_STRUCTURE_UTIL.signedBlock(blindedBlock.blockContainer().getBlock()); final ValidatorApiChannelRequest publishingRequest = apiChannel ->