Skip to content

Commit

Permalink
Change blindedBlockCreatorCache keys from slot to slotAndBlockRoot. (#…
Browse files Browse the repository at this point in the history
…8780)

Co-authored-by: Stefan Bratanov <stefan.bratanov93@gmail.com>
  • Loading branch information
david-ry4n and StefanBratanov authored Nov 4, 2024
1 parent 2db844c commit 8bcbfc9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,30 @@ public SafeFuture<Optional<GenesisData>> getGenesisData() {

@Override
public SafeFuture<Map<BLSPublicKey, Integer>> getValidatorIndices(
Collection<BLSPublicKey> publicKeys) {
final Collection<BLSPublicKey> publicKeys) {
return SafeFuture.completedFuture(Map.of());
}

@Override
public SafeFuture<Optional<Map<BLSPublicKey, ValidatorStatus>>> getValidatorStatuses(
Collection<BLSPublicKey> validatorIdentifiers) {
final Collection<BLSPublicKey> validatorIdentifiers) {
return SafeFuture.completedFuture(Optional.empty());
}

@Override
public SafeFuture<Optional<AttesterDuties>> getAttestationDuties(
UInt64 epoch, IntCollection validatorIndices) {
final UInt64 epoch, final IntCollection validatorIndices) {
return SafeFuture.completedFuture(Optional.empty());
}

@Override
public SafeFuture<Optional<SyncCommitteeDuties>> getSyncCommitteeDuties(
UInt64 epoch, IntCollection validatorIndices) {
final UInt64 epoch, final IntCollection validatorIndices) {
return SafeFuture.completedFuture(Optional.empty());
}

@Override
public SafeFuture<Optional<ProposerDuties>> getProposerDuties(UInt64 epoch) {
public SafeFuture<Optional<ProposerDuties>> getProposerDuties(final UInt64 epoch) {
return SafeFuture.completedFuture(Optional.empty());
}

Expand All @@ -93,95 +93,97 @@ public SafeFuture<Optional<PeerCount>> getPeerCount() {

@Override
public SafeFuture<Optional<BlockContainerAndMetaData>> createUnsignedBlock(
UInt64 slot,
BLSSignature randaoReveal,
Optional<Bytes32> graffiti,
Optional<UInt64> requestedBuilderBoostFactor) {
final UInt64 slot,
final BLSSignature randaoReveal,
final Optional<Bytes32> graffiti,
final Optional<UInt64> requestedBuilderBoostFactor) {
return SafeFuture.completedFuture(Optional.empty());
}

@Override
public SafeFuture<Optional<AttestationData>> createAttestationData(
UInt64 slot, int committeeIndex) {
final UInt64 slot, final int committeeIndex) {
return SafeFuture.completedFuture(Optional.empty());
}

@Override
public SafeFuture<Optional<Attestation>> createAggregate(
UInt64 slot, Bytes32 attestationHashTreeRoot, Optional<UInt64> committeeIndex) {
final UInt64 slot,
final Bytes32 attestationHashTreeRoot,
final Optional<UInt64> committeeIndex) {
return SafeFuture.completedFuture(Optional.empty());
}

@Override
public SafeFuture<Optional<SyncCommitteeContribution>> createSyncCommitteeContribution(
UInt64 slot, int subcommitteeIndex, Bytes32 beaconBlockRoot) {
final UInt64 slot, final int subcommitteeIndex, final Bytes32 beaconBlockRoot) {
return SafeFuture.completedFuture(Optional.empty());
}

@Override
public SafeFuture<Void> subscribeToBeaconCommittee(
List<CommitteeSubscriptionRequest> requests) {
final List<CommitteeSubscriptionRequest> requests) {
return SafeFuture.COMPLETE;
}

@Override
public SafeFuture<Void> subscribeToSyncCommitteeSubnets(
Collection<SyncCommitteeSubnetSubscription> subscriptions) {
final Collection<SyncCommitteeSubnetSubscription> subscriptions) {
return SafeFuture.COMPLETE;
}

@Override
public SafeFuture<Void> subscribeToPersistentSubnets(
Set<SubnetSubscription> subnetSubscriptions) {
final Set<SubnetSubscription> subnetSubscriptions) {
return SafeFuture.COMPLETE;
}

@Override
public SafeFuture<List<SubmitDataError>> sendSignedAttestations(
List<Attestation> attestations) {
final List<Attestation> attestations) {
return SafeFuture.completedFuture(List.of());
}

@Override
public SafeFuture<List<SubmitDataError>> sendAggregateAndProofs(
List<SignedAggregateAndProof> aggregateAndProofs) {
final List<SignedAggregateAndProof> aggregateAndProofs) {
return SafeFuture.completedFuture(List.of());
}

@Override
public SafeFuture<SendSignedBlockResult> sendSignedBlock(
SignedBlockContainer blockContainer,
BroadcastValidationLevel broadcastValidationLevel) {
final SignedBlockContainer blockContainer,
final BroadcastValidationLevel broadcastValidationLevel) {
return SafeFuture.completedFuture(SendSignedBlockResult.rejected("NO OP Implementation"));
}

@Override
public SafeFuture<List<SubmitDataError>> sendSyncCommitteeMessages(
List<SyncCommitteeMessage> syncCommitteeMessages) {
final List<SyncCommitteeMessage> syncCommitteeMessages) {
return SafeFuture.completedFuture(List.of());
}

@Override
public SafeFuture<Void> sendSignedContributionAndProofs(
Collection<SignedContributionAndProof> signedContributionAndProofs) {
final Collection<SignedContributionAndProof> signedContributionAndProofs) {
return SafeFuture.COMPLETE;
}

@Override
public SafeFuture<Void> prepareBeaconProposer(
Collection<BeaconPreparableProposer> beaconPreparableProposers) {
final Collection<BeaconPreparableProposer> beaconPreparableProposers) {
return SafeFuture.COMPLETE;
}

@Override
public SafeFuture<Void> registerValidators(
SszList<SignedValidatorRegistration> validatorRegistrations) {
final SszList<SignedValidatorRegistration> validatorRegistrations) {
return SafeFuture.COMPLETE;
}

@Override
public SafeFuture<Optional<List<ValidatorLivenessAtEpoch>>> getValidatorsLiveness(
List<UInt64> validatorIndices, UInt64 epoch) {
final List<UInt64> validatorIndices, final UInt64 epoch) {
return SafeFuture.completedFuture(Optional.empty());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<UInt64, ValidatorApiChannel> blindedBlockCreatorCache =
private final Map<SlotAndBlockRoot, ValidatorApiChannel> blindedBlockCreatorCache =
LimitedMap.createSynchronizedLRU(2);

private final BeaconNodeReadinessManager beaconNodeReadinessManager;
Expand Down Expand Up @@ -172,7 +173,13 @@ public SafeFuture<Optional<BlockContainerAndMetaData>> 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);
Expand Down Expand Up @@ -254,12 +261,14 @@ public SafeFuture<List<SubmitDataError>> sendAggregateAndProofs(
public SafeFuture<SendSignedBlockResult> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SendSignedBlockResult> publishingRequest =
apiChannel ->
Expand Down

0 comments on commit 8bcbfc9

Please sign in to comment.