Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ void sendSignedBlock_shouldImportAndPublishBlock(final SpecContext specContext)

when(blockImportChannel.importBlock(block, NOT_REQUIRED))
.thenReturn(prepareBlockImportResult(BlockImportResult.successful(block)));
final SafeFuture<SendSignedBlockResult> result = handler.sendSignedBlock(block, NOT_REQUIRED);
final SafeFuture<SendSignedBlockResult> result =
handler.sendSignedBlock(block, NOT_REQUIRED, Optional.empty());
assertThat(result).isCompletedWithValue(SendSignedBlockResult.success(block.getRoot()));

if (specContext.getSpecMilestone() == SpecMilestone.DENEB) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer;
import tech.pegasys.teku.spec.datastructures.execution.BlobsBundle;
import tech.pegasys.teku.spec.datastructures.metadata.BlockContainerAndMetaData;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb;

public class BlockFactoryDeneb extends BlockFactoryPhase0 {
Expand All @@ -34,15 +35,21 @@ public BlockFactoryDeneb(final Spec spec, final BlockOperationSelectorFactory op
@Override
public SafeFuture<BlockContainerAndMetaData> createUnsignedBlock(
final BlockProductionContext blockProductionContext) {
return super.createUnsignedBlock(blockProductionContext)
return createNewUnsignedBlock(blockProductionContext)
.thenCompose(
blockContainerAndMetaData -> {
final BeaconBlock block = blockContainerAndMetaData.blockContainer().getBlock();
blockAndState -> {
final BeaconBlock block = blockAndState.getBlock();
final BeaconState state = blockAndState.getState();
if (block.isBlinded()) {
return SafeFuture.completedFuture(blockContainerAndMetaData);
return SafeFuture.completedFuture(
createBlockContainerAndMetaDataBuilder(state).blockContainer(block).build());
}
return createBlockContents(block)
.thenApply(blockContainerAndMetaData::withBlockContents);
.thenApply(
blockContents ->
createBlockContainerAndMetaDataBuilder(state)
.blockContainer(blockContents)
.build());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package tech.pegasys.teku.validator.coordinator;

import static tech.pegasys.teku.spec.constants.EthConstants.GWEI_TO_WEI;

import com.google.common.base.Preconditions;
import java.util.Optional;
import tech.pegasys.teku.ethereum.performance.trackers.BlockPublishingPerformance;
Expand All @@ -28,6 +30,9 @@
import tech.pegasys.teku.spec.datastructures.epbs.versions.gloas.SignedExecutionPayloadBid;
import tech.pegasys.teku.spec.datastructures.execution.BlobsBundle;
import tech.pegasys.teku.spec.datastructures.metadata.BlockContainerAndMetaData;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateCache;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.common.SlotCaches;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsGloas;

// Gloas is more similar to BlockFactoryPhase0 than BlockFactoryFulu
Expand All @@ -50,17 +55,22 @@ public BlockFactoryGloas(final Spec spec, final BlockOperationSelectorFactory op
@Override
public SafeFuture<BlockContainerAndMetaData> createUnsignedBlock(
final BlockProductionContext blockProductionContext) {
return super.createUnsignedBlock(blockProductionContext)
return createNewUnsignedBlock(blockProductionContext)
.thenCompose(
blockContainerAndMetaData -> {
final BeaconBlock block = (BeaconBlock) blockContainerAndMetaData.blockContainer();
blockAndState -> {
final BeaconBlock block = blockAndState.getBlock();
final BeaconState state = blockAndState.getState();
final SignedExecutionPayloadBid bid =
BeaconBlockBodyGloas.required(block.getBody()).getSignedExecutionPayloadBid();
// G2-point-at-infinity signature means we self-built the payload
final boolean selfBuilt = bid.getSignature().isInfinity();
// include_payload=false or builder bid → return beacon block only
if (!blockProductionContext.includePayload() || !selfBuilt) {
return SafeFuture.completedFuture(blockContainerAndMetaData);
return SafeFuture.completedFuture(
createBlockContainerAndMetaDataBuilder(state)
.blockContainer(block)
.payloadIncluded(false)
.build());
}
// include_payload=true and self-built → include full contents
final UInt64 slot = block.getSlot();
Expand Down Expand Up @@ -91,11 +101,25 @@ public SafeFuture<BlockContainerAndMetaData> createUnsignedBlock(
blobsBundle.getProofs(),
blobsBundle.getBlobs(),
Optional.of(envelope));
return blockContainerAndMetaData.withBlockContents(blockContents);
return createBlockContainerAndMetaDataBuilder(state)
.blockContainer(blockContents)
.payloadIncluded(true)
.build();
});
});
}

@Override
protected BlockContainerAndMetaData.Builder createBlockContainerAndMetaDataBuilder(
final BeaconState state) {
final SlotCaches slotCaches = BeaconStateCache.getSlotCaches(state);
return BlockContainerAndMetaData.builder()
.milestone(spec.atSlot(state.getSlot()).getMilestone())
.executionPayloadValue(slotCaches.getBlockExecutionValue())
.consensusBlockValue(GWEI_TO_WEI.multiply(slotCaches.getBlockProposerRewards().longValue()))
.builderUrl(slotCaches.getBuilderUrl());
}
Comment thread
StefanBratanov marked this conversation as resolved.

// blocks in ePBS are all unblinded
@Override
public SafeFuture<Optional<SignedBeaconBlock>> unblindSignedBlockIfBlinded(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,35 @@ public BlockFactoryPhase0(
@Override
public SafeFuture<BlockContainerAndMetaData> createUnsignedBlock(
final BlockProductionContext blockProductionContext) {
return createNewUnsignedBlock(blockProductionContext)
.thenApply(
blockAndState ->
createBlockContainerAndMetaDataBuilder(blockAndState.getState())
.blockContainer(blockAndState.getBlock())
.build());
}

protected SafeFuture<BeaconBlockAndState> createNewUnsignedBlock(
final BlockProductionContext blockProductionContext) {
final BeaconState blockSlotState = blockProductionContext.blockSlotState();
final UInt64 proposalSlot = blockProductionContext.proposalSlot();

return spec.createNewUnsignedBlock(
proposalSlot,
spec.getBeaconProposerIndex(blockSlotState, proposalSlot),
blockSlotState,
blockProductionContext.parentRoot(),
operationSelector.createSelector(blockProductionContext),
blockProductionContext.blockProductionPerformance())
.thenApply(this::blockAndStateToBlockContainerAndMetaData);
proposalSlot,
spec.getBeaconProposerIndex(blockSlotState, proposalSlot),
blockSlotState,
blockProductionContext.parentRoot(),
operationSelector.createSelector(blockProductionContext),
blockProductionContext.blockProductionPerformance());
}

private BlockContainerAndMetaData blockAndStateToBlockContainerAndMetaData(
final BeaconBlockAndState blockAndState) {
final SlotCaches slotCaches = BeaconStateCache.getSlotCaches(blockAndState.getState());
return new BlockContainerAndMetaData(
blockAndState.getBlock(),
spec.atSlot(blockAndState.getSlot()).getMilestone(),
slotCaches.getBlockExecutionValue(),
GWEI_TO_WEI.multiply(slotCaches.getBlockProposerRewards().longValue()));
protected BlockContainerAndMetaData.Builder createBlockContainerAndMetaDataBuilder(
final BeaconState state) {
final SlotCaches slotCaches = BeaconStateCache.getSlotCaches(state);
return BlockContainerAndMetaData.builder()
.milestone(spec.atSlot(state.getSlot()).getMilestone())
.executionPayloadValue(slotCaches.getBlockExecutionValue())
.consensusBlockValue(
GWEI_TO_WEI.multiply(slotCaches.getBlockProposerRewards().longValue()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,8 @@ private SafeFuture<InternalValidationResult> processAggregateAndProof(
@Override
public SafeFuture<SendSignedBlockResult> sendSignedBlock(
final SignedBlockContainer maybeBlindedBlockContainer,
final BroadcastValidationLevel broadcastValidationLevel) {
final BroadcastValidationLevel broadcastValidationLevel,
final Optional<String> builderUrl) {
final BlockPublishingPerformance blockPublishingPerformance =
blockProductionAndPublishingPerformanceFactory.createForPublishing(
maybeBlindedBlockContainer.getSlot());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ public void sendSignedBlock_shouldPublish() {
when(blockPublisher.sendSignedBlock(eq(block), eq(NOT_REQUIRED), any()))
.thenReturn(SafeFuture.completedFuture(SendSignedBlockResult.success(block.getRoot())));
final SafeFuture<SendSignedBlockResult> result =
validatorApiHandler.sendSignedBlock(block, NOT_REQUIRED);
validatorApiHandler.sendSignedBlock(block, NOT_REQUIRED, Optional.empty());

assertThat(result).isCompletedWithValue(SendSignedBlockResult.success(block.getRoot()));
}
Expand All @@ -1022,7 +1022,7 @@ public void sendSignedBlock_shouldCatchPublishFailure() {
.thenReturn(SafeFuture.failedFuture(new RuntimeException("Failed to publish block")));

final SafeFuture<SendSignedBlockResult> result =
validatorApiHandler.sendSignedBlock(block, NOT_REQUIRED);
validatorApiHandler.sendSignedBlock(block, NOT_REQUIRED, Optional.empty());

assertThat(result)
.isCompletedWithValue(SendSignedBlockResult.rejected("Failed to publish block"));
Expand Down Expand Up @@ -1062,7 +1062,7 @@ public void sendSignedBlock_shouldCatchPublishFailure() {

// require GOSSIP validation
final SafeFuture<SendSignedBlockResult> result =
validatorApiHandler.sendSignedBlock(block, GOSSIP);
validatorApiHandler.sendSignedBlock(block, GOSSIP, Optional.empty());

assertThat(result).isCompletedWithValue(SendSignedBlockResult.success(block.getRoot()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,29 +149,29 @@ void postDeneb(
private void prepareResponse(final SignedBeaconBlock request, final Version version) {
if (version == V2) {
when(validatorApiChannel.sendSignedBlock(
request, BroadcastValidationLevel.CONSENSUS_AND_EQUIVOCATION))
request, BroadcastValidationLevel.CONSENSUS_AND_EQUIVOCATION, Optional.empty()))
.thenReturn(SafeFuture.completedFuture(SendSignedBlockResult.success(request.getRoot())));
} else {
final BroadcastValidationLevel broadcastValidationLevel =
request.isBlinded()
? BroadcastValidationLevel.NOT_REQUIRED
: BroadcastValidationLevel.GOSSIP;
when(validatorApiChannel.sendSignedBlock(request, broadcastValidationLevel))
when(validatorApiChannel.sendSignedBlock(request, broadcastValidationLevel, Optional.empty()))
.thenReturn(SafeFuture.completedFuture(SendSignedBlockResult.success(request.getRoot())));
}
}

private void prepareResponse(final SignedBlockContainer request, final Version version) {
if (version == V2) {
when(validatorApiChannel.sendSignedBlock(
request, BroadcastValidationLevel.CONSENSUS_AND_EQUIVOCATION))
request, BroadcastValidationLevel.CONSENSUS_AND_EQUIVOCATION, Optional.empty()))
.thenReturn(SafeFuture.completedFuture(SendSignedBlockResult.success(request.getRoot())));
} else {
final BroadcastValidationLevel broadcastValidationLevel =
request.isBlinded()
? BroadcastValidationLevel.NOT_REQUIRED
: BroadcastValidationLevel.GOSSIP;
when(validatorApiChannel.sendSignedBlock(request, broadcastValidationLevel))
when(validatorApiChannel.sendSignedBlock(request, broadcastValidationLevel, Optional.empty()))
.thenReturn(SafeFuture.completedFuture(SendSignedBlockResult.success(request.getRoot())));
}
}
Expand Down
Loading
Loading