Skip to content

Commit 21efe6e

Browse files
author
David Ryan
authored
Change the builderResultCache of ExecutionLayerBlockProductionManagerImpl (#8766)
Change the builderResultCache of ExecutionLayerBlockProductionManagerImpl keys from slot to SlotAndBlockRoot. This allows the cache to return proposals based on slot and block root, which is required if there's multiple operators requesting different beacon block proposals. fixes #8625
1 parent e2a9019 commit 21efe6e

File tree

8 files changed

+45
-22
lines changed

8 files changed

+45
-22
lines changed

beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockOperationSelectorFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ public Function<SignedBlockContainer, List<BlobSidecar>> createBlobSidecarsSelec
465465
// the blobs and the proofs wouldn't be part of the BlockContainer.
466466
final BuilderPayloadOrFallbackData builderPayloadOrFallbackData =
467467
executionLayerBlockProductionManager
468-
.getCachedUnblindedPayload(slot)
468+
.getCachedUnblindedPayload(block.getSlotAndBlockRoot())
469469
.orElseThrow(
470470
() ->
471471
new IllegalStateException(

beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/AbstractBlockFactoryTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ protected BlockAndBlobSidecars createBlockAndBlobSidecars(
374374
}
375375

376376
// simulate caching of the builder payload
377-
when(executionLayer.getCachedUnblindedPayload(signedBlockContainer.getSlot()))
377+
when(executionLayer.getCachedUnblindedPayload(
378+
signedBlockContainer.getSignedBlock().getSlotAndBlockRoot()))
378379
.thenReturn(builderPayload.map(BuilderPayloadOrFallbackData::create));
379380

380381
final List<BlobSidecar> blobSidecars =

beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockFactoryDenebTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ void shouldCreateValidBlobSidecarsForBlindedBlock() {
156156
final SignedBlockContainer block = blockAndBlobSidecars.block();
157157
final List<BlobSidecar> blobSidecars = blockAndBlobSidecars.blobSidecars();
158158

159-
verify(executionLayer).getCachedUnblindedPayload(block.getSlot());
159+
verify(executionLayer).getCachedUnblindedPayload(block.getSlotAndBlockRoot());
160160

161161
final SszList<SszKZGCommitment> expectedCommitments =
162162
block.getSignedBlock().getMessage().getBody().getOptionalBlobKzgCommitments().orElseThrow();

beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockOperationSelectorFactoryTest.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
5151
import tech.pegasys.teku.spec.datastructures.blocks.Eth1Data;
5252
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
53+
import tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot;
5354
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody;
5455
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodyBuilder;
5556
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodySchema;
@@ -817,7 +818,7 @@ void shouldFailCreatingBlobSidecarsIfBuilderBlobsBundleCommitmentsRootIsNotConsi
817818
dataStructureUtil.randomBuilderBlobsBundle(3);
818819

819820
prepareCachedBuilderPayload(
820-
signedBlindedBeaconBlock.getSlot(),
821+
signedBlindedBeaconBlock.getSlotAndBlockRoot(),
821822
dataStructureUtil.randomExecutionPayload(),
822823
blobsBundle);
823824

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

844845
prepareCachedBuilderPayload(
845-
signedBlindedBeaconBlock.getSlot(),
846+
signedBlindedBeaconBlock.getSlotAndBlockRoot(),
846847
dataStructureUtil.randomExecutionPayload(),
847848
blobsBundle);
848849

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

869870
prepareCachedBuilderPayload(
870-
signedBlindedBeaconBlock.getSlot(),
871+
signedBlindedBeaconBlock.getSlotAndBlockRoot(),
871872
dataStructureUtil.randomExecutionPayload(),
872873
blobsBundle);
873874

@@ -901,10 +902,14 @@ void shouldCreateBlobSidecarsForBlindedBlock(final boolean useLocalFallback) {
901902
.toList(),
902903
blobsBundle.getProofs().stream().map(SszKZGProof::getKZGProof).toList(),
903904
blobsBundle.getBlobs().stream().toList());
904-
prepareCachedFallbackData(slot, executionPayload, localFallbackBlobsBundle);
905+
prepareCachedFallbackData(
906+
signedBlindedBeaconBlock.getSlotAndBlockRoot(),
907+
executionPayload,
908+
localFallbackBlobsBundle);
905909
} else {
906910

907-
prepareCachedBuilderPayload(slot, executionPayload, blobsBundle);
911+
prepareCachedBuilderPayload(
912+
signedBlindedBeaconBlock.getSlotAndBlockRoot(), executionPayload, blobsBundle);
908913
}
909914

910915
final List<BlobSidecar> blobSidecars =
@@ -1281,20 +1286,23 @@ private void prepareCachedPayloadHeaderWithFallbackResult(
12811286
}
12821287

12831288
private void prepareCachedBuilderPayload(
1284-
final UInt64 slot,
1289+
final SlotAndBlockRoot slotAndBlockRoot,
12851290
final ExecutionPayload executionPayload,
12861291
final tech.pegasys.teku.spec.datastructures.builder.BlobsBundle blobsBundle) {
12871292
final BuilderPayload builderPayload =
1288-
SchemaDefinitionsDeneb.required(spec.atSlot(slot).getSchemaDefinitions())
1293+
SchemaDefinitionsDeneb.required(
1294+
spec.atSlot(slotAndBlockRoot.getSlot()).getSchemaDefinitions())
12891295
.getExecutionPayloadAndBlobsBundleSchema()
12901296
.create(executionPayload, blobsBundle);
1291-
when(executionLayer.getCachedUnblindedPayload(slot))
1297+
when(executionLayer.getCachedUnblindedPayload(slotAndBlockRoot))
12921298
.thenReturn(Optional.of(BuilderPayloadOrFallbackData.create(builderPayload)));
12931299
}
12941300

12951301
private void prepareCachedFallbackData(
1296-
final UInt64 slot, final ExecutionPayload executionPayload, final BlobsBundle blobsBundle) {
1297-
when(executionLayer.getCachedUnblindedPayload(slot))
1302+
final SlotAndBlockRoot slotAndBlockRoot,
1303+
final ExecutionPayload executionPayload,
1304+
final BlobsBundle blobsBundle) {
1305+
when(executionLayer.getCachedUnblindedPayload(slotAndBlockRoot))
12981306
.thenReturn(
12991307
Optional.of(
13001308
BuilderPayloadOrFallbackData.create(

ethereum/executionlayer/src/main/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionLayerBlockProductionManagerImpl.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import tech.pegasys.teku.infrastructure.async.SafeFuture;
2323
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
2424
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
25+
import tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot;
2526
import tech.pegasys.teku.spec.datastructures.execution.BuilderBidOrFallbackData;
2627
import tech.pegasys.teku.spec.datastructures.execution.BuilderPayloadOrFallbackData;
2728
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadContext;
@@ -40,7 +41,7 @@ public class ExecutionLayerBlockProductionManagerImpl
4041
private final NavigableMap<UInt64, ExecutionPayloadResult> executionResultCache =
4142
new ConcurrentSkipListMap<>();
4243

43-
private final NavigableMap<UInt64, BuilderPayloadOrFallbackData> builderResultCache =
44+
private final NavigableMap<SlotAndBlockRoot, BuilderPayloadOrFallbackData> builderResultCache =
4445
new ConcurrentSkipListMap<>();
4546

4647
private final ExecutionLayerChannel executionLayerChannel;
@@ -55,9 +56,8 @@ public void onSlot(final UInt64 slot) {
5556
executionResultCache
5657
.headMap(slot.minusMinZero(EXECUTION_RESULT_CACHE_RETENTION_SLOTS), false)
5758
.clear();
58-
builderResultCache
59-
.headMap(slot.minusMinZero(BUILDER_RESULT_CACHE_RETENTION_SLOTS), false)
60-
.clear();
59+
final UInt64 slotMax = slot.minusMinZero(BUILDER_RESULT_CACHE_RETENTION_SLOTS);
60+
builderResultCache.keySet().removeIf(key -> key.getSlot().isLessThan(slotMax));
6161
}
6262

6363
@Override
@@ -92,13 +92,15 @@ public SafeFuture<BuilderPayloadOrFallbackData> getUnblindedPayload(
9292
.builderGetPayload(signedBeaconBlock, this::getCachedPayloadResult)
9393
.thenPeek(
9494
builderPayloadOrFallbackData ->
95-
builderResultCache.put(signedBeaconBlock.getSlot(), builderPayloadOrFallbackData))
95+
builderResultCache.put(
96+
signedBeaconBlock.getSlotAndBlockRoot(), builderPayloadOrFallbackData))
9697
.alwaysRun(blockPublishingPerformance::builderGetPayload);
9798
}
9899

99100
@Override
100-
public Optional<BuilderPayloadOrFallbackData> getCachedUnblindedPayload(final UInt64 slot) {
101-
return Optional.ofNullable(builderResultCache.get(slot));
101+
public Optional<BuilderPayloadOrFallbackData> getCachedUnblindedPayload(
102+
final SlotAndBlockRoot slotAndBlockRoot) {
103+
return Optional.ofNullable(builderResultCache.get(slotAndBlockRoot));
102104
}
103105

104106
private ExecutionPayloadResult executeLocalFlow(

ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/SignedBeaconBlock.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ public UInt64 getSlot() {
137137
return getMessage().getSlot();
138138
}
139139

140+
@Override
141+
public SlotAndBlockRoot getSlotAndBlockRoot() {
142+
return getMessage().getSlotAndBlockRoot();
143+
}
144+
140145
@Override
141146
public Bytes32 getParentRoot() {
142147
return getMessage().getParentRoot();

ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/SignedBlockContainer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ default Bytes32 getRoot() {
4040
return getSignedBlock().getRoot();
4141
}
4242

43+
default SlotAndBlockRoot getSlotAndBlockRoot() {
44+
return getSignedBlock().getSlotAndBlockRoot();
45+
}
46+
4347
default Optional<SszList<SszKZGProof>> getKzgProofs() {
4448
return Optional.empty();
4549
}

ethereum/spec/src/main/java/tech/pegasys/teku/spec/executionlayer/ExecutionLayerBlockProductionManager.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import tech.pegasys.teku.infrastructure.async.SafeFuture;
2020
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
2121
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
22+
import tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot;
2223
import tech.pegasys.teku.spec.datastructures.execution.BuilderPayloadOrFallbackData;
2324
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadContext;
2425
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadResult;
@@ -56,7 +57,8 @@ public SafeFuture<BuilderPayloadOrFallbackData> getUnblindedPayload(
5657
}
5758

5859
@Override
59-
public Optional<BuilderPayloadOrFallbackData> getCachedUnblindedPayload(final UInt64 slot) {
60+
public Optional<BuilderPayloadOrFallbackData> getCachedUnblindedPayload(
61+
final SlotAndBlockRoot slotAndBlockRoot) {
6062
return Optional.empty();
6163
}
6264
};
@@ -93,5 +95,6 @@ SafeFuture<BuilderPayloadOrFallbackData> getUnblindedPayload(
9395
* Requires {@link #getUnblindedPayload(SignedBeaconBlock, BlockPublishingPerformance)} to have
9496
* been called first in order for a value to be present
9597
*/
96-
Optional<BuilderPayloadOrFallbackData> getCachedUnblindedPayload(UInt64 slot);
98+
Optional<BuilderPayloadOrFallbackData> getCachedUnblindedPayload(
99+
SlotAndBlockRoot slotAndBlockRoot);
97100
}

0 commit comments

Comments
 (0)