From 3aa904f40aceeab88fc1b0eb2198dad4ac123146 Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Wed, 23 Oct 2024 23:13:23 +0800 Subject: [PATCH] changes --- .../coordinator/ValidatorApiHandler.java | 22 +++++++++++++------ .../datastructures/blocks/BlockContainer.java | 5 +++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/ValidatorApiHandler.java b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/ValidatorApiHandler.java index 508853584b0..be01345ba91 100644 --- a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/ValidatorApiHandler.java +++ b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/ValidatorApiHandler.java @@ -666,15 +666,15 @@ private SafeFuture processAggregateAndProof( public SafeFuture sendSignedBlock( final SignedBlockContainer maybeBlindedBlockContainer, final BroadcastValidationLevel broadcastValidationLevel) { - final UInt64 slot = maybeBlindedBlockContainer.getSlot(); final BlockPublishingPerformance blockPublishingPerformance = - blockProductionAndPublishingPerformanceFactory.createForPublishing(slot); + blockProductionAndPublishingPerformanceFactory.createForPublishing( + maybeBlindedBlockContainer.getSlot()); return blockPublisher .sendSignedBlock( maybeBlindedBlockContainer, // do only EQUIVOCATION validation when GOSSIP validation has been requested and the // block has been locally created - broadcastValidationLevel == GOSSIP && isLocallyCreatedBlock(slot) + broadcastValidationLevel == GOSSIP && isLocallyCreatedBlock(maybeBlindedBlockContainer) ? EQUIVOCATION : broadcastValidationLevel, blockPublishingPerformance) @@ -883,13 +883,21 @@ private List getProposalSlotsForEpoch(final BeaconState state, fin return proposerSlots; } - private boolean isLocallyCreatedBlock(final UInt64 slot) { + private boolean isLocallyCreatedBlock(final SignedBlockContainer signedBlockContainer) { final SafeFuture> localBlockProduction = - localBlockProductionBySlotCache.get(slot); - if (localBlockProduction == null) { + localBlockProductionBySlotCache.get(signedBlockContainer.getSlot()); + if (localBlockProduction == null || !localBlockProduction.isCompletedNormally()) { return false; } - return localBlockProduction.isCompletedNormally(); + return localBlockProduction + .join() + .map( + blockContainerAndMetaData -> + blockContainerAndMetaData + .blockContainer() + .getRoot() + .equals(signedBlockContainer.getRoot())) + .orElse(false); } @Override diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/BlockContainer.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/BlockContainer.java index 8a7e6c7f798..f2134b996be 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/BlockContainer.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/BlockContainer.java @@ -14,6 +14,7 @@ package tech.pegasys.teku.spec.datastructures.blocks; import java.util.Optional; +import org.apache.tuweni.bytes.Bytes32; import tech.pegasys.teku.infrastructure.ssz.SszContainer; import tech.pegasys.teku.infrastructure.ssz.SszData; import tech.pegasys.teku.infrastructure.ssz.SszList; @@ -35,6 +36,10 @@ default UInt64 getSlot() { return getBlock().getSlot(); } + default Bytes32 getRoot() { + return getBlock().getRoot(); + } + default Optional> getKzgProofs() { return Optional.empty(); }