Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -465,7 +465,7 @@ public Function<SignedBlockContainer, List<BlobSidecar>> createBlobSidecarsSelec
// the blobs and the proofs wouldn't be part of the BlockContainer.
final BuilderPayloadOrFallbackData builderPayloadOrFallbackData =
executionLayerBlockProductionManager
.getCachedUnblindedPayload(slot)
.getCachedUnblindedPayload(block.getSlotAndBlockRoot())
.orElseThrow(
() ->
new IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ protected BlockAndBlobSidecars createBlockAndBlobSidecars(
}

// simulate caching of the builder payload
when(executionLayer.getCachedUnblindedPayload(signedBlockContainer.getSlot()))
when(executionLayer.getCachedUnblindedPayload(
signedBlockContainer.getSignedBlock().getSlotAndBlockRoot()))
.thenReturn(builderPayload.map(BuilderPayloadOrFallbackData::create));

final List<BlobSidecar> blobSidecars =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void shouldCreateValidBlobSidecarsForBlindedBlock() {
final SignedBlockContainer block = blockAndBlobSidecars.block();
final List<BlobSidecar> blobSidecars = blockAndBlobSidecars.blobSidecars();

verify(executionLayer).getCachedUnblindedPayload(block.getSlot());
verify(executionLayer).getCachedUnblindedPayload(block.getSignedBlock().getSlotAndBlockRoot());

final SszList<SszKZGCommitment> expectedCommitments =
block.getSignedBlock().getMessage().getBody().getOptionalBlobKzgCommitments().orElseThrow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.Eth1Data;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodyBuilder;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodySchema;
Expand Down Expand Up @@ -817,7 +818,7 @@ void shouldFailCreatingBlobSidecarsIfBuilderBlobsBundleCommitmentsRootIsNotConsi
dataStructureUtil.randomBuilderBlobsBundle(3);

prepareCachedBuilderPayload(
signedBlindedBeaconBlock.getSlot(),
signedBlindedBeaconBlock.getSlotAndBlockRoot(),
dataStructureUtil.randomExecutionPayload(),
blobsBundle);

Expand All @@ -842,7 +843,7 @@ void shouldFailCreatingBlobSidecarsIfBuilderBlobsBundleProofsIsNotConsistent() {
when(blobsBundle.getBlobs()).thenReturn(dataStructureUtil.randomSszBlobs(2));

prepareCachedBuilderPayload(
signedBlindedBeaconBlock.getSlot(),
signedBlindedBeaconBlock.getSlotAndBlockRoot(),
dataStructureUtil.randomExecutionPayload(),
blobsBundle);

Expand All @@ -867,7 +868,7 @@ void shouldFailCreatingBlobSidecarsIfBuilderBlobsBundleBlobsIsNotConsistent() {
when(blobsBundle.getProofs()).thenReturn(dataStructureUtil.randomSszKZGProofs(2));

prepareCachedBuilderPayload(
signedBlindedBeaconBlock.getSlot(),
signedBlindedBeaconBlock.getSlotAndBlockRoot(),
dataStructureUtil.randomExecutionPayload(),
blobsBundle);

Expand Down Expand Up @@ -901,10 +902,14 @@ void shouldCreateBlobSidecarsForBlindedBlock(final boolean useLocalFallback) {
.toList(),
blobsBundle.getProofs().stream().map(SszKZGProof::getKZGProof).toList(),
blobsBundle.getBlobs().stream().toList());
prepareCachedFallbackData(slot, executionPayload, localFallbackBlobsBundle);
prepareCachedFallbackData(
signedBlindedBeaconBlock.getSlotAndBlockRoot(),
executionPayload,
localFallbackBlobsBundle);
} else {

prepareCachedBuilderPayload(slot, executionPayload, blobsBundle);
prepareCachedBuilderPayload(
signedBlindedBeaconBlock.getSlotAndBlockRoot(), executionPayload, blobsBundle);
}

final List<BlobSidecar> blobSidecars =
Expand Down Expand Up @@ -1281,20 +1286,23 @@ private void prepareCachedPayloadHeaderWithFallbackResult(
}

private void prepareCachedBuilderPayload(
final UInt64 slot,
final SlotAndBlockRoot slotAndBlockRoot,
final ExecutionPayload executionPayload,
final tech.pegasys.teku.spec.datastructures.builder.BlobsBundle blobsBundle) {
final BuilderPayload builderPayload =
SchemaDefinitionsDeneb.required(spec.atSlot(slot).getSchemaDefinitions())
SchemaDefinitionsDeneb.required(
spec.atSlot(slotAndBlockRoot.getSlot()).getSchemaDefinitions())
.getExecutionPayloadAndBlobsBundleSchema()
.create(executionPayload, blobsBundle);
when(executionLayer.getCachedUnblindedPayload(slot))
when(executionLayer.getCachedUnblindedPayload(slotAndBlockRoot))
.thenReturn(Optional.of(BuilderPayloadOrFallbackData.create(builderPayload)));
}

private void prepareCachedFallbackData(
final UInt64 slot, final ExecutionPayload executionPayload, final BlobsBundle blobsBundle) {
when(executionLayer.getCachedUnblindedPayload(slot))
final SlotAndBlockRoot slotAndBlockRoot,
final ExecutionPayload executionPayload,
final BlobsBundle blobsBundle) {
when(executionLayer.getCachedUnblindedPayload(slotAndBlockRoot))
.thenReturn(
Optional.of(
BuilderPayloadOrFallbackData.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
import java.util.NavigableMap;
import java.util.Optional;
import java.util.concurrent.ConcurrentSkipListMap;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.ethereum.events.SlotEventsChannel;
import tech.pegasys.teku.ethereum.performance.trackers.BlockProductionPerformance;
import tech.pegasys.teku.ethereum.performance.trackers.BlockPublishingPerformance;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot;
import tech.pegasys.teku.spec.datastructures.execution.BuilderBidOrFallbackData;
import tech.pegasys.teku.spec.datastructures.execution.BuilderPayloadOrFallbackData;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadContext;
Expand All @@ -40,7 +42,7 @@ public class ExecutionLayerBlockProductionManagerImpl
private final NavigableMap<UInt64, ExecutionPayloadResult> executionResultCache =
new ConcurrentSkipListMap<>();

private final NavigableMap<UInt64, BuilderPayloadOrFallbackData> builderResultCache =
private final NavigableMap<SlotAndBlockRoot, BuilderPayloadOrFallbackData> builderResultCache =
new ConcurrentSkipListMap<>();

private final ExecutionLayerChannel executionLayerChannel;
Expand All @@ -55,9 +57,9 @@ public void onSlot(final UInt64 slot) {
executionResultCache
.headMap(slot.minusMinZero(EXECUTION_RESULT_CACHE_RETENTION_SLOTS), false)
.clear();
builderResultCache
.headMap(slot.minusMinZero(BUILDER_RESULT_CACHE_RETENTION_SLOTS), false)
.clear();
SlotAndBlockRoot toSlotAndBlockRoot =
new SlotAndBlockRoot(slot.minusMinZero(BUILDER_RESULT_CACHE_RETENTION_SLOTS), Bytes32.ZERO);
builderResultCache.headMap(toSlotAndBlockRoot, false).clear();
}

@Override
Expand Down Expand Up @@ -92,13 +94,15 @@ public SafeFuture<BuilderPayloadOrFallbackData> getUnblindedPayload(
.builderGetPayload(signedBeaconBlock, this::getCachedPayloadResult)
.thenPeek(
builderPayloadOrFallbackData ->
builderResultCache.put(signedBeaconBlock.getSlot(), builderPayloadOrFallbackData))
builderResultCache.put(
signedBeaconBlock.getSlotAndBlockRoot(), builderPayloadOrFallbackData))
.alwaysRun(blockPublishingPerformance::builderGetPayload);
}

@Override
public Optional<BuilderPayloadOrFallbackData> getCachedUnblindedPayload(final UInt64 slot) {
return Optional.ofNullable(builderResultCache.get(slot));
public Optional<BuilderPayloadOrFallbackData> getCachedUnblindedPayload(
final SlotAndBlockRoot slotAndBlockRoot) {
return Optional.ofNullable(builderResultCache.get(slotAndBlockRoot));
}

private ExecutionPayloadResult executeLocalFlow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot;
import tech.pegasys.teku.spec.datastructures.execution.BuilderPayloadOrFallbackData;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadContext;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadResult;
Expand Down Expand Up @@ -56,7 +57,8 @@ public SafeFuture<BuilderPayloadOrFallbackData> getUnblindedPayload(
}

@Override
public Optional<BuilderPayloadOrFallbackData> getCachedUnblindedPayload(final UInt64 slot) {
public Optional<BuilderPayloadOrFallbackData> getCachedUnblindedPayload(
final SlotAndBlockRoot slotAndBlockRoot) {
return Optional.empty();
}
};
Expand Down Expand Up @@ -93,5 +95,6 @@ SafeFuture<BuilderPayloadOrFallbackData> getUnblindedPayload(
* Requires {@link #getUnblindedPayload(SignedBeaconBlock, BlockPublishingPerformance)} to have
* been called first in order for a value to be present
*/
Optional<BuilderPayloadOrFallbackData> getCachedUnblindedPayload(UInt64 slot);
Optional<BuilderPayloadOrFallbackData> getCachedUnblindedPayload(
SlotAndBlockRoot slotAndBlockRoot);
}